Bug 489158 - --browser-chrome Mochitests on Fennec [preferences] [r=jmaher r=mfinkle]
authorAditya Rao <adicoolrao@gmail.com>
Fri, 11 Jun 2010 15:17:14 -0400
changeset 66278 c01409ba1b05ddae803ec2e25ab9310c98b24c5f
parent 66277 45f957ce844c048cbc1570abec65e8c385d0246b
child 66279 3c139d1d5c90d9b34c309c9a51accd8d175a951e
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)
reviewersjmaher, mfinkle
bugs489158
Bug 489158 - --browser-chrome Mochitests on Fennec [preferences] [r=jmaher r=mfinkle]
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_preferences_basic.js
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -52,16 +52,17 @@ include $(topsrcdir)/config/rules.mk
   browser_bookmarks_star.js \
   browser_bookmarks_tags.js \
   browser_select.js \
   browser_rect.js \
   browser_click_content.js \
   browser_FormAssistant.js \
   browser_viewport.js \
   browser_navigation.js \
+  browser_preferences_basic.js \
   browser_blank_01.html \
   browser_blank_02.html \
   browser_select.html \
   browser_click_content.html \
   browser_FormAssistant.html \
   browser_viewport_00.html \
   browser_viewport_01.html \
   browser_viewport_02.html \
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_preferences_basic.js
@@ -0,0 +1,182 @@
+// Bug 489158 - --browser-chrome Mochitests on Fennec [preferences]
+
+
+var gTests = [];
+var gCurrentTest = null;
+var initialDragOffset = null;
+var finalDragOffset = null;
+let x = {};
+let y = {};
+
+
+function dragElement(element,x1,y1,x2,y2)
+{
+  EventUtils.synthesizeMouse(element, x1, y1, { type: "mousedown" });
+  EventUtils.synthesizeMouse(element, x2, y2, { type: "mousemove" });
+  EventUtils.synthesizeMouse(element, x2, y2, { type: "mouseup" });
+}
+
+function doubleClick(element,x,y)
+{
+  EventUtils.synthesizeMouse(element, x, y, {});
+  EventUtils.synthesizeMouse(element, x, y, {});
+}
+
+function test() {
+  // The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
+  // We call "finish()" when the tests are finished
+  waitForExplicitFinish();
+  
+  // Start the tests
+  runNextTest();
+}
+//------------------------------------------------------------------------------
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+  // Run the next test until all tests completed
+  if (gTests.length > 0) {
+    gCurrentTest = gTests.shift();
+    info(gCurrentTest.desc);
+    gCurrentTest.run();
+  }
+  else {
+    // Cleanup. All tests are completed at this point
+    finish();
+  }
+}
+// ------------------Verifying panning of preferences list----------------------
+gTests.push({
+  desc: "Test basic panning of Preferences",
+  _currenttab : null,
+  _contentScrollbox : document.getElementById("controls-scrollbox")
+    .boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject),
+  _prefsScrollbox : document.getAnonymousElementByAttribute(document.getElementById("prefs-list"),
+    "anonid", "main-box").boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject),
+
+  run: function(){
+    this._currenttab = Browser.addTab("about:blank",true);
+    function handleEvent() {
+      gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
+      gCurrentTest.onPageLoad();
+    };
+    this._currenttab.browser.addEventListener("load", handleEvent , true);
+  },
+ 
+  onPageLoad: function(){
+    // check whether the right sidebar is invisible
+    let controls = document.getElementById("controls-scrollbox");
+
+    // Assign offsets while panning
+		initialDragOffset = document.getElementById("tabs-container").getBoundingClientRect().width;
+		finalDragOffset = initialDragOffset + document.getElementById("browser-controls")
+      .getBoundingClientRect().width;
+
+    gCurrentTest._contentScrollbox.getPosition(x,y);
+    ok((x.value==initialDragOffset & y.value==0),"The right sidebar must be invisible",
+      "Got "+x.value+" "+y.value+", expected " + initialDragOffset + ",0");
+
+    // Reveal right sidebar
+    let w = controls.clientWidth;
+    let h = controls.clientHeight;
+    dragElement(controls,w/2, h/2, w/4, h/2);
+
+    // check whether the right sidebar has appeared
+    gCurrentTest._contentScrollbox.getPosition(x,y);
+    ok((x.value==finalDragOffset & y.value==0),"The right sidebar must be visible",
+      "Got "+x.value+" "+y.value+", expected "+ finalDragOffset +",0");
+  
+    // check to see if the preference open button is visible and not depressed
+    var prefsOpen = document.getElementById("tool-panel-open");
+    is(prefsOpen.hidden, false, "Preferences open button must be visible");
+    is(prefsOpen.checked, false, "Preferences open button must not be depressed");
+
+    // check if preferences pane is invisble 
+    is(document.getElementById("panel-container").hidden,true, "Preferences panel is invisble");
+
+    // click on the prefs button to go the preferences pane
+    var prefsClick = document.getElementById("tool-panel-open");
+    prefsClick.click();
+    waitFor(gCurrentTest.onPrefsView, function() { return document.getElementById("panel-container").hidden == false; });
+  },
+
+  onPrefsView: function(){
+    let prefsList = document.getElementById("prefs-list");
+    let w = prefsList.clientWidth;
+    let h = prefsList.clientHeight;
+
+    //check whether the preferences panel is visible
+    var prefsContainer = document.getElementById("panel-container");
+    is(prefsContainer.hidden, false, "Preferences panel must now be visble");
+
+    // Check if preferences container is visible
+    is(document.getElementById("panel-container").hidden, false, "Preferences panel should be visible");
+
+    // check if side buttons are visible 6.Verify preference button is depressed and others are not
+    is(document.getElementById("tool-addons").hidden, false, "Addons button must be visible");
+    is(document.getElementById("tool-addons").checked, false, "Addons button must not be pressed");
+
+    is(document.getElementById("tool-downloads").hidden, false, "Downloads button must be visible");
+    is(document.getElementById("tool-downloads").checked, false, "Downloads button must not be pressed");
+
+    is(document.getElementById("tool-preferences").hidden, false, "Preferences button must be visible");
+    is(document.getElementById("tool-preferences").checked, true, "Preferences button must be pressed");
+
+    // Verify back button is exists, is visible and is depressed
+    is(document.getElementById("tool-panel-close").hidden, false, "Panel close button must be visible");
+    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 visble","Got "+x.value+" "+y.value+", expected 0,0");
+
+    // Move preferences pane upexpected "+ finalDragOffset +"
+    dragElement(prefsList,w/2,h/2,w/2,h/4);
+
+    // Check whether it is moved up to the correct view, height should be 104
+    gCurrentTest._prefsScrollbox.getPosition(x,y);
+    ok((x.value==0 & y.value==104),"Preferences pane is panned up","Got "+x.value+" "+y.value+", expected 0,104");
+
+    // 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");
+
+    // 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
+    var prefClose = document.getElementById("tool-panel-close");
+    prefClose.click();
+    waitFor(gCurrentTest.finish, function () { return document.getElementById("panel-container").hidden == true; });
+  },
+
+  finish: function(){
+    // 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);
+    ok((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);
+    runNextTest();    
+  }
+});