Bug 598962 - Fix panning test in browser_preferences_basic.js [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 04 Oct 2010 09:41:08 -0700
changeset 66774 98eda2ad1aefe0794586013523fff71916d68afb
parent 66773 967d0094cf3715b2e69da55530220b8e4f9ca4a8
child 66775 20b1da828c42fb7ef92927385e3db973347d2559
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs598962
Bug 598962 - Fix panning test in browser_preferences_basic.js [r=mfinkle]
mobile/chrome/tests/browser_bookmarks_tags.js
mobile/chrome/tests/browser_preferences_basic.js
mobile/chrome/tests/browser_preferences_text.js
mobile/chrome/tests/browser_tabs.js
--- a/mobile/chrome/tests/browser_bookmarks_tags.js
+++ b/mobile/chrome/tests/browser_bookmarks_tags.js
@@ -83,17 +83,17 @@ gTests.push({
     let donebutton = document.getAnonymousElementByAttribute(bookmark, "anonid", "done-button");
     donebutton.click();
 
     let tagsarray = PlacesUtils.tagging.getTagsForURI(makeURI(testURL_02), {});
     is(tagsarray.length, 4, "All tags are associated with specified bookmark");
 
     BrowserUI.activePanel = null;
 
-    Browser.closeTab(this._currentTab);
+    Browser.closeTab(gCurrentTest._currentTab);
 
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
 // Case: Test editing tags to bookmark
 gTests.push({
--- a/mobile/chrome/tests/browser_preferences_basic.js
+++ b/mobile/chrome/tests/browser_preferences_basic.js
@@ -129,61 +129,68 @@ gTests.push({
       is(document.getElementById("tool-panel-close").checked, false, "Panel close button must not be pressed");
     }
 
     // Now pan preferences pane up/down, left/right
     // check whether it is in correct position
     gCurrentTest._prefsScrollbox.getPosition(x, y);
     ok((x.value == 0 && y.value == 0),"The preferences pane should be visible", "Got " + x.value + " " + y.value + ", expected 0,0");
 
-    // Move preferences pane up
-    dragElement(prefsList, w / 2, h / 2, w / 2, h / 4);
-
-    // Check whether it is moved up to the correct view
-    let distance = (h / 2) - (h / 4);
-    gCurrentTest._prefsScrollbox.getPosition(x, y);
-    ok((x.value == 0 && y.value == distance), "Preferences pane is panned up", "Got " + x.value + " " + y.value + ", expected 0," + distance);
-
-    // Move preferences pane down
-    dragElement(prefsList, w / 2, h / 4, w / 2, h / 2);
-
-    // Check whether it goes back to old position
-    gCurrentTest._prefsScrollbox.getPosition(x, y);
-    ok((x.value == 0 && y.value == 0), "Preferences pane is panned down", "Got " + x.value + " " + y.value + ", expected 0,0");
-
-    // Force the scroll position to 0, 0 - just in case the previous test fails
-    gCurrentTest._prefsScrollbox.scrollTo(0, 0);
-
-    // Now check whether it is not panned right/left
     // Move the preferences pane right
     dragElement(prefsList, w / 2, h / 2, w / 4, h / 2);
 
     gCurrentTest._prefsScrollbox.getPosition(x, y);
     ok((x.value == 0 && y.value == 0), "Preferences pane is not panned left", "Got " + x.value + " " + y.value + ", expected 0,0");
 
     // Move the preferences pane left
     dragElement(prefsList, w / 4, h / 2, w / 2, h / 2);
 
     gCurrentTest._prefsScrollbox.getPosition(x, y);
     ok((x.value == 0 && y.value ==0 ), "Preferences pane is not panned right", "Got " + x.value + " " + y.value + ", expected 0,0");
 
-    // Close the preferences pane
-    BrowserUI.hidePanel();
-    waitFor(gCurrentTest.finish, function () { return document.getElementById("panel-container").hidden == true; });
+    // Move preferences pane up
+    let [x1, y1, x2, y2] = [w / 2, h / 2, w / 2, h / 4].map(Math.round);
+    EventUtils.synthesizeMouse(prefsList, x1, y1, { type: "mousedown" });
+    EventUtils.synthesizeMouse(prefsList, x2, y2, { type: "mousemove" });
+
+    // Check whether it is moved up to the correct view
+    let distance = y1 - y2;
+    gCurrentTest._prefsScrollbox.getPosition(x, y);
+    ok((x.value == 0 && y.value == distance), "Preferences pane is panned up", "Got " + x.value + " " + y.value + ", expected 0," + distance);
+
+    // Need to wait for a paint event before another 
+    addEventListener("MozBeforePaint", function(aEvent) {
+      removeEventListener("MozBeforePaint", arguments.callee, false);
+
+      // Move preferences pane down
+      EventUtils.synthesizeMouse(prefsList, x1, y1, { type: "mousemove" });
+      EventUtils.synthesizeMouse(prefsList, x1, y1, { type: "mouseup" });
+
+      // Check whether it goes back to old position
+      gCurrentTest._prefsScrollbox.getPosition(x, y);
+      ok((x.value == 0 && y.value == 0), "Preferences pane is panned down", "Got " + x.value + " " + y.value + ", expected 0,0");
+
+      gCurrentTest.finish();
+    }, false);
   },
 
   finish: function() {
+    // Close the preferences pane
+    BrowserUI.hidePanel();
+
     // check whether the preferences pane has disappeared
     is(document.getElementById("panel-container").hidden, true, "Preference pane is now invisible");
 
     //check if the right sidebar is still visible
     gCurrentTest._contentScrollbox.getPosition(x, y);
     todo((x.value == finalDragOffset && y.value == 0), "The right sidebar is still visible",
        "Got " + x.value + " " + y.value + ", expected " + finalDragOffset + ",0");
 
     // check whether the preferences open button is not depressed
     var prefsOpen = document.getElementById("tool-panel-open");
     is(prefsOpen.checked, false, "Preferences open button must not be depressed");
 
-    Browser.closeTab(this._currentTab);
+    // Reset the UI before the next test starts.
+    Browser.hideSidebars();
+    Browser.closeTab(gCurrentTest._currentTab);
     runNextTest();
   }
 });
--- a/mobile/chrome/tests/browser_preferences_text.js
+++ b/mobile/chrome/tests/browser_preferences_text.js
@@ -57,27 +57,26 @@ function runNextTest() {
     finish();
   }
 }
 
 // -----------------------------------------------------------------------------------------
 // Verify preferences and text
 gTests.push({
   desc: "Verify Preferences and Text",
-  _currentTab : null,
 
   run: function(){
     var prefs = getPreferencesElements();
     // 1.Click preferences to view prefs
     prefs.panelOpen.click();
 
     // 2. For each prefs *verify text *the button/option type *verify height of each field to be the same
     is(prefs.panelContainer.hidden, false, "Preferences should be visible");
 
-    // Check whether the Preferences pan title is Preferences
+    // Check whether the Preferences pane title is Preferences
     var prefTitle = document.getElementById("panel-header");
     is(prefTitle.value, "Preferences", "The title must be preferences");
 
     var prefsList = document.getElementById("prefs-messages");
 
     // Check for *About page*
     let about = expected.aboutButton;
     var aboutRegion = document.getAnonymousElementByAttribute(prefsList, "title", "About Fennec");
@@ -173,13 +172,12 @@ gTests.push({
     ok((cookiesRegionHeight == getHeight(passwordsRegion)) && (cookiesRegionHeight == getHeight(clearDataRegion)),
        "The fields of Privacy & Security are of same height");
     ok(aboutRegionHeight == imageRegionHeight, "The fields of Content Region and above are of same height");
     ok(aboutRegionHeight == cookiesRegionHeight, "The fields of Privacy & Security and above are of same height");
     ok(imageRegionHeight == cookiesRegionHeight, "The fields of Content and Privacy & Security are of same height");
 
     prefs.panelClose.click()
     is(document.getElementById("panel-container").hidden, true, "Preferences panel should be closed");
-    Browser.closeTab(gCurrentTest._currentTab);
     runNextTest();
   }
 });
 
--- a/mobile/chrome/tests/browser_tabs.js
+++ b/mobile/chrome/tests/browser_tabs.js
@@ -69,12 +69,16 @@ function tab_switch_03() {
   done();
 }
 
 function done() {
   //Close new tab 
   Browser.closeTab(new_tab_01);
   Browser.closeTab(new_tab_02);
   Browser.closeTab(new_tab_03);
-  
+
+  // For some reason, this test is causing the sidebar to appear.
+  // Clean up the UI for later tests (see bug 598962).
+  Browser.hideSidebars();
+
   // We must finialize the tests
   finish();
 }