Bug 522271: --browser-chrome Mochitests on Fennec (bookmark popup) [r=gavin.sharp]
authorMark Finkle <mfinkle@mozilla.com>
Fri, 16 Oct 2009 00:00:14 -0400
changeset 65679 dd0dec5e133c0dba8490fab6e98282000e32766d
parent 65678 23b33cd36561a2d45733a772049cad893d6fcc95
child 65680 22014317e8974ad138a3d67b82eea535ef218b89
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)
reviewersgavin
bugs522271
Bug 522271: --browser-chrome Mochitests on Fennec (bookmark popup) [r=gavin.sharp]
mobile/chrome/tests/browser_bookmarks.js
mobile/chrome/tests/browser_bookmarks_star.js
mobile/chrome/tests/browser_bookmarks_tags.js
mobile/chrome/tests/browser_mainui.js
--- a/mobile/chrome/tests/browser_bookmarks.js
+++ b/mobile/chrome/tests/browser_bookmarks.js
@@ -100,17 +100,17 @@ gTests.push({
     waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmarklist-container").hidden == false; });
   },
   
   onBookmarksReady: function() {
     // Create a listener for the opening bookmark  
     gCurrentTest._currenttab.browser.addEventListener("pageshow", 
       function() {
         gCurrentTest._currenttab.browser.removeEventListener("pageshow", arguments.callee, true);
-        todo(gCurrentTest._currenttab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");      
+        todo_is(gCurrentTest._currenttab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");      
 
         Browser.closeTab(gCurrentTest._currenttab);
 
         runNextTest();
       }, 
       true);
 
     var bookmarkitems = document.getElementById("bookmark-items");    
@@ -198,33 +198,38 @@ gTests.push({
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
 // Case: Test removing existing bookmark
 gTests.push({
   desc: "Test removing existing bookmark",
+  bookmarkitem: null,
   
   run: function() {
     // Open the bookmark list
     BookmarkList.show();
 
     // Go into edit mode
     BookmarkList.toggleManage();
 
     waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
   },
   
   onBookmarksReady: function() {
     var bookmarkitems = document.getElementById("bookmark-items");
-    var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
-    EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
+    gCurrentTest.bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
+    EventUtils.synthesizeMouse(gCurrentTest.bookmarkitem, gCurrentTest.bookmarkitem.clientWidth / 2, gCurrentTest.bookmarkitem.clientHeight / 2, {});
 
-    var removebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "close-button");
+    waitFor(gCurrentTest.onEditorReady, function() { return gCurrentTest.bookmarkitem.isEditing == true; });
+  },
+  
+  onEditorReady: function() {
+    var removebutton = document.getAnonymousElementByAttribute(gCurrentTest.bookmarkitem, "anonid", "remove-button");
     removebutton.click();
     
     var bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_02));
     ok(bookmark == -1, testURL_02 + " should no longer in bookmark");
     bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01));
     ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
 
     BookmarkList.close();
--- a/mobile/chrome/tests/browser_bookmarks_star.js
+++ b/mobile/chrome/tests/browser_bookmarks_star.js
@@ -40,34 +40,113 @@ function runNextTest() {
     finally {
       // We must finialize the tests
       finish();
     }
   }
 }
 
 //------------------------------------------------------------------------------
-// Case: Test adding tags via star icon
+// Case: Test appearance and behavior of the bookmark popup
 gTests.push({
-  desc: "Test adding tags via star icon",
+  desc: "Test appearance and behavior of the bookmark popup",
   _currenttab: null,
   
   run: function() {
     this._currenttab = Browser.addTab(testURL_02, true);
-    var handleEvent = function() {
+    function handleEvent() {
       gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
       gCurrentTest.onPageLoad();
     };
     this._currenttab.browser.addEventListener("load", handleEvent , true);
   },
   
   onPageLoad: function() {
     var starbutton = document.getElementById("tool-star");
     starbutton.click();
     
+    waitFor(gCurrentTest.onPopupReady1, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+  
+  onPopupReady1: function() {
+    // Popup should auto-hide after 2 seconds on the initial bookmark with star
+    setTimeout(gCurrentTest.onPopupGone, 3000);
+  },
+  
+  onPopupGone: function() {
+    // Make sure it's hidden again
+    is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be auto-hidden");
+    
+    // Let's make it appear again and continue the test
+    var starbutton = document.getElementById("tool-star");
+    starbutton.click();
+    
+    waitFor(gCurrentTest.onPopupReady2, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+  
+  onPopupReady2: function() {
+    // Let's make it disappear again by clicking the star again
+    var starbutton = document.getElementById("tool-star");
+    starbutton.click();
+    
+    waitFor(gCurrentTest.onPopupGone2, function() { return document.getElementById("bookmark-popup").hidden == true; });
+  },
+  
+  onPopupGone2: function() {
+    // Make sure it's hidden again
+    is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be hidden by clicking star");
+    
+    // Let's make it appear again and continue the test
+    var starbutton = document.getElementById("tool-star");
+    starbutton.click();
+    
+    waitFor(gCurrentTest.onPopupReady3, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+
+  onPopupReady3: function() {
+    // Let's make it disappear again by clicking somewhere
+    var contentarea = document.getElementById("tile-container");
+    EventUtils.synthesizeMouse(contentarea, contentarea.clientWidth / 2, contentarea.clientHeight / 2, {});
+    
+    waitFor(gCurrentTest.onPopupGone3, function() { return document.getElementById("bookmark-popup").hidden == true; });
+  },
+  
+  onPopupGone3: function() {
+    // Make sure it's hidden again
+    is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be hidden by clicking in content");
+    
+    BrowserUI.closeTab(this._currenttab);
+    
+    runNextTest();
+  }  
+});
+
+//------------------------------------------------------------------------------
+// Case: Test adding tags via star icon
+gTests.push({
+  desc: "Test adding tags via star icon",
+  _currenttab: null,
+  
+  run: function() {
+    this._currenttab = Browser.addTab(testURL_02, true);
+    function handleEvent() {
+      gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
+      gCurrentTest.onPageLoad();
+    };
+    this._currenttab.browser.addEventListener("load", handleEvent , true);
+  },
+  
+  onPageLoad: function() {
+    var starbutton = document.getElementById("tool-star");
+    starbutton.click();
+
+    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+  
+  onPopupReady: function() {
     var editbutton = document.getElementById("bookmark-popup-edit");
     editbutton.click();
     
     waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
   },
   
   onEditorReady: function() {
     var bookmarkitem = document.getElementById("bookmark-item");
@@ -92,27 +171,31 @@ gTests.push({
 //------------------------------------------------------------------------------
 // Case: Test editing uri via star icon
 gTests.push({
   desc: "Test editing uri via star icon",
   _currenttab: null,
   
   run: function() {
     this._currenttab = Browser.addTab(testURL_02, true);
-    var handleEvent = function() {
+    function handleEvent() {
       gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
       gCurrentTest.onPageLoad();
     };
     this._currenttab.browser.addEventListener("load", handleEvent, true);
   },
   
   onPageLoad: function() {
     var starbutton = document.getElementById("tool-star");
     starbutton.click();    
     
+    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+  
+  onPopupReady: function() {
     var editbutton = document.getElementById("bookmark-popup-edit");
     editbutton.click();
     
     waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
   },
   
   onEditorReady: function() {
     var bookmarkitem = document.getElementById("bookmark-item");    
@@ -140,27 +223,31 @@ gTests.push({
 //------------------------------------------------------------------------------
 // Case: Test removing existing bookmark via popup
 gTests.push({
   desc: "Test removing existing bookmark via popup",
   _currenttab: null,
   
   run: function() {
     this._currenttab = Browser.addTab(testURL_01, true);
-    var handleEvent = function() {
+    function handleEvent() {
       gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
       gCurrentTest.onPageLoad();
     };
     this._currenttab.browser.addEventListener("load", handleEvent, true);
   },
   
   onPageLoad: function() {
     var starbutton = document.getElementById("tool-star");
     starbutton.click();    
     
+    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+  },
+  
+  onPopupReady: function() {
     var removebutton = document.getElementById("bookmark-popup-remove");
     removebutton.click();
     
     var bookmark = PlacesUtils.getMostRecentBookmarkForURI(uri(testURL_01));
     ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
 
     BrowserUI.closeTab(this._currenttab);
 
--- a/mobile/chrome/tests/browser_bookmarks_tags.js
+++ b/mobile/chrome/tests/browser_bookmarks_tags.js
@@ -47,17 +47,17 @@ function runNextTest() {
 //------------------------------------------------------------------------------
 // Case: Test adding tags to bookmark
 gTests.push({
   desc: "Test adding tags to a bookmark",
   _currenttab: null,
   
   run: function() {
     this._currenttab = Browser.addTab(testURL_02, true);
-    var handleEvent = function() {
+    function handleEvent() {
       gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true);
       gCurrentTest.onPageLoad();
     };
     this._currenttab.browser.addEventListener("load", handleEvent , true);
   },
   
   onPageLoad: function() {
     var starbutton = document.getElementById("tool-star");
--- a/mobile/chrome/tests/browser_mainui.js
+++ b/mobile/chrome/tests/browser_mainui.js
@@ -1,26 +1,26 @@
 // Very basic tests for the main window UI
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
- is(window.location.href, "chrome://browser/content/browser.xul", "Main window should be browser.xul");
-
- window.focus();
-
- let browser = Browser.selectedBrowser;
- isnot(browser, null, "Should have a browser");
-   
- is(browser.currentURI.spec, Browser.selectedTab.browser.currentURI.spec, "selectedBrowser == selectedTab.browser");
-
- testContentContainerSize();
+  is(window.location.href, "chrome://browser/content/browser.xul", "Main window should be browser.xul");
+  
+  window.focus();
+  
+  let browser = Browser.selectedBrowser;
+  isnot(browser, null, "Should have a browser");
+  
+  is(browser.currentURI.spec, Browser.selectedTab.browser.currentURI.spec, "selectedBrowser == selectedTab.browser");
+  
+  testContentContainerSize();
 }
 
 function testContentContainerSize() {
   let tiles = document.getElementById("tile-container");
   let oldtilesstyle = tiles.getAttribute("style");
 
   try {
     tiles.style.width = (window.innerWidth + 100) + "px";