Bug 295977 - browser-chrome tests + non-multiple select fixup; r=neil@parkwaycc.co.uk
authorArpad Borsos <arpad.borsos@googlemail.com>
Sat, 22 Aug 2009 11:12:31 +0200
changeset 33915 c19711e6eef2965966942611f55b2faa37a7a651
parent 33914 c045d251e69fc55cb4dae38742ce4c9197a6fe34
child 33916 d6a03e3e6e6f8e14263b378a6da916e889c0c07c
push idunknown
push userunknown
push dateunknown
reviewersneil
bugs295977
milestone1.9.3a1pre
Bug 295977 - browser-chrome tests + non-multiple select fixup; r=neil@parkwaycc.co.uk
toolkit/content/tests/browser/Makefile.in
toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js
toolkit/content/widgets/browser.xml
--- a/toolkit/content/tests/browser/Makefile.in
+++ b/toolkit/content/tests/browser/Makefile.in
@@ -45,15 +45,16 @@ include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   common \
   data \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
-_BROWSER_FILES = \
+_BROWSER_TEST_FILES = \
   browser_bug471962.js \
   browser_keyevents_during_autoscrolling.js \
+  browser_bug295977_autoscroll_overflow.js \
   $(NULL)
 
-libs:: $(_BROWSER_FILES)
+libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js
@@ -0,0 +1,88 @@
+function test()
+{
+  const kPrefName_AutoScroll = "general.autoScroll";
+  var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
+                          .getService(Components.interfaces.nsIPrefBranch2);
+  prefSvc.setBoolPref(kPrefName_AutoScroll, true);
+
+  const expectScrollNone = 0;
+  const expectScrollVert = 1;
+  const expectScrollHori = 2;
+  const expectScrollBoth = 3;
+
+  var allTests = [
+    {elem: 'a', expected: expectScrollNone},
+    {elem: 'b', expected: expectScrollBoth},
+    {elem: 'c', expected: expectScrollHori},
+    {elem: 'd', expected: expectScrollVert},
+    {elem: 'e', expected: expectScrollVert},
+    {elem: 'f', expected: expectScrollNone}
+  ];
+
+  var doc;
+
+  function nextTest() {
+    var test = allTests.shift();
+    if(!test) {
+      endTest();
+      return;
+    }
+    var elem = doc.getElementById(test.elem);
+    EventUtils.synthesizeMouse(elem, 10, 10, { button: 1 },
+                               gBrowser.contentWindow);
+    EventUtils.synthesizeMouse(elem, 80, 80,
+                               { type: "mousemove", clickCount: "0" },
+                               gBrowser.contentWindow);
+    // the autoscroll implementation uses a 20ms interval
+    // wait for 40ms to make sure it did autoscroll at least once
+    setTimeout(function () {
+      EventUtils.synthesizeKey("VK_ESCAPE", {}, gBrowser.contentWindow);
+      var scrollVert = test.expected & expectScrollVert;
+      ok((scrollVert && elem.scrollTop > 0) ||
+         (!scrollVert && elem.scrollTop == 0),
+         test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically');
+      var scrollHori = test.expected & expectScrollHori;
+      ok((scrollHori && elem.scrollLeft > 0) ||
+         (!scrollHori && elem.scrollLeft == 0),
+         test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally');
+      nextTest();
+    }, 40);
+  }
+
+  waitForExplicitFinish();
+  gBrowser.addEventListener("load", onLoad, false);
+  var dataUri = 'data:text/html,<body>\
+    <div id="a" style="width: 100px; height: 100px; overflow: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
+    <div id="b" style="width: 100px; height: 100px; overflow: auto;"><div style="width: 200px; height: 200px;"></div></div>\
+    <div id="c" style="width: 100px; height: 100px; overflow-x: auto; overflow-y: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
+    <div id="d" style="width: 100px; height: 100px; overflow-y: auto; overflow-x: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
+    <select id="e" style="width: 100px; height: 100px;" multiple="multiple"><option>aaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option><option>a</option>\
+    <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\
+    <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\
+    <select id="f" style="width: 100px; height: 100px;"><option>a</option><option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option>\
+    <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\
+    <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\
+    </body>';
+  gBrowser.loadURI(dataUri);
+
+  function onLoad() {
+    gBrowser.removeEventListener("load", onLoad, false);
+    waitForFocus(onFocus, content);
+  }
+
+  function onFocus() {
+    doc = gBrowser.contentDocument;
+    nextTest();
+  }
+
+  function endTest() {
+    // restore the changed prefs
+    prefSvc.clearUserPref(kPrefName_AutoScroll);
+
+    // cleaning-up
+    gBrowser.addTab().linkedBrowser.stop();
+    gBrowser.removeCurrentTab();
+
+    finish();
+  }
+}
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -806,18 +806,20 @@
             }
 
             // go upward in the DOM and find any parent element that has a overflow
             // area and can therefore be scrolled
             for (this._scrollable = event.originalTarget; this._scrollable;
                  this._scrollable = this._scrollable.parentNode) {
               // do not use overflow based autoscroll for <html> Elements
               // or non-html elements such as svg or Document nodes
+              // also make sure to skip select elements that are not multiline
               if (!(this._scrollable instanceof HTMLElement) ||
-                  (this._scrollable instanceof HTMLHtmlElement)) {
+                  (this._scrollable instanceof HTMLHtmlElement) ||
+                  ((this._scrollable instanceof HTMLSelectElement) && !this._scrollable.multiple)) {
                 continue;
               }
 
               var overflowx = this._scrollable.ownerDocument.defaultView
                                   .getComputedStyle(this._scrollable, '')
                                   .getPropertyValue('overflow-x');
               var overflowy = this._scrollable.ownerDocument.defaultView
                                   .getComputedStyle(this._scrollable, '')