Bug 820743 - test-only change to (hopefully!) fix intermittent chat resize orange. r=me
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 28 Mar 2013 16:01:02 +1100
changeset 126524 7fdeab2a549dafa1373d3e76b9167c63f97178df
parent 126523 023023d36160f20851d7e55ff2ceef340132ddac
child 126525 cf276949f2b65be190249b943557efa629e11c53
push id24485
push userryanvm@gmail.com
push dateThu, 28 Mar 2013 12:31:20 +0000
treeherdermozilla-central@293498096b28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs820743
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 820743 - test-only change to (hopefully!) fix intermittent chat resize orange. r=me
browser/base/content/test/social/browser_social_chatwindow.js
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -8,24 +8,27 @@ function test() {
 
   let manifest = { // normal provider
     name: "provider 1",
     origin: "https://example.com",
     sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
     workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
     iconURL: "https://example.com/browser/browser/base/content/test/moz.png"
   };
-  let oldwidth = window.outerWidth; // we futz with this, so we restore it
+  let oldwidth = window.outerWidth; // we futz with these, so we restore them
+  let oldleft = window.screenX;
+  window.moveTo(0, window.screenY)
   let postSubTest = function(cb) {
     let chats = document.getElementById("pinnedchats");
     ok(chats.children.length == 0, "no chatty children left behind");
     cb();
   };
   runSocialTestWithProvider(manifest, function (finishcb) {
     runSocialTests(tests, undefined, postSubTest, function() {
+      window.moveTo(oldleft, window.screenY)
       window.resizeTo(oldwidth, window.outerHeight);
       finishcb();
     });
   });
 }
 
 var tests = {
   testOpenCloseChat: function(next) {
@@ -331,31 +334,33 @@ var tests = {
     port.postMessage({topic: "test-init"});
     get3ChatsForCollapsing(mode || "normal", function(first, second, third) {
       let chatWidth = chats.getTotalChildWidth(first);
       ok(chatWidth, "have a chatwidth");
       let popupWidth = getPopupWidth();
       ok(popupWidth, "have a popupwidth");
       info("starting resize tests - each chat's width is " + chatWidth +
            " and the popup width is " + popupWidth);
+      // Note that due to a difference between "device", "app" and "css" pixels
+      // we allow use 2 pixels as the minimum size difference.
       resizeAndCheckWidths(first, second, third, [
-        [chatWidth-1, false, false, true, "to < 1 chat width - only last should be visible."],
-        [chatWidth+1, false, false, true, "one pixel more then one fully exposed (not counting popup) - still only 1."],
-        [chatWidth+popupWidth+1, false, false, true, "one pixel more than one fully exposed (including popup) - still only 1."],
-        [chatWidth*2-1, false, false, true, "second not showing by 1 pixel (not counting popup) - only 1 exposed."],
-        [chatWidth*2+popupWidth-1, false, false, true, "second not showing by 1 pixel (including popup) - only 1 exposed."],
-        [chatWidth*2+popupWidth+1, false, true, true, "big enough to fit 2 - nub remains visible as first is still hidden"],
-        [chatWidth*3+popupWidth-1, false, true, true, "one smaller than the size necessary to display all three - first still hidden"],
-        [chatWidth*3+popupWidth+1, true, true, true, "big enough to fit all - all exposed (which removes the nub)"],
-        [chatWidth*3, true, true, true, "now the nub is hidden we can resize back down to chatWidth*3 before overflow."],
-        [chatWidth*3-1, false, true, true, "one pixel less and the first is again collapsed (and the nub re-appears)"],
-        [chatWidth*2+popupWidth+1, false, true, true, "back down to just big enough to fit 2"],
-        [chatWidth*2+popupWidth-1, false, false, true, "back down to just not enough to fit 2"],
-        [chatWidth*3+popupWidth+1, true, true, true, "now a large jump to make all 3 visible (ie, affects 2)"],
-        [chatWidth*1.5, false, false, true, "and a large jump back down to 1 visible (ie, affects 2)"],
+        [chatWidth-2, 1, "to < 1 chat width - only last should be visible."],
+        [chatWidth+2, 1, "2 pixels more then one fully exposed (not counting popup) - still only 1."],
+        [chatWidth+popupWidth+2, 1, "2 pixels more than one fully exposed (including popup) - still only 1."],
+        [chatWidth*2-2, 1, "second not showing by 2 pixels (not counting popup) - only 1 exposed."],
+        [chatWidth*2+popupWidth-2, 1, "second not showing by 2 pixelx (including popup) - only 1 exposed."],
+        [chatWidth*2+popupWidth+2, 2, "big enough to fit 2 - nub remains visible as first is still hidden"],
+        [chatWidth*3+popupWidth-2, 2, "one smaller than the size necessary to display all three - first still hidden"],
+        [chatWidth*3+popupWidth+2, 3, "big enough to fit all - all exposed (which removes the nub)"],
+        [chatWidth*3+2, 3, "now the nub is hidden we can resize back down to chatWidth*3 before overflow."],
+        [chatWidth*3-2, 2, "2 pixels less and the first is again collapsed (and the nub re-appears)"],
+        [chatWidth*2+popupWidth+2, 2, "back down to just big enough to fit 2"],
+        [chatWidth*2+popupWidth-2, 1, "back down to just not enough to fit 2"],
+        [chatWidth*3+popupWidth+2, 3, "now a large jump to make all 3 visible (ie, affects 2)"],
+        [chatWidth*1.5, 1, "and a large jump back down to 1 visible (ie, affects 2)"],
       ], function() {
         closeAllChats();
         port.close();
         next();
       });
     });
   },
 
@@ -631,20 +636,20 @@ function checkPopup() {
 // if we couldn't resize large enough to satisfy the test requirement.
 function resizeWindowToChatAreaWidth(desired, cb) {
   let current = window.SocialChatBar.chatbar.getBoundingClientRect().width;
   let delta = desired - current;
   info("resizing window so chat area is " + desired + " wide, currently it is "
        + current + ".  Screen avail is " + window.screen.availWidth
        + ", current outer width is " + window.outerWidth);
 
-  // WTF?  Some test boxes will resize to fractional values - eg: we
-  // request 660px but actually get 659.5!?
+  // WTF?  Sometimes we will get fractional values due to the - err - magic
+  // of DevPointsPerCSSPixel etc, so we allow a couple of pixels difference.
   let widthDeltaCloseEnough = function(d) {
-    return Math.abs(d) <= 0.5;
+    return Math.abs(d) < 2;
   }
 
   // attempting to resize by (0,0), unsurprisingly, doesn't cause a resize
   // event - so just callback saying all is well.
   if (widthDeltaCloseEnough(delta)) {
     cb(true);
     return;
   }
@@ -671,25 +676,24 @@ function resizeWindowToChatAreaWidth(des
   window.resizeBy(delta, 0);
 }
 
 function resizeAndCheckWidths(first, second, third, checks, cb) {
   if (checks.length == 0) {
     cb(); // nothing more to check!
     return;
   }
-  let [width, firstVisible, secondVisible, thirdVisible, why] = checks.shift();
+  let [width, numExpectedVisible, why] = checks.shift();
   info("Check: " + why);
-  info("resizing window to " + width + ", expect visibility of " + firstVisible + "/" + secondVisible + "/" + thirdVisible);  
+  info("resizing window to " + width + ", expect " + numExpectedVisible + " visible items");
   resizeWindowToChatAreaWidth(width, function(sizedOk) {
     checkPopup();
     if (sizedOk) {
-      is(!first.collapsed, firstVisible, "first should be " + (firstVisible ? "visible" : "hidden"));
-      is(!second.collapsed, secondVisible, "second should be " + (secondVisible ? "visible" : "hidden"));
-      is(!third.collapsed, thirdVisible, "third should be " + (thirdVisible ? "visible" : "hidden"));
+      let numVisible = [first, second, third].filter(function(item) !item.collapsed).length;
+      is(numVisible, numExpectedVisible, "correct number of chats visible");
     }
     resizeAndCheckWidths(first, second, third, checks, cb);
   });
 }
 
 function getPopupWidth() {
   let popup = window.SocialChatBar.chatbar.menupopup;
   ok(!popup.parentNode.collapsed, "asking for popup width when it is visible");