DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5350524bb654)

VCS Links

Line Code
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 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Wheel scroll tests"
  width="600" height="600"
  onload="onload();"
  onunload="onunload();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js" />

<body xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
  #rootview {
    overflow: auto;
    width: 400px;
    height: 400px;
    border: 1px solid;
  }
  #container {
    overflow: auto;
    width: 600px;
    height: 600px;
  }
  #rootview pre {
    margin: 20px 0 20px 20px;
    padding: 0;
    overflow: auto;
    display: block;
    width: 100px;
    height: 100.5px;
    font-size: 16px;
  }
</style>
<div id="rootview" onscroll="onScrollView(event);">
  <div id="container">
    <pre id="subview1" onscroll="onScrollView(event);">
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    </pre>
    <pre id="subview2" onscroll="onScrollView(event);">
Text.
Text.
Text.
Text.
Text.
Text.
Text.
Text.
Text.
Text.
    </pre>
    <pre id="subview3" onscroll="onScrollView(event);">
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    </pre>
  </div>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

<script class="testbody" type="application/javascript">
<![CDATA[

function ok(aCondition, aMessage)
{
  window.opener.wrappedJSObject.SimpleTest.ok(aCondition, aMessage);
}

function is(aLeft, aRight, aMessage)
{
  window.opener.wrappedJSObject.SimpleTest.is(aLeft, aRight, aMessage);
}

function isnot(aLeft, aRight, aMessage)
{
  window.opener.wrappedJSObject.SimpleTest.isnot(aLeft, aRight, aMessage);
}

var gCurrentTestListStatus = { nextListIndex: 0 };
var gCurrentTest;

const kListenEvent_None                 = 0;
const kListenEvent_OnScroll             = 1;
const kListenEvent_OnScrollFailed       = 2;
const kListenEvent_OnTransactionTimeout = 4;
const kListenEvent_All = kListenEvent_OnScroll |
                         kListenEvent_OnScrollFailed |
                         kListenEvent_OnTransactionTimeout;
var gLitesnEvents = kListenEvent_None;

/**
 * At unexpected transaction timeout, we need to stop *all* timers.  But it is
 * difficult and it can be create more complex testing code.  So, we should use
 * only one timer at one time.  For that, we must store the timer id to this
 * variable.  And the functions which may be called via a timer must clear the
 * current timer by |_clearTimer| function.
 */
var gTimer;

var gPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].
               getService(Components.interfaces.nsIPrefBranch);
const kPrefSmoothScroll = "general.smoothScroll";
const kPrefNameTimeout = "mousewheel.transaction.timeout";
const kPrefNameIgnoreMoveDelay = "mousewheel.transaction.ignoremovedelay";
const kPrefTestEventsAsyncEnabled = "test.events.async.enabled";

const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);
const kDefaultIgnoreMoveDelay = gPrefSvc.getIntPref(kPrefNameIgnoreMoveDelay);

gPrefSvc.setBoolPref(kPrefSmoothScroll, false);
gPrefSvc.setBoolPref(kPrefTestEventsAsyncEnabled, true);

var gTimeout, gIgnoreMoveDelay;
var gEnoughForTimeout, gEnoughForIgnoreMoveDelay;

function setTimeoutPrefs(aTimeout, aIgnoreMoveDelay)
{
  gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
  gPrefSvc.setIntPref(kPrefNameIgnoreMoveDelay, aIgnoreMoveDelay);
  gTimeout = aTimeout;
  gIgnoreMoveDelay = aIgnoreMoveDelay;
  gEnoughForTimeout = gTimeout * 2;
  gEnoughForIgnoreMoveDelay = gIgnoreMoveDelay * 1.2;
}

function resetTimeoutPrefs()
{
  if (gTimeout == kDefaultTimeout)
    return;
  setTimeoutPrefs(kDefaultTimeout, kDefaultIgnoreMoveDelay);
  initTestList();
}

function growUpTimeoutPrefs()
{
  if (gTimeout != kDefaultTimeout)
    return;
  setTimeoutPrefs(5000, 1000);
  initTestList();
}

// setting enough time for testing.
gPrefSvc.setIntPref(kPrefNameTimeout, gTimeout);
gPrefSvc.setIntPref(kPrefNameIgnoreMoveDelay, gIgnoreMoveDelay);

var gRootView = document.getElementById("rootview");
var gSubView1 = document.getElementById("subview1");
var gSubView2 = document.getElementById("subview2");
var gSubView3 = document.getElementById("subview3");

gRootView.addEventListener("MozMouseScrollFailed", onMouseScrollFailed, false);
gRootView.addEventListener("MozMouseScrollTransactionTimeout",
                           onTransactionTimeout, false);

function finish()
{
  window.close();
}

function onload()
{
  runNextTestList();
}

function onunload()
{
  resetTimeoutPrefs();
  gPrefSvc.clearUserPref(kPrefSmoothScroll);
  gPrefSvc.clearUserPref(kPrefTestEventsAsyncEnabled);
  disableNonTestMouseEvents(false);
  SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
  window.opener.wrappedJSObject.SimpleTest.finish();
}

const kSubView1Offset = { x: 20, y: 20 };
const kSubView2Offset = { x: 20, y: 20 + 100 + 20 };
const kSubView3Offset = { x: 20, y: 20 + (100 + 20) * 2 };

function _getSubViewTestPtForV(aPt)
{
  return { x: aPt.x + 10, y: aPt.y + 10 };
}

const kPtInRootViewForV = { x: kSubView1Offset.x + 10,
                            y: kSubView1Offset.y - 10 };
const kPtInSubView1ForV = _getSubViewTestPtForV(kSubView1Offset);
const kPtInSubView2ForV = _getSubViewTestPtForV(kSubView2Offset);
const kPtInSubView3ForV = _getSubViewTestPtForV(kSubView3Offset);

function _convertTestPtForH(aPt)
{
  return { x: aPt.y, y: aPt.x };
}

const kPtInRootViewForH = _convertTestPtForH(kPtInRootViewForV);
const kPtInSubView1ForH = _convertTestPtForH(kPtInSubView1ForV);
const kPtInSubView2ForH = _convertTestPtForH(kPtInSubView2ForV);
const kPtInSubView3ForH = _convertTestPtForH(kPtInSubView3ForV);

/**
 * Define the tests here:
 *   Scrolls are processed async always.  Therefore, we need to call all tests
 *   by timer.  gTestLists is array of testing lists. In other words, an item
 *   of gTestList is a group of one or more testing. Each items has following
 *   properties:
 *
 *     - retryWhenTransactionTimeout
 *         The testing of wheel transaction might be fialed randomly by
 *         timeout.  Then, automatically the failed test list will be retested
 *         automatically only this number of times.
 *
 *     - steps
 *         This property is array of testing.  Each steps must have following
 *         properties at least.
 *
 *         - func
 *             This property means function which will be called via
 *             |setTimeout|.  The function cannot have params.  If you need
 *             some additional parameters, you can specify some original
 *             properties for the test function.  If you do so, you should
 *             document it in the testing function.
 *         - delay
 *             This property means delay time until the function to be called.
 *             I.e., the value used for the second param of |setTimeout|.
 *
 *         And also you need one more property when you call a testing function.
 *
 *         - description
 *             This property is description of the test.  This is used for
 *             logging.
 *
 *         At testing, you can access to current step via |gCurrentTest|.
 */

var gTestLists;
function initTestList()
{
  gTestLists = [
    /**************************************************************************
     * Continuous scrolling test for |gRootView|
     *   |gRootView| has both scrollbars and it has three children which are
     *   |gSubView1|, |gSubView2| and |gSubView3|.  They have scrollbars.  If
     *   the current transaction targets |gRootView|, other children should not
     *   be scrolled even if the wheel events are fired on them.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Vertical wheel events should scroll |gRootView| even if the position
        // of wheel events in a child view which has scrollbar.
        { func: testContinuousScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Continuous scrolling test for root view (vertical/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Continuous scrolling test for root view (vertical/backward)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Horizontal wheel events should scroll |gRootView| even if the
        // position of wheel events in a child view which has scrollbar.
        { func: testContinuousScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Continuous scrolling test for root view (horizontal/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Continuous scrolling test for root view (horizontal/backward)" }
      ]
    },


    /**************************************************************************
     * Continuous scrolling test for |gSubView1|
     *   |gSubView1| has both scrollbars.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Vertical wheel events should scroll |gSubView1|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Continuous scrolling test for sub view 1 (vertical/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: false, isVertical: true, expectedView: gSubView1,
          description: "Continuous scrolling test for sub view 1 (vertical/backward)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Horitontal wheel events should scroll |gSubView1|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          description: "Continuous scrolling test for sub view 1 (horizontal/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: false, isVertical: false, expectedView: gSubView1,
          description: "Continuous scrolling test for sub view 1 (horizontal/backward)" }
      ]
    },


    /**************************************************************************
     * Continuous scrolling test for |gSubView2|
     *   |gSubView2| has only vertical scrollbar.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Vertical wheel events should scroll |gSubView2|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView2ForV,
          isForward: true, isVertical: true, expectedView: gSubView2,
          description: "Continuous scrolling test for sub view 2 (vertical/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView2ForV,
          isForward: false, isVertical: true, expectedView: gSubView2,
          description: "Continuous scrolling test for sub view 2 (vertical/backward)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Horizontal wheel events should scroll its nearest scrollable ancestor
        // view, i.e., it is |gRootView|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView2ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Continuous scrolling test for sub view 2 (horizontal/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView2ForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Continuous scrolling test for sub view 2 (horizontal/backward)" }
      ]
    },


    /**************************************************************************
     * Continuous scrolling test for |gSubView3|
     *   |gSubView3| has only horizontal scrollbar.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Vertical wheel events should scroll its nearest scrollable ancestor
        // view, i.e., it is |gRootView|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView3ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Continuous scrolling test for sub view 3 (vertical/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView3ForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Continuous scrolling test for sub view 3 (vertical/backward)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Horitontal wheel events should scroll |gSubView3|.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView3ForH,
          isForward: true, isVertical: false, expectedView: gSubView3,
          description: "Continuous scrolling test for sub view 3 (horizontal/forward)" },
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView3ForH,
          isForward: false, isVertical: false, expectedView: gSubView3,
          description: "Continuous scrolling test for sub view 3 (horizontal/backward)" }
      ]
    },


    /**************************************************************************
     * Don't reset transaction by a different direction wheel event
     *   Even if a wheel event doesn't same direction as last wheel event, the
     *   current transaction should not be reset.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical -> Horizontal
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView| by a vertical wheel
        // event.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Don't reset transaction by a different direction wheel event (1-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Don't reset transaction by a different direction wheel event (1-2)" },
        // Send a horizontal wheel event over |gSubView1| but |gRootView| should
        // be scrolled.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Don't reset transaction by a different direction wheel event (1-3)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal -> Vertical
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView| by a horizontal wheel
        // event.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Don't reset transaction by a different direction wheel event (2-1)" },
        // Scroll back to left-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Don't reset transaction by a different direction wheel event (2-2)" },
        // Send a vertical wheel event over |gSubView1| but |gRootView| should
        // be scrolled.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Don't reset transaction by a different direction wheel event (2-3)" }
      ]
    },


    /**************************************************************************
     * Don't reset transaction even if a wheel event cannot scroll
     *   Even if a wheel event cannot scroll to specified direction in the
     *   current target view, the transaction should not be reset.  E.g., there
     *   are some devices which can scroll obliquely.  If so, probably, users
     *   cannot input only intended direction.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // A view only has vertical scrollbar case.
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gSubView2|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView2ForV,
          isForward: true, isVertical: true, expectedView: gSubView2,
          description: "Don't reset transaction even if a wheel event cannot scroll (1-1)" },
        // |gSubView2| doesn't have horizontal scrollbar but should not scroll
        // any views.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView2ForV,
          isForward: true, isVertical: false, expectedView: null,
          description: "Don't reset transaction even if a wheel event cannot scroll (1-2)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // A view only has horizontal scrollbar case.
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gSubView3|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView3ForV,
          isForward: true, isVertical: false, expectedView: gSubView3,
          description: "Don't reset transaction even if a wheel event cannot scroll (2-1)" },
        // |gSubView3| doesn't have vertical scrollbar but should not scroll any
        // views.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView3ForV,
          isForward: true, isVertical: true, expectedView: null,
          description: "Don't reset transaction even if a wheel event cannot scroll (2-2)" }
      ]
    },


    /**************************************************************************
     * Reset transaction by mouse down/mouse up events
     *   Mouse down and mouse up events should cause resetting the current
     *   transaction.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by mouse down/mouse up events (v-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by mouse down/mouse up events (v-2)" },
        // Send mouse button events which should reset the current transaction.
        // So, the next wheel event should scroll |gSubView1|.
        { func: sendMouseButtonEvents, delay: 0,
          description: "sendMouseButtonEvents" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Reset transaction by mouse down/mouse up events (v-3)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Reset transaction by mouse down/mouse up events (h-1)" },
        // Scroll back to left-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Reset transaction by mouse down/mouse up events (h-2)" },
        // Send mouse button events which should reset the current transaction.
        // So, the next wheel event should scroll |gSubView1|.
        { func: sendMouseButtonEvents, delay: 0,
          description: "sendMouseButtonEvents" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          description: "Reset transaction by mouse down/mouse up events (h-3)" }
      ]
    },


    /**************************************************************************
     * Reset transaction by a key event
     *   A key event should cause resetting the current transaction.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a key event (v-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a key event (v-2)" },
        // Send a key event which should reset the current transaction.  So, the
        // next wheel event should scroll |gSubView1|.
        { func: sendKeyEvents, delay: 0, key: "a",
          description: "sendKeyEvents" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Reset transaction by a key event (v-3)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Reset transaction by a key event (h-1)" },
        // Scroll back to left-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Reset transaction by a key event (h-2)" },
        // Send a key event which should reset the current transaction.  So, the
        // next wheel event should scroll |gSubView1|.
        { func: sendKeyEvents, delay: 0, key: "a",
          description: "sendKeyEvents" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          description: "Reset transaction by a key event (h-3)" }
      ]
    },


    /**************************************************************************
     * Reset transaction by a mouse move event
     *   A mouse move event can cause reseting the current transaction even if
     *   mouse cursor is inside the target view of current transaction. Only
     *   when a wheel event is fired after |gIgnoreMoveDelay| milliseconds since
     *   the first mouse move event from last wheel event, the transaction
     *   should be reset.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a mouse move event (v-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a mouse move event (v-2)" },
        // Send a mouse move event immediately after last wheel event, then,
        // current transaction should be kept.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInSubView1ForV,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-3)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-4)" },
        // Send a mouse move event after |gIgnoreMoveDelay| milliseconds since
        // last wheel event, then, current transaction should be kept.
        { func: sendMouseMoveEvent, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForV,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-5)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-6)" },
        // Send a wheel event after |gIgnoreMoveDelay| milliseconds since last
        // mouse move event but it is fired immediately after the last wheel
        // event, then, current transaction should be kept.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInSubView1ForV,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-7)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (v-8)" },
        // Send a wheel event after |gIgnoreMoveDelay| milliseconds have passed
        // since last mouse move event which is fired after |gIgnoreMoveDelay|
        // milliseconds since last wheel event, then, current transaction should
        // be reset.
        { func: sendMouseMoveEvent, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForV,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          canFailRandomly: { possibleView: gRootView },
          description: "Reset transaction by a mouse move event (v-9)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-2)" },
        // Send a mouse move event immediately after last wheel event, then,
        // current transaction should be kept.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInSubView1ForH,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-3)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-4)" },
        // Send a mouse move event after |gIgnoreMoveDelay| milliseconds since
        // last wheel event, then, current transaction should be kept.
        { func: sendMouseMoveEvent, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForH,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-5)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-6)" },
        // Send a wheel event after |gIgnoreMoveDelay| milliseconds since last
        // mouse move event but it is fired immediately after the last wheel
        // event, then, current transaction should be kept.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInSubView1ForH,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-7)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Reset transaction by a mouse move event (h-8)" },
        // Send a wheel event after |gIgnoreMoveDelay| milliseconds have passed
        // since last mouse move event which is fired after |gIgnoreMoveDelay|
        // milliseconds since last wheel event, then, current transaction should
        // be reset.
        { func: sendMouseMoveEvent, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForH,
          description: "sendMouseMoveEvent" },
        { func: testOneTimeScroll, delay: gEnoughForIgnoreMoveDelay,
          offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          canFailRandomly: { possibleView: gRootView },
          description: "Reset transaction by a mouse move event (h-9)" }
      ]
    },


    /**************************************************************************
     * Reset transaction by a mouse move event on outside of view
     *   When mouse cursor is moved to outside of the current target view, the
     *   transaction should be reset immediately.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gSubView1|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Reset transaction by a mouse move event on outside of view (v-1)" },
        // Send mouse move event over |gRootView|.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInRootViewForV,
          description: "sendMouseMoveEvent" },
        // Send Wheel event over |gRootView| which should be scrolled.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a mouse move event on outside of view (v-2)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Create a transaction which targets |gSubView1|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Reset transaction by a mouse move event on outside of view (h-1)" },
        // Send mouse move event over |gRootView|.
        { func: sendMouseMoveEvent, delay: 0, offset: kPtInRootViewForH,
          description: "sendMouseMoveEvent" },
        // Send Wheel event over |gRootView| which should be scrolled.
        { func: testOneTimeScroll, delay: 0,  offset: kPtInRootViewForH,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Reset transaction by a mouse move event on outside of view (h-2)" }
      ]
    },


    /**************************************************************************
     * Timeout test
     *   A view should not be scrolled during another to be transaction for
     *   another view scrolling. However, a wheel event which is sent after
     *   timeout, a view which is under the mouse cursor should be scrolled.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // First, create a transaction which should target the |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Timeout test (v-1)" },
        // Scroll back to top-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          description: "Timeout test (v-2)" },
        // A wheel event over |gSubView1| should not scroll it during current
        // transaction.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Timeout test (v-3)" },
        // Scroll back to top-most again.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: false, isVertical: true, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Timeout test (v-4)" },
        // A wheel event over |gSubView1| after timeout should scroll
        // |gSubView1|.
        { func: testOneTimeScroll, delay: gEnoughForTimeout,
          offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          isTimeoutTesting: true,
          description: "Timeout test (v-5)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // First, create a transaction which should target the |gRootView|.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Timeout test (h-1)" },
        // Scroll back to left-most for easy cursor position specifying.
        { func: testOneTimeScroll, delay: 0, offset: kPtInRootViewForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          description: "Timeout test (h-2)" },
        // A wheel event over |gSubView1| should not scroll it during current
        // transaction.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Timeout test (h-3)" },
        // Scroll back to left-most again.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: false, isVertical: false, expectedView: gRootView,
          canFailRandomly: { possibleView: gSubView1 },
          description: "Timeout test (h-4)" },
        // A wheel event over |gSubView1| after timeout should scroll
        // |gSubView1|.
        { func: testOneTimeScroll, delay: gEnoughForTimeout,
          offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          isTimeoutTesting: true,
          description: "Timeout test (h-5)" }
      ]
    },


    /**************************************************************************
     * Timeout test even with many wheel events
     *   This tests whether timeout is occurred event if wheel events are sent.
     *   The transaction should not be updated by non-scrollable wheel events.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        // Vertical case
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Scroll |gSubView1| to bottom-most.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          description: "Timeout test even with many wheel events (v-1)" },
        // Don't scroll any views before timeout.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: null,
          canFailRandomly: { possibleView: gRootView },
          description: "Timeout test even with many wheel events (v-2)" },
        // Recreate a transaction which is scrolling |gRootView| after time out.
        { func: testRestartScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gRootView,
          description: "Timeout test even with many wheel events (v-3)" }
      ]
    },


    { retryWhenTransactionTimeout: 5,
      steps: [
        // Horizontal case
        { func: initElements, delay: 0, forVertical: false,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        // Scroll |gSubView1| to right-most.
        { func: testContinuousScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gSubView1,
          description: "Timeout test even with many wheel events (h-1)" },
        // Don't scroll any views before timeout.
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: null,
          canFailRandomly: { possibleView: gRootView },
          description: "Timeout test even with many wheel events (h-2)" },
        // Recreate a transaction which is scrolling |gRootView| after time out.
        { func: testRestartScroll, delay: 0, offset: kPtInSubView1ForH,
          isForward: true, isVertical: false, expectedView: gRootView,
          description: "Timeout test even with many wheel events (h-3)" }
      ]
    },


    /**************************************************************************
     * Very large scrolling wheel event
     *   If the delta value is larger than the scrolling page size, it should be
     *   scrolled only one page instead of the delta value.
     **************************************************************************/
    { retryWhenTransactionTimeout: 5,
      steps: [
        { func: initElements, delay: 0, forVertical: true,
          description: "initElements" },
        { func: clearWheelTransaction, delay: 0,
          description: "clearWheelTransaction" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          delta: 5000,
          description: "Very large delta scrolling (v-1)" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: true, expectedView: gSubView1,
          delta: 5000,
          description: "Very large delta scrolling (v-2)" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: false, expectedView: gSubView1,
          delta: 5000,
          description: "Very large delta scrolling (h-1)" },
        { func: testOneTimeScroll, delay: 0, offset: kPtInSubView1ForV,
          isForward: true, isVertical: false, expectedView: gSubView1,
          delta: 5000,
          description: "Very large delta scrolling (h-2)" }
      ]
    }
  ];
}

/******************************************************************************
 * Actions for preparing tests
 ******************************************************************************/

function initElements()
{
  _clearTimer();

  function resetScrollPosition(aElement)
  {
    aElement.scrollTop = 0;
    aElement.scrollLeft = 0;
  }

  function initInRootView(aElement, aPt)
  {
    aElement.offset =
      gCurrentTest.forVertical ? aPt : { x: aPt.y, y: aPt.x };
  }

  const kDisplay = gCurrentTest.forVertical ? "block" : "inline-block";
  gSubView1.style.display = kDisplay;
  gSubView2.style.display = kDisplay;
  gSubView3.style.display = kDisplay;

  resetScrollPosition(gRootView);
  resetScrollPosition(gSubView1);
  resetScrollPosition(gSubView2);
  resetScrollPosition(gSubView3);
  _getDOMWindowUtils(window).advanceTimeAndRefresh(0);

  runNextTestStep();
}

function clearWheelTransaction()
{
  _clearTimer();
  _clearTransaction();
  runNextTestStep();
}

function sendKeyEvents()
{
  _clearTimer();
  synthesizeKey(gCurrentTest.key, {}, window);
  runNextTestStep();
}

function sendMouseButtonEvents()
{
  _clearTimer();
  synthesizeMouse(gRootView, -1, -1, { type:"mousedown" }, window);
  synthesizeMouse(gRootView, -1, -1, { type:"mouseup" }, window);
  runNextTestStep();
}

function sendMouseMoveEvent()
{
  _clearTimer();
  _fireMouseMoveEvent(gCurrentTest.offset);
  runNextTestStep();
}

/******************************************************************************
 * Utilities for testing functions
 ******************************************************************************/

function _clearTransaction()
{
  synthesizeMouse(gRootView, -1, -1, { type:"mousedown" }, window);
  synthesizeMouse(gRootView, -1, -1, { type:"mouseup" }, window);
}

function _saveScrollPositions()
{
  function save(aElement)
  {
    aElement.prevTop = aElement.scrollTop;
    aElement.prevLeft = aElement.scrollLeft;
  }
  save(gRootView);
  save(gSubView1);
  save(gSubView2);
  save(gSubView3);
}

function _fireMouseMoveEvent(aOffset)
{
  synthesizeMouse(gRootView, aOffset.x, aOffset.y, { type:"mousemove" }, window);
}

function _fireWheelScrollEvent(aOffset, aIsVertical, aForward, aDelta)
{
  var event = { deltaMode: WheelEvent.DOM_DELTA_LINE };
  if (aIsVertical) {
    event.deltaY = aForward ? aDelta : -aDelta;
  } else {
    event.deltaX = aForward ? aDelta : -aDelta;
  }
  sendWheelAndPaint(gRootView, aOffset.x, aOffset.y, event, null, window);
}

function _canScroll(aElement, aIsVertical, aForward)
{
  if (aIsVertical) {
    if (!aForward)
      return aElement.scrollTop > 0;
    return aElement.scrollHeight > aElement.scrollTop + aElement.clientHeight;
  }
  if (!aForward)
    return aElement.scrollLeft > 0;
  return aElement.scrollWidth > aElement.scrollLeft + aElement.clientWidth;
}

const kNotScrolled      = 0;
const kScrolledToTop    = 1;
const kScrolledToBottom = 2;
const kScrolledToLeft   = 4;
const kScrolledToRight  = 8;

const kScrolledVertical   = kScrolledToTop | kScrolledToBottom;
const kScrolledHorizontal = kScrolledToLeft | kScrolledToRight;

function _getScrolledState(aElement)
{
  var ret = kNotScrolled;
  if (aElement.scrollTop != aElement.prevTop) {
    ret |= aElement.scrollTop < aElement.prevTop ? kScrolledToTop :
                                                   kScrolledToBottom;
  }
  if (aElement.scrollLeft != aElement.prevLeft) {
    ret |= aElement.scrollLeft < aElement.prevLeft ? kScrolledToLeft :
                                                     kScrolledToRight;
  }
  return ret;
}

function _getExpectedScrolledState()
{
  return gCurrentTest.isVertical ?
           gCurrentTest.isForward ? kScrolledToBottom : kScrolledToTop :
           gCurrentTest.isForward ? kScrolledToRight : kScrolledToLeft;
}

function _getScrolledStateText(aScrolledState)
{
  if (aScrolledState == kNotScrolled)
    return "Not scrolled";

  var s = "scrolled to ";
  if (aScrolledState & kScrolledVertical) {
    s += aScrolledState & kScrolledToTop ? "backward" : "forward";
    s += " (vertical)"
    if (aScrolledState & kScrolledHorizontal)
      s += " and to ";
  }
  if (aScrolledState & kScrolledHorizontal) {
    s += aScrolledState & kScrolledToLeft ? "backward" : "forward";
    s += " (horizontal)"
  }
  return s;
}

function _getCurrentTestList()
{
  return gTestLists[gCurrentTestListStatus.nextListIndex - 1];
}

function _clearTimer()
{
  clearTimeout(gTimer);
  gTimer = 0;
}

/******************************************************************************
 * Testing functions
 ******************************************************************************/

/**
 * Note that testing functions must set following variables:
 *
 *   gCurrentTest.repeatTest:  See comment in |continueTest|.
 *   gCurrentTest.autoRepeatDelay:  See comment in |continueTest|.
 *   gListenScrollEvent: When this is not true, the event handlers ignores the
 *                       events.
 */

function testContinuousScroll()
{
  /**
   * Testing continuous scrolling.  This function synthesizes a wheel event.  If
   * the test was success, this function will be recalled automatically.
   * And when a generating wheel event cannot scroll the expected view, this
   * function fires the wheel event only one time.
   *
   * @param gCurrentTest.offset
   *          The cursor position of firing wheel event.  The values are offset
   *          from |gRootView|.
   * @param gCurrentTest.isVertical
   *          Whether the wheel event is for virtical scrolling or horizontal.
   * @param gCurrentTest.isForward
   *          Whether the wheel event is to forward or to backward.
   * @param gCurrentTest.expectedView
   *          The expected view which will be scrolled by wheel event. This
   *          value must not be null.
   */

  _clearTimer();
  _saveScrollPositions();
  if (!gCurrentTest.expectedView) {
    runNextTestStep();
    return;
  }

  gLitesnEvents = kListenEvent_All;
  gCurrentTest.repeatTest = true;
  gCurrentTest.autoRepeatDelay = 0;

  if (!_canScroll(gCurrentTest.expectedView,
                  gCurrentTest.isVertical, gCurrentTest.isForward)) {
    gCurrentTest.expectedView = null;
  }
  var delta = gCurrentTest.delta ? gCurrentTest.delta : 4;
  _fireWheelScrollEvent(gCurrentTest.offset,
                        gCurrentTest.isVertical, gCurrentTest.isForward, delta);
}

function testOneTimeScroll()
{
  /**
   * Testing one wheel event.  |runNextTestStep| will be called immediately
   * after this function by |onScrollView| or |onTimeout|.
   *
   * @param gCurrentTest.offset
   *          The cursor position of firing wheel event.  The values are offset
   *          from |gRootView|.
   * @param gCurrentTest.isVertical
   *          Whether the wheel event is for virtical scrolling or horizontal.
   * @param gCurrentTest.isForward
   *          Whether the wheel event is to forward or to backward.
   * @param gCurrentTest.expectedView
   *          The expected view which will be scrolled by wheel event. This
   *          value can be null.  It means any views should not be scrolled.
   */

  _clearTimer();
  _saveScrollPositions();

  gLitesnEvents = kListenEvent_All;
  gCurrentTest.repeatTest = false;
  gCurrentTest.autoRepeatDelay = 0;

  var delta = gCurrentTest.delta ? gCurrentTest.delta : 4;
  _fireWheelScrollEvent(gCurrentTest.offset,
                        gCurrentTest.isVertical, gCurrentTest.isForward, delta);
}

function testRestartScroll()
{
  /**
   * Testing restart to scroll in expected view after timeout from the current
   * transaction.  This function recall this itself until to success this test
   * or timeout from this test.
   *
   * @param gCurrentTest.offset
   *          The cursor position of firing wheel event.  The values are offset
   *          from |gRootView|.
   * @param gCurrentTest.isVertical
   *          Whether the wheel event is for virtical scrolling or horizontal.
   * @param gCurrentTest.isForward
   *          Whether the wheel event is to forward or to backward.
   * @param gCurrentTest.expectedView
   *          The expected view which will be scrolled by wheel event. This
   *          value must not be null.
   */

  _clearTimer();
  _saveScrollPositions();

  if (!gCurrentTest.wasTransactionTimeout) {
    gCurrentTest.repeatTest = true;
    gCurrentTest.autoRepeatDelay = gTimeout / 3;
    gLitesnEvents = kListenEvent_All;
    gCurrentTest.isTimeoutTesting = true;
    if (gCurrentTest.expectedView) {
      gCurrentTest.expectedViewAfterTimeout = gCurrentTest.expectedView;
      gCurrentTest.expectedView = null;
    }
  } else {
    gCurrentTest.repeatTest = false;
    gCurrentTest.autoRepeatDelay = 0;
    gLitesnEvents = kListenEvent_All;
    gCurrentTest.isTimeoutTesting = false;
    gCurrentTest.expectedView = gCurrentTest.expectedViewAfterTimeout;
  }

  var delta = gCurrentTest.delta ? gCurrentTest.delta : 4;
  _fireWheelScrollEvent(gCurrentTest.offset,
                        gCurrentTest.isVertical, gCurrentTest.isForward, delta);
}

/******************************************************************************
 * Event handlers
 ******************************************************************************/

function onScrollView(aEvent)
{
  /**
   * Scroll event handler of |gRootView|, |gSubView1|, |gSubView2| and 
   * |gSubView3|.  If testing is failed, this function cancels all left tests.
   * For checking the event is expected, the event firer must call
   * |_saveScrollPositions|.
   *
   * @param gCurrentTest.expectedView
   *          The expected view which should be scrolled by the wheel event.
   *          This value can be null.  It means any views should not be
   *          scrolled.
   * @param gCurrentTest.isVertical
   *          The expected view should be scrolled vertical or horizontal.
   * @param gCurrentTest.isForward
   *          The expected view should be scrolled to forward or backward.
   * @param gCurrentTest.canFailRandomly
   *          If this is not undefined, this test can fail by unexpected view
   *          scrolling which is caused by unexpected timeout.  If this is
   *          defined, |gCurrentTest.possibleView| must be set.  If the view is
   *          same as the event target, the failure can be random.  At this
   *          time, we should retry the current test list.
   */

  if (!(gLitesnEvents & kListenEvent_OnScroll))
    return;

  // Now testing a timeout, but a view is scrolled before timeout.
  if (gCurrentTest.isTimeoutTesting && !gCurrentTest.wasTransactionTimeout) {
    is(aEvent.target.id, "",
       "The view scrolled before timeout (the expected view after timeout is " +
         gCurrentTest.expectedView ? gCurrentTest.expectedView.id : "null" +
         "): " + gCurrentTest.description);
    runNextTestList();
    return;
  }

  // Check whether the scrolled event should be fired or not.
  if (!gCurrentTest.expectedView) {
    is(aEvent.target.id, "",
         "no views should be scrolled (" +
         _getScrolledStateText(_getScrolledState(aEvent.target)) + "): " +
         gCurrentTest.description);
    runNextTestList();
    return;
  }

  // Check whether the scrolled view is expected or not.
  if (aEvent.target != gCurrentTest.expectedView) {
    // If current test can fail randomly and the possible view is same as the
    // event target, this failure may be caused by unexpected timeout.
    // At this time, we should retry the current tests with slower settings.
    if (gCurrentTest.canFailRandomly &&
        gCurrentTest.canFailRandomly.possibleView == aEvent.target &&
        gCurrentTestListStatus.retryWhenTransactionTimeout > 0) {
      gCurrentTestListStatus.retryWhenTransactionTimeout--;
      retryCurrentTestList();
      return;
    }
    is(aEvent.target.id, gCurrentTest.expectedView.id,
       "wrong view was scrolled: " + gCurrentTest.description);
    runNextTestList();
    return;
  }

  // Check whether the scrolling direction is expected or not.
  var expectedState = _getExpectedScrolledState();
  var currentState = _getScrolledState(aEvent.target);
  if (expectedState != currentState) {
    is(_getScrolledStateText(currentState),
       _getScrolledStateText(expectedState),
       "scrolled to wrong direction: " + gCurrentTest.description);
    runNextTestList();
    return;
  }

  ok(true, "passed: " + gCurrentTest.description);
  continueTest();
}

function onMouseScrollFailed()
{
  /**
   * Scroll failed event handler. If testing is failed, this function cancels
   * all remains of current test-list, and go to next test-list.
   *
   * NOTE: This event is fired immediately after |_fireWheelScrollEvent|.
   *
   * @param gCurrentTest.expectedView
   *          The expected view which should be scrolled by the wheel event.
   *          This value can be null.  It means any views should not be
   *          scrolled.  When this is not null, this event means the test may
   *          be failed.
   */

  if (!(gLitesnEvents & kListenEvent_OnScrollFailed))
    return;

  ok(!gCurrentTest.expectedView,
     "failed to scroll on current target: " + gCurrentTest.description);
  if (gCurrentTest.expectedView) {
    runNextTestList();
    return;
  }

  continueTest();
}

function onTransactionTimeout()
{
  /**
   * Scroll transaction timeout event handler.  If the timeout is unexpected,
   * i.e., |gCurrentTest.isTimeoutTesting| is not true, this function retry
   * the current test-list.  However, if the current test-list failed by timeout
   * |gCurrentTestListStatus.retryWhenTransactionTimeout| times already, marking
   * to failed the current test-list, and go to next test-list.
   *
   * @param gCurrentTest.expectedView
   *          The expected view which should be scrolled by the wheel event.
   *          This value can be null.  It means any views should not be
   *          scrolled.  When this is not null, this event means the testing may
   *          be failed.
   * @param gCurrentTest.isTimeoutTesting
   *          If this value is true, the current testing have waited this
   *          event.  Otherwise, the testing may be failed.
   * @param gCurrentTestListStatus.retryWhenTransactionTimeout
   *          If |gCurrentTest.isTimeoutTesting| is not true but this event is
   *          fired, the failure may be randomly.  Then, this event handler
   *          retry to test the current test-list until this cound will be zero.
   */

  if (!gCurrentTest.isTimeoutTesting &&
      gCurrentTestListStatus.retryWhenTransactionTimeout > 0) {
    gCurrentTestListStatus.retryWhenTransactionTimeout--;
    // retry current test list
    retryCurrentTestList();
    return;
  }

  gCurrentTest.wasTransactionTimeout = true;

  if (!(gLitesnEvents & kListenEvent_OnTransactionTimeout))
    return;

  ok(gCurrentTest.isTimeoutTesting,
     "transaction timeout: " + gCurrentTest.description);
  if (!gCurrentTest.isTimeoutTesting) {
    runNextTestList();
    return;
  }

  continueTest();
}

/******************************************************************************
 * Main function for this tests
 ******************************************************************************/

function runNextTestStep()
{
  // When this is first time or the current test list is finised, load next
  // test-list.
  _clearTimer();
  if (!gCurrentTest)
    runNextTestList();
  else
    runTestStepAt(gCurrentTestListStatus.nextStepIndex);
}

function runNextTestList()
{
  _clearTimer();

  gLitesnEvents = kListenEvent_None;
  _clearTransaction();
  resetTimeoutPrefs();
  if (gCurrentTestListStatus.nextListIndex >= gTestLists.length) {
    finish();
    return;
  }

  gCurrentTestListStatus.nextListIndex++;
  gCurrentTestListStatus.retryWhenTransactionTimeout =
    _getCurrentTestList().retryWhenTransactionTimeout;
  runTestStepAt(0);
}

function runTestStepAt(aStepIndex)
{
  _clearTimer();

  disableNonTestMouseEvents(true);

  // load a step of testing.
  gCurrentTestListStatus.nextStepIndex = aStepIndex;
  gCurrentTest =
    _getCurrentTestList().steps[gCurrentTestListStatus.nextStepIndex++];
  if (gCurrentTest) {
    gCurrentTest.wasTransactionTimeout = false;
    gTimer = setTimeout(gCurrentTest.func, gCurrentTest.delay);
  } else {
    // If current test-list doesn't have more testing, go to next test-list
    // after cleaning up the current transaction.
    _clearTransaction();
    runNextTestList();
  }
}

function retryCurrentTestList()
{
  _clearTimer();

  gLitesnEvents = kListenEvent_None;
  _clearTransaction();
  ok(true, "WARNING: retry current test-list...");
  growUpTimeoutPrefs(); // retry the test with longer timeout settings.
  runTestStepAt(0);
}

function continueTest()
{
  /**
   * This function is called from an event handler when a test succeeded.
   *
   * @param gCurrentTest.repeatTest
   *          When this is true, onScrollView calls |gCurrentTest.func|. So,
   *          same test can repeat.  Otherwise, this calls |runNextTestStep|.
   * @param gCurrentTest.autoRepeatDelay
   *          The delay value in milliseconds, this is used to call
   *          |gCurrentTest.func| via |setTimeout|.
   */

  _clearTimer();
  gLitesnEvents = kListenEvent_OnTransactionTimeout;

  // We should call each functions via setTimeout. Because sometimes this test
  // is broken by stack overflow.
  if (gCurrentTest.repeatTest) {
    gTimer = setTimeout(gCurrentTest.func, gCurrentTest.autoRepeatDelay);
  } else {
    gTimer = setTimeout(runNextTestStep, 0);
  }
}

]]>
</script>

</window>