toolkit/content/tests/chrome/test_scrollbar.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_scrollbar.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +  XUL Widget Test for scrollbars
     1.9 +  -->
    1.10 +<window title="Scrollbar"
    1.11 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.14 +
    1.15 +  <!-- test results are displayed in the html:body -->
    1.16 +  <body xmlns="http://www.w3.org/1999/xhtml"/>
    1.17 +  
    1.18 +  <hbox>
    1.19 +      <scrollbar orient="horizontal"
    1.20 +                 id="scroller"
    1.21 +                 curpos="0"
    1.22 +                 maxpos="600"
    1.23 +                 pageincrement="400"
    1.24 +                 width="500"
    1.25 +                 style="margin:0"/>
    1.26 +  </hbox>
    1.27 +  
    1.28 +  <!-- test code goes here -->
    1.29 +  <script type="application/javascript"><![CDATA[
    1.30 +
    1.31 +/** Test for Scrollbar **/
    1.32 +var scrollbarTester = {
    1.33 +  scrollbar: null,
    1.34 +  middlePref: false,
    1.35 +  startTest: function() {
    1.36 +    this.scrollbar = $("scroller");
    1.37 +    this.middlePref = this.getMiddlePref();
    1.38 +    var self = this;
    1.39 +    [0, 1, 2].map(function(button) {
    1.40 +      [false, true].map(function(alt) {
    1.41 +        [false, true].map(function(shift) {
    1.42 +          self.testThumbDragging(button, alt, shift);
    1.43 +        })
    1.44 +      })
    1.45 +    });
    1.46 +    SimpleTest.finish();
    1.47 +  },
    1.48 +  testThumbDragging: function(button, withAlt, withShift) {
    1.49 +    this.reset();
    1.50 +    var x = 160; // on the right half of the thumb
    1.51 +    var y = 5;
    1.52 +    
    1.53 +    // Start the drag.
    1.54 +    this.mousedown(x, y, button, withAlt, withShift);
    1.55 +    var newPos = this.getPos();
    1.56 +    var scrollToClick = (newPos != 0);
    1.57 +    if (navigator.platform.indexOf("Mac") != -1) {
    1.58 +      ok(!scrollToClick,
    1.59 +          "On Mac OS X, clicking the scrollbar thumb should never move it.");
    1.60 +    } else if (button == 0 && withShift) {
    1.61 +      ok(scrollToClick, "On platforms other than Mac OS X, holding shift should "+
    1.62 +                        "enable scroll-to-click on the scrollbar thumb.");
    1.63 +    } else if (button == 1 && this.middlePref) {
    1.64 +      ok(scrollToClick, "When middlemouse.scrollbarPosition is on, clicking the "+
    1.65 +                        "thumb with the middle mouse button should center it "+
    1.66 +                        "around the cursor.")
    1.67 +    }
    1.68 +    
    1.69 +    // Move one pixel to the right.
    1.70 +    this.mousemove(x+1, y, button, withAlt, withShift);
    1.71 +    var newPos2 = this.getPos();
    1.72 +    if (newPos2 != newPos) {
    1.73 +      ok(newPos2 > newPos, "Scrollbar thumb should follow the mouse when dragged.");
    1.74 +      ok(newPos2 - newPos < 3, "Scrollbar shouldn't move further than the mouse when dragged.");
    1.75 +      ok(button == 0 || (button == 1 && this.middlePref),
    1.76 +         "Dragging the scrollbar should only be possible with the left mouse button.");
    1.77 +    } else {
    1.78 +      // Dragging had no effect.
    1.79 +      if (button == 0) {
    1.80 +        ok(false, "Dragging the scrollbar thumb should work.");
    1.81 +      } else if (button == 1 && this.middlePref && navigator.platform.indexOf("Mac") == -1) {
    1.82 +        ok(false, "When middlemouse.scrollbarPosition is on, dragging the "+
    1.83 +           "scrollbar thumb should be possible using the middle mouse button.");
    1.84 +      } else {
    1.85 +        ok(true, "Dragging works correctly.");
    1.86 +      }
    1.87 +    }
    1.88 +
    1.89 +    // Release the mouse button.
    1.90 +    this.mouseup(x+1, y, button, withAlt, withShift);
    1.91 +    var newPos3 = this.getPos();
    1.92 +    ok(newPos3 == newPos2,
    1.93 +       "Releasing the mouse button after dragging the thumb shouldn't move it.");
    1.94 +  },
    1.95 +  getMiddlePref: function() {
    1.96 +    // It would be better to test with different middlePref settings,
    1.97 +    // but the setting is only queried once, at browser startup, so
    1.98 +    // changing it here wouldn't have any effect
    1.99 +    var prefService = Components.classes["@mozilla.org/preferences-service;1"]
   1.100 +                                .getService(Components.interfaces.nsIPrefService);
   1.101 +    var mouseBranch = prefService.getBranch("middlemouse.");
   1.102 +    return mouseBranch.getBoolPref("scrollbarPosition");
   1.103 +  },
   1.104 +  setPos: function(pos) {
   1.105 +    this.scrollbar.setAttribute("curpos", pos);
   1.106 +  },
   1.107 +  getPos: function() {
   1.108 +    return this.scrollbar.getAttribute("curpos");
   1.109 +  },
   1.110 +  reset: function() {
   1.111 +    this.setPos(0);
   1.112 +  },
   1.113 +  mousedown: function(x, y, button, alt, shift) {
   1.114 +    synthesizeMouse(this.scrollbar, x, y, { type: "mousedown", 'button': button,
   1.115 +                                                altKey: alt, shiftKey: shift });
   1.116 +  },
   1.117 +  mousemove: function(x, y, button, alt, shift) {
   1.118 +    synthesizeMouse(this.scrollbar, x, y, { type: "mousemove", 'button': button,
   1.119 +                                                altKey: alt, shiftKey: shift });
   1.120 +  },
   1.121 +  mouseup: function(x, y, button, alt, shift) {
   1.122 +    synthesizeMouse(this.scrollbar, x, y, { type: "mouseup", 'button': button,
   1.123 +                                                altKey: alt, shiftKey: shift });
   1.124 +  }
   1.125 +}
   1.126 +
   1.127 +function doTest() {
   1.128 +  setTimeout(function() { scrollbarTester.startTest(); }, 0);
   1.129 +}
   1.130 +
   1.131 +SimpleTest.waitForExplicitFinish();
   1.132 +addLoadEvent(doTest);
   1.133 +
   1.134 +]]></script>
   1.135 +</window>

mercurial