1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
|
/*
* Copyright 2015-2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Andrea Bernabei <andrea.bernabei@canonical.com>
*/
import QtQuick 2.4
import QtTest 1.1
import Lomiri.Test 1.0
import Lomiri.Components 1.3
import Lomiri.Components.Styles 1.3
import QtQml.Models 2.1
Item {
id: main
width: units.gu(50)
height: units.gu(100)
Component {
id: flickableComp
Item {
id: item
width: units.gu(20)
height: units.gu(30)
property alias flickable: freshFlickable
property alias scrollbar: freshScrollbar
property alias content: content
property alias scrollbarAlignment: freshScrollbar.align
//Don't change this to a ListView, this usecase has to be simple,
//we don't want the difficulties added by ListView, i.e. delegates
//size estimation, dynamic contentWidth/Height, etc
Flickable {
id: freshFlickable
anchors.fill: parent
contentHeight: content.height
contentWidth: content.width
clip: true
Rectangle {
id: content
width: units.gu(40)
//make this much taller than the flickable to avoid timing issues when
//detecting if the flickable is flicking in the tests
height: units.gu(200)
color: "blue"
}
}
Scrollbar {
id: freshScrollbar
flickableItem: parent.flickable
}
}
}
Component {
id: freshScrollbar
Scrollbar { }
}
SignalSpy {
id: signalSpy
}
SignalSpy {
id: anotherSignalSpy
}
Flickable {
anchors.fill: parent
Column {
id: column
Repeater {
model: layoutsModel
}
}
}
VisualItemModel {
id: layoutsModel
Item {
width: childrenRect.width
height: childrenRect.height
Flickable {
id: flickable_bottomAlign_anchors
}
Scrollbar {
id: scrollbar_bottomAlign_anchors
flickableItem: flickable_bottomAlign_anchors
align: Qt.AlignBottom
}
Flickable {
id: flickable_topAlign_anchors
}
Scrollbar {
id: scrollbar_topAlign_anchors
flickableItem: flickable_topAlign_anchors
align: Qt.AlignBottom
}
Flickable {
id: flickable_leadingAlign_anchors
}
Scrollbar {
id: scrollbar_leadingAlign_anchors
flickableItem: flickable_leadingAlign_anchors
align: Qt.AlignLeading
}
Flickable {
id: flickable_trailingAlign_anchors
}
Scrollbar {
id: scrollbar_trailingAlign_anchors
flickableItem: flickable_trailingAlign_anchors
align: Qt.AlignTrailing
}
Flickable {
id: defaultValuesFlickable
}
Scrollbar {
id: defaultValuesScrollbar
flickableItem: defaultValuesFlickable
}
//Items used for values sanity checks
Flickable {
id: flickableSanityCheck
width: units.gu(30)
height: units.gu(40)
Rectangle {
id: contentSanityCheck
width: units.gu(20)
height: units.gu(30)
color: "yellow"
}
}
Scrollbar {
id: scrollbarSanityCheck
flickableItem: flickableSanityCheck
}
}
}
ScrollbarTestCase13 {
name: "Scrollbar"
function getFreshFlickable(alignment) {
var wrapper = createTemporaryObject(flickableComp, column, { scrollbarAlignment: alignment } )
verify(wrapper !== null, "Error: dynamic item creation failed.")
compare(wrapper.scrollbar.align, alignment, "getFreshFlickable: wrong alignment.")
return wrapper
}
function init_data() {
return [
{ tag: "vertical scrollbar", alignment: Qt.AlignTrailing },
{ tag: "horizontal scrollbar", alignment: Qt.AlignBottom }
]
}
function clickOnStepperAndCheckNoContentPositionChange(msgPrefix, itemToClickOn, flickable, expectedContentX, expectedContentY) {
clickInTheMiddle(itemToClickOn)
wait(150)
checkNoContentPositionChange(msgPrefix, flickable, expectedContentX, expectedContentY)
}
//NOTE: this does not test that the properties have the correct value, just that
//their values is not out of range (so it only applies to numeric values or enums)
function performStyleSanityCheck(scrollbar) {
var style = scrollbar.__styleInstance
/*****************************************************
* STYLING PROPERTIES *
*****************************************************/
verify(style.minimumSliderSize >= 0, "Sanity check: invalid property value.")
verify(style.overlayOpacityWhenShown > 0, "Sanity check: invalid property value.")
verify(style.overlayOpacityWhenHidden >= 0, "Sanity check: invalid property value.")
verify(style.troughThicknessSteppersStyle > 0, "Sanity check: invalid property value.")
verify(style.troughThicknessThumbStyle > 0, "Sanity check: invalid property value.")
verify(style.troughThicknessIndicatorStyle > 0, "Sanity check: invalid property value.")
verify(style.sliderRadius >= 0, "Sanity check: invalid property value.")
verify(style.thumbThickness > 0, "Sanity check: invalid property value.")
verify(style.indicatorThickness > 0, "Sanity check: invalid property value.")
verify(style.scrollbarThicknessAnimation.duration >= 0, "Sanity check: invalid property value.")
verify(style.scrollbarFadeInAnimation.duration >= 0, "Sanity check: invalid property value.")
verify(style.scrollbarFadeOutAnimation.duration >= 0, "Sanity check: invalid property value.")
verify(style.scrollbarFadeOutPause >= 0, "Sanity check: invalid property value.")
verify(style.scrollbarCollapsePause >= 0, "Sanity check: invalid property value.")
verify(style.shortScrollingRatio > 0, "Sanity check: invalid property value.")
verify(style.longScrollingRatio > 0, "Sanity check: invalid property value.")
verify(style.hintingStyle === 'thumb'
|| style.hintingStyle === 'indicator', "Sanity check: invalid property value.")
verify(style.thumbsExtremesMargin >= 0, "Sanity check: invalid property value.")
/*****************************************************
* HELPER PROPERTIES *
*****************************************************/
verify(!!style.thumb, "Sanity check: invalid property value.")
verify(!!style.trough, "Sanity check: invalid property value.")
//flickable helper properties
verify(!!style.flickableItem, "Sanity check: invalid property value.")
/*****************************************************
* INTERNAL PROPERTIES AND FUNCTIONS *
*****************************************************/
verify(style.nonOverlayScrollbarMargin >= 0, "Sanity check: invalid property value.")
verify(style.touchDragStartMargin >= 0, "Sanity check: invalid property value.")
verify(style.dragThreshold >= 0, "Sanity check: invalid property value.")
verify(style.__stepperAssetWidth <= style.troughThicknessSteppersStyle, "Sanity check: check that the stepper arrow is narrower than the trough.")
verify(style.__stepperImgOpacityNormal < style.__stepperImgOpacityOnHover, "Sanity check: check that stepper is darker on hover than on normal state.")
verify(style.__stepperImgOpacityOnHover < style.__stepperImgOpacityOnPressed, "Sanity check: check that stepper is darker on pressed than on hover state.")
verify(style.__stepperBgOpacityOnHover < style.__stepperBgOpacityOnPressed, "Sanity check: check that stepper background is darker on pressed than on hover state.")
}
function test_visibility(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var scrollbar = freshTestItem.scrollbar
compare(scrollbar.visible, true, "Wrong Scrollbar visible property value")
scrollbar.flickableItem = null
compare(scrollbar.visible, false, "Wrong Scrollbar visible property value")
//check that the same apply to a scrollbar that was born without Flickable
var nullFlickableScrollbar = freshScrollbar.createObject(freshTestItem)
verify(nullFlickableScrollbar !== null, "Error: dynamic item creation failed.")
compare(nullFlickableScrollbar.visible, false, "Scrollbar is visible before an initialized flickable is assigned to it")
nullFlickableScrollbar.destroy()
}
//no need to test the anchors values when flickable is not set because we already
//test that the scrollbar is hidden when there's no flickable set
function test_bottomAlign_anchors() {
compare(scrollbar_bottomAlign_anchors.flickableItem,
flickable_bottomAlign_anchors, "wrong flickableItem")
compare(scrollbar_bottomAlign_anchors.anchors.left,
scrollbar_bottomAlign_anchors.flickableItem.left, "left anchor")
compare(scrollbar_bottomAlign_anchors.anchors.right,
scrollbar_bottomAlign_anchors.flickableItem.right, "right anchor")
compare(scrollbar_bottomAlign_anchors.anchors.bottom,
scrollbar_bottomAlign_anchors.flickableItem.bottom, "bottom anchor")
//we can't check that the top anchor is not anchored
}
function test_topAlign_anchors() {
compare(scrollbar_topAlign_anchors.flickableItem,
flickable_topAlign_anchors, "wrong flickableItem")
compare(scrollbar_topAlign_anchors.anchors.left,
scrollbar_topAlign_anchors.flickableItem.left, "left anchor")
compare(scrollbar_topAlign_anchors.anchors.right,
scrollbar_topAlign_anchors.flickableItem.right, "right anchor")
compare(scrollbar_topAlign_anchors.anchors.top,
scrollbar_topAlign_anchors.flickableItem.top, "top anchor")
}
function test_leadingAlign_anchors() {
compare(scrollbar_leadingAlign_anchors.flickableItem,
flickable_leadingAlign_anchors, "wrong flickableItem")
compare(scrollbar_leadingAlign_anchors.anchors.left,
scrollbar_leadingAlign_anchors.flickableItem.left, "left anchor")
compare(scrollbar_leadingAlign_anchors.anchors.bottom,
scrollbar_leadingAlign_anchors.flickableItem.bottom, "bottom anchor")
compare(scrollbar_leadingAlign_anchors.anchors.top,
scrollbar_leadingAlign_anchors.flickableItem.top, "top anchor")
}
function test_trailingAlign_anchors() {
compare(scrollbar_trailingAlign_anchors.flickableItem,
flickable_trailingAlign_anchors, "wrong flickableItem")
compare(scrollbar_trailingAlign_anchors.anchors.right,
scrollbar_trailingAlign_anchors.flickableItem.right, "right anchor")
compare(scrollbar_trailingAlign_anchors.anchors.bottom,
scrollbar_trailingAlign_anchors.flickableItem.bottom, "bottom anchor")
compare(scrollbar_trailingAlign_anchors.anchors.top,
scrollbar_trailingAlign_anchors.flickableItem.top, "top anchor")
}
function test_indicatorStyleWhileFlicking_shortContent(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
compare(scrollbar.__styleInstance.veryLongContentItem, false, "Scrollable item should be short.")
//The final "1" is a workaround to bug #1549256
flick(flickable, 2, 2, -units.gu(10), -units.gu(10), undefined, undefined, undefined, undefined, 1)
tryCompare(flickable, "moving", true, 5000, "Flickable not moving after simulating a flick.")
compare(scrollbar.__styleInstance.state, "indicator", "Wrong style while flicking.")
//we don't set it up before because the hinting feature already changes the state
setupSignalSpy(anotherSignalSpy, scrollbar.__styleInstance, "stateChanged")
//wait for the flickable to stop
tryCompare(flickable, "moving", false, 5000, "Flickable still moving after timeout.")
anotherSignalSpy.wait()
compare(anotherSignalSpy.count, 1, "State unchanged after Flickable stopped moving.")
compare(scrollbar.__styleInstance.state, "hidden", "Wrong style after the item stopped moving.")
}
function test_thumbStyleWhileFlicking_veryLongContent(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
setupSignalSpy(signalSpy, scrollbar.__styleInstance, "veryLongContentItemChanged")
setVeryLongContentItem(flickable, scrollbar.__styleInstance, false)
signalSpy.wait()
compare(scrollbar.__styleInstance.veryLongContentItem, true, "Very long content item not detected")
//The final "1" is a workaround to bug #1549256
flick(flickable, 2, 2, -units.gu(10), -units.gu(10), undefined, undefined, undefined, undefined, 1)
tryCompare(flickable, "moving", true, 5000, "Flickable not moving after simulating a flick.")
compare(scrollbar.__styleInstance.state, "thumb", "Wrong style while flicking a very long item")
setupSignalSpy(anotherSignalSpy, scrollbar.__styleInstance, "stateChanged")
//wait for the flickable to stop
tryCompare(flickable, "moving", false, 5000, "Flickable still moving after timeout.")
anotherSignalSpy.wait()
compare(anotherSignalSpy.count, 1, "State unchanged after Flickable stopped moving.")
compare(scrollbar.__styleInstance.state, "hidden", "Wrong style after a the item stopped moving.")
}
function test_scrollingWithContentMargins(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var style = freshTestItem.scrollbar.__styleInstance
var scrollbarUtils = getScrollbarUtils(scrollbar)
//to make sure that it's only scrolling in the direction it should
var notScrollingProperty = scrollbarUtils.propContent === "contentX" ? "contentY" : "contentX"
addContentMargins(flickable)
style.scrollToBeginning(false)
compare(flickable[notScrollingProperty], 0, "ContentX changed when it shouldn't")
compare(flickable[scrollbarUtils.propContent],
style.isVertical ? -flickable.topMargin : -flickable.leftMargin,
"Wrong beginning contentY")
style.scrollToEnd(false)
compare(flickable[notScrollingProperty], 0, "ContentX changed when it shouldn't")
compare(flickable[scrollbarUtils.propContent],
style.isVertical
? flickable.contentHeight + flickable.bottomMargin - flickable[scrollbarUtils.propSize]
: flickable.contentWidth + flickable.rightMargin - flickable[scrollbarUtils.propSize],
"Wrong end contentY")
//contentHeight+top+bottom is the max you can scroll anyway, so it's
//safe to use it, and the scrollbar should go to returnToBounds() if it goes beyond
var maxScrolling = style.totalContentSize
style.scrollBy(-maxScrolling, false)
compare(flickable[notScrollingProperty], 0, "ContentX changed when it shouldn't")
compare(flickable[scrollbarUtils.propContent],
style.isVertical ? -flickable.topMargin : -flickable.leftMargin,
"scrollBy: wrong contentY after scrolling to the beginning")
style.scrollBy(maxScrolling, false)
compare(flickable[notScrollingProperty], 0, "ContentX changed when it shouldn't")
compare(flickable[scrollbarUtils.propContent],
style.isVertical
? flickable.contentHeight + flickable.bottomMargin - flickable[scrollbarUtils.propSize]
: flickable.contentWidth + flickable.rightMargin - flickable[scrollbarUtils.propSize],
"scrollBy: wrong contentY after scrolling to the end")
//we can only scroll up now
var oldContentProp = flickable[scrollbarUtils.propContent]
style.scrollBy(-units.gu(1), false)
compare(flickable[scrollbarUtils.propContent],
oldContentProp - units.gu(1),
"scrollBy: wrong contentY after scrolling by +1GU")
style.scrollBy(units.gu(1), false)
compare(flickable[scrollbarUtils.propContent],
oldContentProp,
"scrollBy: wrong contentY after scrolling by -1GU")
}
function test_showSteppers(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var style = scrollbar.__styleInstance
var steppersTransition = findInListProperty(scrollbar.__styleInstance.transitions, "indicatorToThumbSteppersTransition")
verify(steppersTransition !== null, "Could not find transition object")
setupSignalSpy(signalSpy, scrollbar.__styleInstance, "stateChanged")
setupSignalSpy(anotherSignalSpy, steppersTransition, "runningChanged")
//show steppers on mouse move
mouseMove(scrollbar, 0, 0)
signalSpy.wait()
compare(signalSpy.count, 1, "Mouse move doesn't trigger state change")
anotherSignalSpy.wait()
compare(anotherSignalSpy.count, 1, "Mouse move doesn't trigger state transition")
compare(scrollbar.__styleInstance.state, "steppers", "Mouse move doesn't trigger steppers state.")
var firstStepper = getFirstStepper(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
var trough = getTrough(scrollbar)
compare(trough.visible, true, "Trough not visible in steppers state")
compare(firstStepper.visible, true, "First stepper not visible in steppers state")
compare(secondStepper.visible, true, "Second stepper not visible in steppers state")
anotherSignalSpy.wait()
compare(anotherSignalSpy.count, 2, "State transition does not complete.")
compare(steppersTransition.running, false, "State transition does not stop.")
if (style.isVertical) {
compare(trough.width, scrollbar.__styleInstance.troughThicknessSteppersStyle, "Wrong trough thickness in steppers style")
} else {
compare(trough.height, scrollbar.__styleInstance.troughThicknessSteppersStyle, "Wrong trough thickness in steppers style")
}
}
function checkSteppersColour(scrollbar, firstStepperStateString, secondStepperStateString, testDescription) {
var firstStepper = getFirstStepper(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
var firstStepperIcon = getFirstStepperIcon(scrollbar)
var secondStepperIcon = getSecondStepperIcon(scrollbar)
var style = scrollbar.__styleInstance
var stepperBgColorBase = style.stepperBgColor
var stepperImgColor = style.sliderColor
var stepperBgColorDisabled = "transparent"
var stepperImgColorDisabled = Qt.rgba(stepperImgColor.r, stepperImgColor.g, stepperImgColor.b,
stepperImgColor.a * style.__stepperImgOpacityDisabled)
var stepperBgColorNormal = "transparent"
var stepperImgColorNormal = Qt.rgba(stepperImgColor.r, stepperImgColor.g, stepperImgColor.b,
stepperImgColor.a * style.__stepperImgOpacityNormal)
var stepperBgColorOnHover = Qt.rgba(stepperBgColorBase.r, stepperBgColorBase.g, stepperBgColorBase.b,
stepperBgColorBase.a * style.__stepperBgOpacityOnHover)
var stepperImgColorOnHover = Qt.rgba(stepperImgColor.r, stepperImgColor.g, stepperImgColor.b,
stepperImgColor.a * style.__stepperImgOpacityOnHover)
var stepperBgColorOnPressed = Qt.rgba(stepperBgColorBase.r, stepperBgColorBase.g, stepperBgColorBase.b,
stepperBgColorBase.a * style.__stepperBgOpacityOnPressed)
var stepperImgColorOnPressed = Qt.rgba(stepperImgColor.r, stepperImgColor.g, stepperImgColor.b,
stepperImgColor.a * style.__stepperImgOpacityOnPressed)
switch (firstStepperStateString) {
case "disabled":
var expectedFirstStepperColour = stepperBgColorDisabled
var expectedFirstStepperIconColour = stepperImgColorDisabled
break
case "normal":
var expectedFirstStepperColour = stepperBgColorNormal
var expectedFirstStepperIconColour = stepperImgColorNormal
break
case "hovered":
var expectedFirstStepperColour = stepperBgColorOnHover
var expectedFirstStepperIconColour = stepperImgColorOnHover
break
case "pressed":
var expectedFirstStepperColour = stepperBgColorOnPressed
var expectedFirstStepperIconColour = stepperImgColorOnPressed
break
default:
fail("Invalid stepper state string")
}
switch (secondStepperStateString) {
case "disabled":
var expectedSecondStepperColour = stepperBgColorDisabled
var expectedSecondStepperIconColour = stepperImgColorDisabled
break
case "normal":
var expectedSecondStepperColour = stepperBgColorNormal
var expectedSecondStepperIconColour = stepperImgColorNormal
break
case "hovered":
var expectedSecondStepperColour = stepperBgColorOnHover
var expectedSecondStepperIconColour = stepperImgColorOnHover
break
case "pressed":
var expectedSecondStepperColour = stepperBgColorOnPressed
var expectedSecondStepperIconColour = stepperImgColorOnPressed
break
default:
fail("Invalid stepper state string")
}
var msg = "First stepper expected state: " + firstStepperStateString + "."
+ " Second stepper expected state: " + secondStepperStateString + ". "
+ " Test description: " + testDescription + ". "
+ " Error encountered: "
//compare() returns pass on different colours, see https://bugreports.qt.io/browse/QTBUG-34878
compare(Qt.colorEqual(firstStepper.color, expectedFirstStepperColour), true,
msg + "wrong first stepper background color.")
compare(Qt.colorEqual(firstStepperIcon.color, expectedFirstStepperIconColour), true,
msg + "wrong first stepper icon color.")
compare(Qt.colorEqual(secondStepper.color, expectedSecondStepperColour), true,
msg + "wrong second stepper background color.")
compare(Qt.colorEqual(secondStepperIcon.color, expectedSecondStepperIconColour), true,
msg + "wrong second stepper icon color.")
}
function test_checkStepperStatesStyling(data) {
skip("Scrollbar already in steppers mode under Qt 5.9, causing failure.")
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var style = scrollbar.__styleInstance
var firstStepper = getFirstStepper(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
triggerSteppersMode(scrollbar)
//the following tests are assuming that the steppers are not disabled
compare(style.isScrollable, true, "Scrollbar is not scrollable, cannot test steppers hover/pressed state.")
if (style.isVertical) {
compare(style.flickableItem.atYBeginning, true, "View not scrolled to the beginning as expected.")
compare(style.flickableItem.atYEnd, false, "View unexpectedly already scrolled to the end.")
} else {
compare(style.flickableItem.atXBeginning, true, "View not scrolled to the beginning as expected.")
compare(style.flickableItem.atXEnd, false, "View unexpectedly already scrolled to the end.")
}
//Check that the first stepper is disabled and the second one is in normal state
checkSteppersColour(scrollbar, "disabled", "normal", "default state before moving mouse")
//Check that hovering on a disabled stepper does not change its colour
mouseMove(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "disabled", "normal", "mouse hovered to disabled first stepper")
//Check that tapping on a disabled stepper does not change its colour
mousePress(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "disabled", "normal", "mouse pressed on disabled first stepper")
mouseRelease(firstStepper, firstStepper.width/2, firstStepper.height/2)
//move mouse away from the steppers
mouseMove(scrollbar, 0, 0)
//Scroll to the bottom to check disabled state of the second stepper
var thumb = getThumb(scrollbar)
var trough = getTrough(scrollbar)
if (style.isVertical) {
mouseMove(thumb, 0, 0)
mouseDrag(thumb, thumb.width/2, thumb.height/2, 0, trough.height)
compare(style.flickableItem.atYBeginning, false, "View not scrolled to the bottom as expected.")
compare(style.flickableItem.atYEnd, true, "View unexpectedly at the beginning.")
} else {
mouseMove(thumb, 0, 0)
mouseDrag(thumb, thumb.width/2, thumb.height/2, trough.width, 0)
compare(style.flickableItem.atXBeginning, false, "View not scrolled to the bottom as expected.")
compare(style.flickableItem.atXEnd, true, "View unexpectedly at the beginning.")
}
//Check that the first stepper is normal and the second one is in disable state
checkSteppersColour(scrollbar, "normal", "disabled", "after thumb dragged to bottom and mouse moved away from steppers.")
//Check that hovering on a disabled stepper does not change its colour
mouseMove(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "disabled", "thumb at the bottom, mouse hovered on disabled second stepper")
//Check that tapping on a disabled stepper does not change its colour
mousePress(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "disabled", "thumb at the bottom, mouse pressed on disabled second stepper")
mouseRelease(secondStepper, secondStepper.width/2, secondStepper.height/2)
//move mouse away from the steppers
mouseMove(scrollbar, 0, 0)
//trigger first stepper to scroll up a bit, so that they're both not disabled
//scrolling up with a stepper should not scroll to the top, unless there's a bug somewhere else
//or the flickable test item gets changed
clickInTheMiddle(firstStepper)
checkScrolling(flickable, style.flickableItem.contentX, style.flickableItem.contentY, style,
false, -1, "First stepper, click")
//the previous click ungrabs the mouse after release, so we can't directly send a Move outside
//the stepper's area because QQuickWindow will just deliver it to the item at that coord, given
//that there is no item grabbing the mouse. So we have to send a mouse move
//to the second stepper INSIDE its area, before we can send it an event outside
//its area in order to trigger HoverLeave.
mouseMove(secondStepper, 0, 0)
//send an event outside the area of the second stepper (read comment above). This will
//trigger HoverLeave for the secondStepper. If you want to know why, see
//https://github.com/qtproject/qtdeclarative/blob/5.4/src/quick/items/qquickwindow.cpp#L1666
mouseMove(scrollbar, 0, 0)
//Check colours in normal state
checkSteppersColour(scrollbar, "normal", "normal", "mouse moved away from steppers")
//Hover on first stepper and check colour of both steppers
mouseMove(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "hovered", "normal", "mouse hovered on first stepper")
//Press on first stepper and check colour of both steppers
mousePress(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "pressed", "normal", "mouse pressed on first stepper")
mouseRelease(firstStepper, firstStepper.width/2, firstStepper.height/2)
//Hover on second stepper and check colour of both steppers
mouseMove(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "hovered", "mouse hovered on second stepper")
//Press on second stepper and check colour of both steppers
mousePress(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "pressed", "mouse pressed on second stepper")
mouseRelease(secondStepper, secondStepper.width/2, secondStepper.height/2)
//Check that pressing on a stepper (mouse-only) will activate the hover state
//even without a mouse move (i.e. without onEntered/onExited, which can often
//happen in unit tests)
//Press on first stepper without first firing mouseMove and check colour of both steppers
mousePress(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "pressed", "normal", "mouse pressed on first stepper without sending mouseMove before")
mouseRelease(firstStepper, firstStepper.width/2, firstStepper.height/2)
checkSteppersColour(scrollbar, "hovered", "normal", "after mouse released while on first stepper")
//Press on second stepper without first firing mouseMove and check colour of both steppers
mousePress(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "pressed", "mouse pressed on second stepper without sending mouseMove before")
mouseRelease(secondStepper, secondStepper.width/2, secondStepper.height/2)
checkSteppersColour(scrollbar, "normal", "hovered", "after mouse released while on second stepper")
}
//test that moving the mouse inside and outside any of the hover area borders has the expected effect
function test_thumbHoverArea(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var thumb = getThumb(scrollbar)
var thumbArea = getThumbArea(scrollbar)
var trough = getTrough(scrollbar)
var style = freshTestItem.scrollbar.__styleInstance
var scrollbarUtils = getScrollbarUtils(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
var thumbNormalColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 0.4)
var thumbHoveredColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 0.7)
var thumbPressedColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 1.0)
addContentMargins(flickable)
setContentPositionToTopLeft(flickable)
triggerSteppersMode(scrollbar)
//check colour of the thumb in normal state
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true, "Wrong thumb color in normal state.")
//hover on the middle
mouseMove(thumb, thumb.width/2, thumb.height/2)
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true, "Wrong thumb color in hover state.")
//check that moving mouse outside the thumb (to the second stepper, in this case) and back in will
//trigger the correct color changes
mouseMove(secondStepper, secondStepper.width/2, secondStepper.height/2)
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true, "Wrong thumb color after moving mouse to a stepper.")
mouseMove(thumb, thumb.width/2, thumb.height/2)
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Wrong thumb color after moving mouse from stepper back into the thumb.")
//check pressed state colour
mousePress(thumb, thumb.width/2, thumb.height/2)
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true, "Wrong thumb color in pressed state.")
mouseRelease(thumb, thumb.width/2, thumb.height/2)
//check hovered colour again, the thumb should still show as hovered after releasing mouse
//(assuming the mouse is still inside it, which it is)
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Thumb does not show as hovered after mouse press-release inside it.")
//depending on how the implementation of the scrollbar evolves, the input area
//may become bigger than the trough on one or both sides, so we map the coords
//to know where to send events relative to the thumb so that they hit the trough
//(which is part of the hover area, along the scrolling axis, i.e. x-axis for vert.scrollbar)
var mappedCoords = thumb.mapToItem(trough, 0, 0)
//mouseMove seem to deliver events at pixel bound, so we have to take the floor of the sizes
//otherwise if thumb has width 50.6, mouseMove(thumb, 50.6, 0) will send an event to x==51 and that
//will cause the logic to assume the mouse is outside the hover area while it's on the border
var floorThumbWidth = Math.floor(thumb.width)
var floorThumbHeight = Math.floor(thumb.height)
var floorTroughWidth = Math.floor(trough.width)
var floorTroughHeight = Math.floor(trough.height)
//top-left and bottom-right coords of the rectangle defining the thumb hover area
//we need different handling of vertical/horizontal because the hover area is defined
//as the whole trough along the scrolling axis (e.g. whole trough width for the vert. scrollbar)
//and exactly the thumb along the non-scrolling axis (e.g. thumb's height for vert. scrollbar
if (style.isVertical) {
var insideTopLeft = [-mappedCoords.x , 0 ]
var insideBottomRight = [-mappedCoords.x + floorTroughWidth, floorThumbHeight]
} else {
var insideTopLeft = [0 , -mappedCoords.y ]
var insideBottomRight = [floorThumbWidth, -mappedCoords.y + floorTroughHeight]
}
mouseMove(thumb, insideTopLeft[0], insideTopLeft[1])
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Thumb does not show as hovered after mouse moved to the top-left corner of the hover area.")
mouseMove(thumb, insideBottomRight[0], insideBottomRight[1])
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Thumb does not show as hovered after mouse moved to the bottom-right corner of the hover area.")
//right outside the hover area
var outsideTopBorder = [insideTopLeft[0] , insideTopLeft[1] - 1] //move 1 up
var outsideLeftBorder = [insideTopLeft[0] - 1 , insideTopLeft[1]] //move 1 left
var outsideBottomBorder = [insideBottomRight[0] , insideBottomRight[1] + 1] //move 1 down
var outsideRightBorder = [insideBottomRight[0] + 1 , insideBottomRight[1]] //move 1 right
//check that when the mouse is right outside the borders of the hover area the thumb will use the non-hover colour
mouseMove(thumb, outsideTopBorder[0], outsideTopBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true,
"Thumb does not show as NOT-hovered after mouse moved outside the top border of the hover area.")
mouseMove(thumb, outsideBottomBorder[0], outsideBottomBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true,
"Thumb does not show as NOT-hovered after mouse moved outside the bottom border of the hover area.")
mouseMove(thumb, outsideLeftBorder[0], outsideLeftBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true,
"Thumb does not show as NOT-hovered after mouse moved outside the left border of the hover area.")
mouseMove(thumb, outsideRightBorder[0], outsideRightBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true,
"Thumb does not show as NOT-hovered after mouse moved outside the right border of the hover area.")
//BUG #1616926
//check pressind on the THUMB and releasing mouse outside the TROUGH resets it to normal state
//press thumb, move mouse outside the trough and check that the thumb is not showing as hovered
//The broken logic was just checking if mouse was inside the thumb
//on the same axis as the scrolling one (so y for vertical scrollbar, x for horizontal) so we move
//mouse in the opposite axis (i.e. along x if vertical scrollbar) to check that the bug is fixed
mousePress(thumb, thumb.width/2, thumb.height/2)
if (style.isVertical) {
mouseMove(thumb, outsideLeftBorder[0], outsideLeftBorder[1])
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true, "Wrong THUMB color in pressed state.")
mouseRelease(thumb, outsideLeftBorder[0], outsideLeftBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true, "Wrong THUMB color after releasing mouse with x outside TROUGH.")
} else {
mouseMove(thumb, outsideTopBorder[0], outsideTopBorder[1])
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true, "Wrong THUMB color in pressed state.")
mouseRelease(thumb, outsideTopBorder[0], outsideTopBorder[1])
compare(Qt.colorEqual(thumb.color, thumbNormalColor), true, "Wrong THUMB color after releasing mouse with y outside TROUGH.")
}
}
//test dragging the thumb and relative visual changes due to hover/pressed states
function test_dragThumbAndCheckStyling(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var thumb = getThumb(scrollbar)
var thumbArea = getThumbArea(scrollbar)
var trough = getTrough(scrollbar)
var style = freshTestItem.scrollbar.__styleInstance
var scrollbarUtils = getScrollbarUtils(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
var thumbNormalColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 0.4)
var thumbHoveredColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 0.7)
var thumbPressedColor = Qt.rgba(style.sliderColor.r, style.sliderColor.g, style.sliderColor.b,
style.sliderColor.a * 1.0)
addContentMargins(flickable)
setContentPositionToTopLeft(flickable)
triggerSteppersMode(scrollbar)
if (style.isVertical) {
mouseDrag(thumb, thumb.width/2, thumb.height/2, 0, trough.height)
compare(flickable[scrollbarUtils.propContent],
flickable.contentHeight + flickable.bottomMargin - flickable.height,
"Vertical thumb mouse drag: wrong contentProp after dragging to the end")
var sceneThumbY = thumb.mapToItem(column, 0, 0).y
//Cannot use mouseDrag here, because the thumb is at the end of the trough.
//mouseDrag uses
//mouseMove(item, x + util.dragThreshold + 1, y + util.dragThreshold + 1, delay, button)
//to trigger the drag, but in our case that cannot work because the scrollbar is at
//the end of the trough, hence cannot move to its
//bottom (vertical scrollbar) or to its right (in the case of the horiz scrollbar)
mousePress(thumb, thumb.width/2, thumb.height/2)
mouseMove(thumb, thumb.width/2, 0 )
//drag to the beginning
mouseMove(thumb, thumb.width/2, -sceneThumbY)
//try moving the mouse outside the thumb (to the left, the 10* is random)
//and check that it's still using the pressed state colour
mouseMove(thumb, -10*thumb.width/2, -sceneThumbY)
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true,
"Not showing pressed colour after dragging the thumb up and moving mouse outside of it without releasing.")
//move mouse back inside the thumb
mouseMove(thumb, thumb.width/2, -sceneThumbY)
//check pressed colour again
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true,
"Not showing pressed colour after dragging the thumb up and moving mouse outside of it and back in, without releasing.")
mouseRelease(thumb, 0, 0)
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Thumb does not show as hovered after mouse is dragged and released inside of it.")
compare(flickable[scrollbarUtils.propContent], -flickable.topMargin,
"Vertical thumb mouse drag: wrong contentProp after dragging to the beginning")
} else {
mouseDrag(thumb, thumb.width/2, thumb.height/2, trough.width, 0)
compare(flickable[scrollbarUtils.propContent],
flickable.contentWidth + flickable.rightMargin - flickable.width,
"Horizontal thumb mouse drag: wrong contentProp after dragging to the end")
var sceneThumbX = thumb.mapToItem(column, 0, 0).x
//Can't use mouseDrag here, see the explanation inside the "if" branch
mousePress(thumb, thumb.width/2, thumb.height/2)
mouseMove(thumb, 0, thumb.height/2 )
//drag to beginning
mouseMove(thumb, -sceneThumbX, thumb.height/2)
//try moving the mouse outside the thumb (to the top, the 10* is random)
//and check that it's still using the pressed state colour
mouseMove(thumb, -sceneThumbX, -10*thumb.height/2)
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true,
"Not showing pressed colour after dragging the thumb up and moving mouse outside of it without releasing.")
//move mouse back inside the thumb
mouseMove(thumb, -sceneThumbX, thumb.height/2)
//check pressed colour again
compare(Qt.colorEqual(thumb.color, thumbPressedColor), true,
"Not showing pressed colour after dragging the thumb up and moving mouse outside of it and back in, without releasing.")
mouseRelease(thumb, 0, 0)
compare(Qt.colorEqual(thumb.color, thumbHoveredColor), true,
"Thumb does not show as hovered after mouse is dragged and released inside of it.")
compare(flickable[scrollbarUtils.propContent], -flickable.leftMargin,
"Horizontal thumb mouse drag: wrong contentProp after dragging to the beginning")
}
}
function test_hinting_data() {
return [
//ownSide here is the side the scrollable cares about, i.e. height for vert scrollbar
{tag: "vertical scrollbar, no scrollable side, short content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: false, scrollableVertically: false, veryLong: false },
{tag: "horizontal scrollbar, no scrollable side, short content item",
alignment: Qt.AlignBottom, scrollableHorizontally: false, scrollableVertically: false, veryLong: false },
{tag: "vertical scrollbar, horizontal side scrollable, short content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: true, scrollableVertically: false, veryLong: false },
{tag: "horizontal scrollbar, horizontal side scrollable, short content item",
alignment: Qt.AlignBottom, scrollableHorizontally: true, scrollableVertically: false, veryLong: false },
{tag: "vertical scrollbar, vertical side scrollable, short content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: false, scrollableVertically: true, veryLong: false },
{tag: "horizontal scrollbar, vertical side scrollable, short content item",
alignment: Qt.AlignBottom, scrollableHorizontally: false, scrollableVertically: true, veryLong: false },
{tag: "vertical scrollbar, both sides scrollable, short content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: true, scrollableVertically: true, veryLong: false },
{tag: "horizontal scrollbar, both sides scrollable, short content item",
alignment: Qt.AlignBottom, scrollableHorizontally: true, scrollableVertically: true, veryLong: false },
{tag: "vertical scrollbar, no scrollable side, long content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: false, scrollableVertically: false, veryLong: true },
{tag: "horizontal scrollbar, no scrollable side, long content item",
alignment: Qt.AlignBottom, scrollableHorizontally: false, scrollableVertically: false, veryLong: true },
{tag: "vertical scrollbar, horizontal side scrollable, long content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: true, scrollableVertically: false, veryLong: true },
{tag: "horizontal scrollbar, horizontal side scrollable, long content item",
alignment: Qt.AlignBottom, scrollableHorizontally: true, scrollableVertically: false, veryLong: true },
{tag: "vertical scrollbar, vertical side scrollable, long content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: false, scrollableVertically: true, veryLong: true },
{tag: "horizontal scrollbar, vertical side scrollable, long content item",
alignment: Qt.AlignBottom, scrollableHorizontally: false, scrollableVertically: true, veryLong: true },
{tag: "vertical scrollbar, both sides scrollable, long content item",
alignment: Qt.AlignTrailing, scrollableHorizontally: true, scrollableVertically: true, veryLong: true },
{tag: "horizontal scrollbar, both sides scrollable, long content item",
alignment: Qt.AlignBottom, scrollableHorizontally: true, scrollableVertically: true, veryLong: true },
];
}
//test that the scrollbar is shown on contentHeight/width changes
function test_hinting(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var style = freshTestItem.scrollbar.__styleInstance
//we'll add it 1gu to simulate a change that doesn't make it become scrollable
//so we need to make sure adding 1gu doesn't make it scrollable
verify(flickable.width > units.gu(5), "Flickable width assumption is satisfied.")
verify(flickable.height > units.gu(5), "Flickable height assumption is satisfied.")
flickable.contentWidth = units.gu(2)
flickable.contentHeight = units.gu(2)
checkNonScrollableState(scrollbar)
if (data.scrollableHorizontally) {
if (data.veryLong) {
setVeryLongContentItem(flickable, style, true)
tryCompare(style, "veryLongContentItem", true, 5000, "Hinting: veryLongContentItem should be true.")
} else {
flickable.contentWidth = flickable.width + units.gu(1)
}
if (!style.isVertical) {
checkHinting(scrollbar)
//wait for the hinting to finish
checkScrollableAndHidden(scrollbar)
} else {
//make sure the scrollbar was not affected by the size change of the opposite side
checkNonScrollableState(scrollbar)
}
}
if (data.scrollableVertically) {
if (data.veryLong) {
setVeryLongContentItem(flickable, style, false)
tryCompare(style, "veryLongContentItem", true, 5000, "Hinting: veryLongContentItem should be true.")
} else {
flickable.contentHeight = flickable.height + units.gu(1)
}
if (style.isVertical) {
checkHinting(scrollbar)
checkScrollableAndHidden(scrollbar)
} else {
//Only make sure that the horiz scrollbar is not scrollable IF
//we didn't previously also make the horizontal side scrollable
if (!data.scrollableHorizontally) {
checkNonScrollableState(scrollbar)
}
}
}
//try changing contentHeight
flickable.contentHeight += units.gu(1)
if (style.isVertical && data.scrollableVertically) {
checkHinting(scrollbar)
checkScrollableAndHidden(scrollbar)
} else if (!style.isVertical && data.scrollableHorizontally) {
compare(style.state, "hidden", "Wrong state.")
} else {
checkNonScrollableState(scrollbar)
}
flickable.contentWidth += units.gu(1)
if (!style.isVertical && data.scrollableHorizontally) {
checkHinting(scrollbar)
checkScrollableAndHidden(scrollbar)
} else if (style.isVertical && data.scrollableVertically) {
compare(style.state, "hidden", "Wrong state.")
} else {
checkNonScrollableState(scrollbar)
}
}
function test_minimumSliderSize(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var trough = getTrough(scrollbar)
var thumb = getThumb(scrollbar)
var style = freshTestItem.scrollbar.__styleInstance
var minSize = style.minimumSliderSize
verify(trough !== null, "Could not find the trough.")
verify(thumb !== null, "Could not find the thumb.")
if (style.isVertical) {
//ignore margins etc, just go for an upper bound
flickable.contentHeight = flickable.height * (flickable.height / minSize) + units.gu(100)
compare(thumb.height, minSize, "Thumb does not respect the minimum size.")
} else {
flickable.contentWidth = flickable.width * (flickable.width / minSize) + units.gu(100)
compare(thumb.width, minSize, "Thumb does not respect the minimum size.")
}
}
function test_scrollingRatioValuesSanityCheck() {
var freshTestItem = getFreshFlickable(Qt.AlignTrailing)
var style = freshTestItem.scrollbar.__styleInstance
verify(style.shortScrollingRatio > 0,
"Short scrolling ratio must be > 0.")
verify(style.longScrollingRatio > 0,
"Short scrolling ratio must be > 0.")
verify(style.shortScrollingRatio <= style.longScrollingRatio,
"Short scrolling ratio is higher than long scrolling ratio.")
}
// NOTE: ANY FAILURE COMING AFTER MOUSEPRESS WILL LEAVE THE MOUSE IN A DIRTY STATE!
// (QQuickWindow's mouseGrabberItem is not reset)
// OTHER TESTS WILL FAIL JUST BECAUSE THIS TEST HAS NOT CALLED MOUSERELEASE!
// I REPORTED https://bugreports.qt.io/browse/QTBUG-51193 TO GET THIS FIXED
function test_resetDragWhenMouseIsVeryFarFromTheThumb(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var thumb = getThumb(scrollbar)
var style = freshTestItem.scrollbar.__styleInstance
//SKIP THE TEST IF THE FEATURE IS DISABLED
verify(style.__disableDragResetFeature !== undefined, "Check that __disableDragResetFeature exists. Remember to enable this test again when the feature is added back.")
if (style.__disableDragResetFeature) return
compare(style.isScrollable, true, "Item is assumed to be scrollable.")
triggerSteppersMode(scrollbar)
var contentXBackup = flickable.contentX
var contentYBackup = flickable.contentY
//coords of the 2 mouse move used to simulate a drag
var firstStep = units.gu(5)
var secondStep = units.gu(10)
var releaseCoord = units.gu(11)
mousePress(thumb, 0, 0)
mouseMove(thumb,
(style.isVertical ? 0 : firstStep),
(style.isVertical ? firstStep : 0))
mouseMove(thumb,
(style.isVertical ? 0 : secondStep),
(style.isVertical ? secondStep : 0))
var newContentX = flickable.contentX
var newContentY = flickable.contentY
if (style.isVertical) {
verify(newContentY !== contentYBackup, "Check that mouse drag changed contentY." )
} else {
verify(newContentX !== contentXBackup, "Check that mouse drag changed contentX." )
}
mouseMove(thumb,
(style.isVertical ? dragResetThreshold(scrollbar)+1 : secondStep),
(style.isVertical ? secondStep : dragResetThreshold(scrollbar)+1))
//check that it goes back to the pre-drag content position, as if the drag never started
checkNoContentPositionChange("Mouse drag reset", flickable, contentXBackup, contentYBackup)
//go back to the old position
mouseMove(thumb,
(style.isVertical ? 0 : secondStep),
(style.isVertical ? secondStep : 0))
//resume the drag by moving at least 1 px (scrollbar should have 0 drag threshold)
mouseMove(thumb,
(style.isVertical ? 0 : secondStep + style.dragThreshold + 1),
(style.isVertical ? secondStep + style.dragThreshold + 1 : 0))
//NOTE: now the thumb has moved, adding another mouseMove here will use
//coordinates relative to the NEW position!
mouseMove(thumb,
(style.isVertical ? 0 : -(style.dragThreshold + 1)),
(style.isVertical ? -(style.dragThreshold + 1) : 0))
//check that it goes back to the pre-drag content position, as if the drag never started
checkNoContentPositionChange("Mouse drag reset", flickable, contentXBackup, contentYBackup)
//test that we resume dragging
if (style.isVertical) {
verify(newContentY !== contentYBackup, "Check that mouse drag changed contentY." )
} else {
verify(newContentX !== contentXBackup, "Check that mouse drag changed contentX." )
}
//try moving the other way
//FIXME: I'M USING +7 BECAUSE THE LOGIC USES (mouse.x - thumbArea.x)
//AND HERE WE START AT 5px AND THEN MOVE BY 10x + 1
//THE LOGIC HAS TO USE A DIFFERENT CONDITION
mouseMove(thumb,
(style.isVertical ? -(dragResetThreshold(scrollbar) + 7) : secondStep),
(style.isVertical ? secondStep : -(dragResetThreshold(scrollbar) + 7)))
//check that it goes back to the pre-drag content position, as if the drag never started
checkNoContentPositionChange("Mouse drag reset", flickable, contentXBackup, contentYBackup)
mouseRelease(thumb,
(style.isVertical ? -(dragResetThreshold(scrollbar) + 7) : secondStep),
(style.isVertical ? secondStep : -(dragResetThreshold(scrollbar) + 7)))
}
function test_actionSteppers_data() {
return [
{tag:"Content item with margins and vertical scrollbar", addContentMargins: true, alignment: Qt.AlignTrailing},
{tag:"Content item and vertical scrollbar", addContentMargins: false, alignment: Qt.AlignTrailing},
{tag:"Content item with margins and horizontal scrollbar", addContentMargins: true, alignment: Qt.AlignBottom},
{tag:"Content item and horizontal scrollbar", addContentMargins: false, alignment: Qt.AlignBottom}
];
}
function test_actionSteppers(data) {
skip("Scrollbar already in steppers mode under Qt 5.9, causing failure.")
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
var trough = getTrough(scrollbar)
var thumb = getThumb(scrollbar)
var firstStepper = getFirstStepper(scrollbar)
var secondStepper = getSecondStepper(scrollbar)
var style = freshTestItem.scrollbar.__styleInstance
var minSize = style.minimumSliderSize
if (data.addContentMargins) {
addContentMargins(flickable)
}
triggerSteppersMode(scrollbar)
setContentPositionToTopLeft(flickable)
var contentXBackup = flickable.contentX
var contentYBackup = flickable.contentY
clickOnStepperAndCheckNoContentPositionChange("First stepper", firstStepper, flickable,
contentXBackup, contentYBackup)
//NOTE: mouseClick(secondStepper, 0, 0) would trigger firstStepper, because
//the logic uses contains(point) that also counts the edges!
//(the code uses if firstStepper.contains else if secondStepper.contains
//so it stops at the first branch)
clickInTheMiddle(secondStepper)
checkScrolling(flickable, contentXBackup, contentYBackup, style,
false, 1, "Second stepper, first click")
contentXBackup = flickable.contentX
contentYBackup = flickable.contentY
//do it once more
clickInTheMiddle(secondStepper)
checkScrolling(flickable, contentXBackup, contentYBackup, style,
false, 1, "Second stepper, second click")
setContentPositionToBottomRight(flickable)
contentXBackup = flickable.contentX
contentYBackup = flickable.contentY
clickOnStepperAndCheckNoContentPositionChange("Second stepper", secondStepper, flickable,
contentXBackup, contentYBackup)
clickInTheMiddle(firstStepper)
checkScrolling(flickable, contentXBackup, contentYBackup, style,
false, -1, "First stepper, first click")
contentXBackup = flickable.contentX
contentYBackup = flickable.contentY
//do it once more
clickInTheMiddle(firstStepper)
checkScrolling(flickable, contentXBackup, contentYBackup, style,
false, -1, "First stepper, second click")
}
//check that the mouse filters handling the interactions with the thumb and steppers
//ignore the synthesized events. This is required to have the correct hover handling,
//because it's the way we make sure that the hover logic is only called for real mouse
//events, and not touch-to-mouse synthesized events
function test_ignoreSynthesizedEventsInMouseFilters() {
var scrollbar = defaultValuesScrollbar
var style = scrollbar.__styleInstance
var thumbArea = getThumbArea(scrollbar)
var steppersMouseArea = getSteppersMouseArea(scrollbar)
compare(thumbArea.Mouse.ignoreSynthesizedEvents, true,
"The mouse filter in the thumb MouseArea does not ignore synthesized events. Hover state logic may be affected.")
compare(steppersMouseArea.Mouse.ignoreSynthesizedEvents, true,
"The mouse filter in the steppers MouseArea does not ignore synthesized events. Hover state logic may be affected.")
}
function test_defaultStylingValues() {
var scrollbar = defaultValuesScrollbar
var style = scrollbar.__styleInstance
/*****************************************************
* STYLING PROPERTIES *
*****************************************************/
compare(style.interactive, style.isMouseConnected || style.veryLongContentItem, "Wrong styling property default value.")
compare(style.minimumSliderSize, units.gu(1), "Wrong styling property default value.")
compare(style.overlay, !style.alwaysOnScrollbars, "Wrong styling property default value.")
compare(style.overlayOpacityWhenShown, 1.0, "Wrong styling property default value.")
compare(style.overlayOpacityWhenHidden, 0.0, "Wrong styling property default value.")
compare(style.troughThicknessSteppersStyle, units.dp(14), "Wrong styling property default value.")
compare(style.troughThicknessThumbStyle, units.dp(14), "Wrong styling property default value.")
compare(style.troughThicknessIndicatorStyle, units.dp(9), "Wrong styling property default value.")
compare(style.troughColorThumbStyle, theme.palette.normal.foreground, "Wrong styling property default value.")
compare(style.troughColorSteppersStyle, theme.palette.normal.foreground, "Wrong styling property default value.")
compare(style.stepperBgColor, theme.palette.normal.base, "Wrong styling property default value.")
compare(style.sliderColor, theme.palette.normal.overlayText, "Wrong styling property default value.")
compare(style.sliderRadius, units.dp(3), "Wrong styling property default value.")
compare(style.thumbThickness, units.gu(1), "Wrong styling property default value.")
compare(style.indicatorThickness, units.dp(3), "Wrong styling property default value.")
compare(style.scrollbarThicknessAnimation.duration, LomiriAnimation.SnapDuration, "Wrong styling property default value.")
compare(style.scrollbarFadeInAnimation.duration, LomiriAnimation.SlowDuration, "Wrong styling property default value.")
compare(style.scrollbarFadeOutAnimation.duration, LomiriAnimation.SlowDuration, "Wrong styling property default value.")
compare(style.scrollbarFadeOutPause, 3000, "Wrong styling property default value.")
compare(style.scrollbarCollapsePause, 1000, "Wrong styling property default value.")
compare(style.shortScrollingRatio, 0.1, "Wrong styling property default value.")
compare(style.longScrollingRatio, 0.9, "Wrong styling property default value.")
compare(style.hintingStyle, style.veryLongContentItem ? 'thumb' : 'indicator', "Wrong styling property default value.")
compare(style.thumbsExtremesMargin, units.dp(4), "Wrong styling property default value.")
/*****************************************************
* HELPER PROPERTIES *
*****************************************************/
var slider = getThumb(scrollbar)
var trough = getTrough(scrollbar)
compare(style.thumb, slider, "Wrong styling property default value.")
compare(style.trough, trough, "Wrong styling property default value.")
compare(style.isScrollable, scrollbar.__private.scrollable && style.pageSize > 0.0
&& style.contentSize > 0.0 && style.totalContentSize > style.pageSize, "Wrong styling property default value.")
compare(style.isVertical, (scrollbar.align === Qt.AlignLeading) || (scrollbar.align === Qt.AlignTrailing), "Wrong styling property default value.")
compare(style.frontAligned, scrollbar.align === Qt.AlignLeading, "Wrong styling property default value.")
compare(style.rearAligned, scrollbar.align === Qt.AlignTrailing, "Wrong styling property default value.")
compare(style.topAligned, scrollbar.align === Qt.AlignTop, "Wrong styling property default value.")
compare(style.bottomAligned, scrollbar.align === Qt.AlignBottom, "Wrong styling property default value.")
//flickable helper properties
compare(style.flickableItem, scrollbar.flickableItem, "Wrong styling property default value.")
compare(style.pageSize, (style.isVertical) ? (scrollbar.flickableItem.height) : (scrollbar.flickableItem.width), "Wrong styling property default value.")
compare(style.contentSize, (style.isVertical) ? scrollbar.flickableItem.contentHeight : scrollbar.flickableItem.contentWidth, "Wrong styling property default value.")
compare(style.leadingContentMargin, style.isVertical ? scrollbar.flickableItem.topMargin : scrollbar.flickableItem.leftMargin, "Wrong styling property default value.")
compare(style.trailingContentMargin, style.isVertical ? scrollbar.flickableItem.bottomMargin : scrollbar.flickableItem.rightMargin, "Wrong styling property default value.")
compare(style.totalContentSize, style.contentSize + style.leadingContentMargin + style.trailingContentMargin, "Wrong styling property default value.")
/*****************************************************
* INTERNAL PROPERTIES AND FUNCTIONS *
*****************************************************/
var thumbArea = getThumbArea(scrollbar)
var scrollAnimation = getScrollAnimation(scrollbar)
compare(style.__recursionGuard, false, "Wrong styling property default value.")
compare(style.__disableStateBinding, false, "Wrong styling property default value.")
compare(style.__hinting, false, "Wrong styling property default value.")
compare(style.draggingThumb, thumbArea.drag.active || slider.mouseDragging || slider.touchDragging, "Wrong styling property default value.")
compare(style.thumbStyleFlag, style.veryLongContentItem && (scrollbar.flickableItem.moving || scrollAnimation.running), "Wrong styling property default value.")
compare(style.veryLongContentItem, scrollbar.flickableItem && style.initialized
&& ((scrollbar.flickableItem.contentHeight > scrollbar.flickableItem.height * 10)
|| (scrollbar.flickableItem.contentWidth > scrollbar.flickableItem.width * 10)), "Wrong styling property default value.")
compare(style.isMouseConnected, true, "Wrong styling property default value.")
compare(style.nonOverlayScrollbarMargin, style.troughThicknessSteppersStyle, "Wrong styling property default value.")
compare(style.useSteppers, true, "Wrong styling property default value.")
compare(style.touchDragStartMargin, units.gu(2), "Wrong styling property default value.")
compare(style.dragThreshold, units.dp(2), "Wrong styling property default value.")
compare(style.alwaysOnScrollbars, scrollbar.__alwaysOnScrollbars, "Wrong styling property default value.")
}
//just a few tests to ensure the key variables don't get out of range values
//NOTE: this does not test that the properties have the correct value, just that
//their values is not out of range (so it only applies to numeric values)
function test_sanityCheckStylingVariables() {
flickableSanityCheck.contentHeight = contentSanityCheck.height
flickableSanityCheck.contentWidth = contentSanityCheck.width
performStyleSanityCheck(scrollbarSanityCheck)
flickableSanityCheck.contentHeight = -contentSanityCheck.height
flickableSanityCheck.contentWidth = -contentSanityCheck.width
performStyleSanityCheck(scrollbarSanityCheck)
flickableSanityCheck.topMargin = units.gu(1)
flickableSanityCheck.leftMargin = units.gu(2)
flickableSanityCheck.rightMargin = units.gu(3)
flickableSanityCheck.bottomMargin = units.gu(4)
performStyleSanityCheck(scrollbarSanityCheck)
flickableSanityCheck.topMargin = -units.gu(1)
flickableSanityCheck.leftMargin = -units.gu(2)
flickableSanityCheck.rightMargin = -units.gu(3)
flickableSanityCheck.bottomMargin = -units.gu(4)
performStyleSanityCheck(scrollbarSanityCheck)
}
//Test that Scrollbar defaults to Flickable.topMargin/bottomMargin (content margins)
//as its ANCHORS margins
function test_topBottomMargins(data) {
var freshTestItem = getFreshFlickable(data.alignment)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
compare(scrollbar.__styleInstance.isScrollable, true, "The view is not scrollable.")
compare(scrollbar.__styleInstance.alwaysOnScrollbars, false, "This test assumes overlay scrollbars (if you need to change this, fix the expected margins).")
compare(scrollbar.anchors.topMargin, flickable.topMargin, "Wrong anchors.topMargin.")
compare(scrollbar.anchors.bottomMargin, flickable.bottomMargin, "Wrong anchors.bottomMargin.")
flickable.topMargin = units.gu(1)
compare(scrollbar.anchors.topMargin, units.gu(1), "Wrong anchors.topMargin.")
compare(scrollbar.anchors.bottomMargin, flickable.bottomMargin, "Wrong anchors.bottomMargin.")
flickable.bottomMargin = units.gu(3)
compare(scrollbar.anchors.topMargin, units.gu(1), "Wrong anchors.topMargin.")
compare(scrollbar.anchors.bottomMargin, units.gu(3), "Wrong anchors.bottomMargin.")
flickable.topMargin = 0
flickable.bottomMargin = units.gu(6)
compare(scrollbar.anchors.topMargin, 0, "Wrong anchors.topMargin.")
compare(scrollbar.anchors.bottomMargin, units.gu(6), "Wrong anchors.bottomMargin.")
}
//check that we don't output lots of warnings when the flickable item becomes null
//(it could happen while transitioning values or before the Binding applies and similar situations)
function test_noWarningsWhenFlickableIsNull() {
var freshTestItem = getFreshFlickable(Qt.AlignTrailing)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
verify(scrollbar.flickableItem !== null, "Check that Scrollbar is linked to a Flickable.")
//try triggering warnings (they will be marked as failures by the SDK test runner)
scrollbar.flickableItem = null
var secondScrollbar = freshScrollbar.createObject(freshTestItem)
verify(secondScrollbar !== null, "Error: dynamic item creation failed.")
var style = secondScrollbar.__styleInstance
//check that the default value is correct
compare(style.flickableItem, null, "Wrong style flickableItem")
compare(scrollbar.flickableItem, null, "Wrong scrollbar's flickableItem")
compare(scrollbar.__initializedFlickable, null, "Wrong scrollbar's initialized flickable var")
//check that calling functions that rely on flickableItem doesn't output errors
style.scrollToBeginning()
style.scrollToEnd()
//This test will always pass if run with qmltestrunner, unfortunately there's no way
//using TestCase to do "if (testOutputsWarnings) --> fail", but the SDK test script
//will fail if this test outputs warnings, which is what we want
}
//test that __initializedFlickable has the right value even when
//the Scrollbar is assigned to one Flickable, then to another one (this could
//be useful to reuse the same instance of Scrollbar for multiple Flickables
//if they're only visible one at a time)
function test_initializedFlickableVariableChange() {
var freshTestItem = getFreshFlickable(Qt.AlignTrailing)
var flickable = freshTestItem.flickable
var scrollbar = freshTestItem.scrollbar
//check that the variables are correct when the Scrollbar is initialized with a set Flickable
compare(scrollbar.flickableItem, flickable, "Wrong value of flickableItem")
compare(scrollbar.__initializedFlickable, flickable, "Wrong value of __initializedFlickable")
var secondScrollbar = freshScrollbar.createObject(freshTestItem)
verify(secondScrollbar !== null, "Error: dynamic item creation failed.")
//check that the variables are correct when the Scrollbar is assigned a new Flickable
secondScrollbar.flickableItem = flickable
compare(secondScrollbar.flickableItem, flickable, "Wrong value of flickableItem")
compare(secondScrollbar.__initializedFlickable, flickable, "Wrong value of __initializedFlickable")
//set to null and check that both change
secondScrollbar.flickableItem = null
compare(secondScrollbar.flickableItem, null, "Wrong value of flickableItem")
compare(secondScrollbar.__initializedFlickable, null, "Wrong value of __initializedFlickable")
//set to a valid flickable again and check that both the variables are correctly updated
secondScrollbar.flickableItem = flickable
compare(secondScrollbar.flickableItem, flickable, "Wrong value of flickableItem")
compare(secondScrollbar.__initializedFlickable, flickable, "Wrong value of __initializedFlickable")
secondScrollbar.destroy()
}
}
}
|