Bug 644641: Fix perma-oranges browser-chrome tests on desktop [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Fri, 25 Mar 2011 00:35:21 +0100
changeset 67535 bcaa623a76961dd178763dd276bd0bfd0072543b
parent 67534 3333554d36df9d5e19a39147e63e3cc67b25ea9d
child 67536 0a6bc90779a8f75e7ec1fae9cc42732f9d487b12
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
bugs644641
Bug 644641: Fix perma-oranges browser-chrome tests on desktop [r=mfinkle]
mobile/chrome/content/bindings.xml
mobile/chrome/content/content.js
mobile/chrome/tests/browser_awesomescreen.js
mobile/chrome/tests/browser_bookmarks_star.js
mobile/chrome/tests/browser_navigation.js
mobile/chrome/tests/browser_tapping.js
--- a/mobile/chrome/content/bindings.xml
+++ b/mobile/chrome/content/bindings.xml
@@ -777,27 +777,27 @@
                     tagsToAdd.push(tags[i]);
                 }
 
                 if (tagsToAdd.length > 0)
                   PlacesUtils.tagging.tagURI(this.uri, tagsToAdd);
                 if (tagsToRemove.length > 0)
                   PlacesUtils.tagging.untagURI(this.uri, tagsToRemove);
               }
-              this.setAttribute('tags', this.tags);
+              this.setAttribute("tags", this.tags);
 
               // If the URI was updated change it in the bookmark, but don't
               // allow a blank URI. Revert to previous URI if blank.
               let spec = this.spec;
               if (spec && this.uri.spec != spec) {
                 try {
                   let oldURI = this._uri;
                   this._uri = Services.io.newURI(spec, null, null);
                   PlacesUtils.bookmarks.changeBookmarkURI(this.itemId, this.uri);
-                  this.setAttribute('uri', this.spec);
+                  this.setAttribute("uri", this.spec);
 
                   // move tags from old URI to new URI
                   let tags = this.tagsAsArray;
                   if (tags.length != 0) {
                     // only untag the old URI if this is the only bookmark
                     if (PlacesUtils.getBookmarksForURI(oldURI, {}).length == 0)
                       PlacesUtils.tagging.untagURI(oldURI, tags);
 
@@ -807,17 +807,17 @@
                 catch (e) { }
               }
               if (spec != this.uri.spec)
                 this.spec = this.uri.spec;
             }
 
             // Update the name and use the URI if name is blank
             this.name = this.name || this.spec;
-            this.setAttribute('title', this.name);
+            this.setAttribute("title", this.name);
             PlacesUtils.bookmarks.setItemTitle(this.itemId, this.name);
           ]]>
         </body>
       </method>
       <method name="remove">
         <body>
           <![CDATA[
             PlacesUtils.bookmarks.removeItem(this.itemId);
@@ -998,19 +998,20 @@
       <field name="_children">
         document.getAnonymousElementByAttribute(this, "anonid", "child-items");
       </field>
 
       <field name="scrollBoxObject">this._children.scrollBoxObject</field>
 
       <property name="items" readonly="true" onget="return this._children.childNodes"/>
 
-      <field name="mobileRoot"><![CDATA[
-        PlacesUtils.annotations.getItemsWithAnnotation("mobile/bookmarksRoot", {})[0];
-      ]]></field>
+      <!-- mobileRoot is a property otherwise if it is accessed before Places
+           is ready the value will be bitrotted
+      -->
+      <property name="mobileRoot" onget="return PlacesUtils.annotations.getItemsWithAnnotation('mobile/bookmarksRoot', {})[0];"/>
 
       <property name="isRootFolder" readonly="true">
         <getter>
           <![CDATA[
             let currentFolderId = this._parents.lastChild.itemId;
             return currentFolderId == this.mobileRoot;
           ]]>
         </getter>
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -926,20 +926,16 @@ var ContextHandler = {
   /** Remove all handlers registered for a given type. */
   unregisterType: function unregisterType(aName) {
     this._types = this._types.filter(function(type) type.name != aName);
   }
 };
 
 ContextHandler.init();
 
-ContextHandler.registerType("link", function(aState, aElement) {
-  return !!aState.linkURL;
-});
-
 ContextHandler.registerType("mailto", function(aState, aElement) {
   return aState.linkProtocol == "mailto";
 });
 
 ContextHandler.registerType("callto", function(aState, aElement) {
   let protocol = aState.linkProtocol;
   return protocol == "tel" || protocol == "callto" || protocol == "sip" || protocol == "voipto";
 });
--- a/mobile/chrome/tests/browser_awesomescreen.js
+++ b/mobile/chrome/tests/browser_awesomescreen.js
@@ -279,17 +279,20 @@ gTests.push({
       ok(edit.selectionStart == 0 && edit.selectionEnd == edit.textLength, "urlbar text should be selected on a double click");
     });
 
     edit.clickSelectsAll = oldClickSelectsAll;
 
     BrowserUI.closeTab(this._currentTab);
 
     BrowserUI.activePanel = null;
-    runNextTest();
+
+    // Ensure the tab is well closed before doing the rest of the code, otherwise
+    // this cause some bugs with the composition events
+    waitFor(runNextTest, function() { return Browser.tabs.length == 1 });
   }
 });
 
 // Case: Test context clicks on awesome panel
 gTests.push({
   desc: "Test context clicks on awesome panel",
 
   _panelIndex : 0,
@@ -416,15 +419,14 @@ gTests.push({
       return gCurrentTest.popupHeader.hidden;
     }
 
     // Wait to be sure there the header won't dissapear
     // XXX this sucks because it means we'll be stuck 500ms if the test succeed
     // but I don't have a better idea about how to do it for now since we don't
     // that to happen!
     waitForAndContinue(function() {
-      todo(false, "Unexpected fail!!");
-      //gCurrentTest._checkState();
+      gCurrentTest._checkState();
       runNextTest();
     }, isHiddenHeader, Date.now() + 500);
   }
 });
 
--- a/mobile/chrome/tests/browser_bookmarks_star.js
+++ b/mobile/chrome/tests/browser_bookmarks_star.js
@@ -1,20 +1,20 @@
 /*
  * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome 
  *              code in mobile/chrome/content in terms of integration with Places
  *              component, specifically for bookmark management.
  */
 
-var testURL_01 = chromeRoot + "browser_blank_01.html";
-var testURL_02 = chromeRoot + "browser_blank_02.html";
+let testURL_01 = chromeRoot + "browser_blank_01.html";
+let testURL_02 = chromeRoot + "browser_blank_02.html";
 
 // A queue to order the tests and a handle for each test
-var gTests = [];
-var gCurrentTest = null;
+let gTests = [];
+let gCurrentTest = null;
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
   // We call "finish()" when the tests are finished
   waitForExplicitFinish();
 
@@ -51,71 +51,67 @@ gTests.push({
 
   run: function() {
     this._currentTab = Browser.addTab(testURL_02, true);
 
     messageManager.addMessageListener("pageshow",
     function(aMessage) {
       if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
         messageManager.removeMessageListener(aMessage.name, arguments.callee);
-        gCurrentTest.onPageLoad();
+
+        // Wait a bit until Places is initialized
+        waitFor(gCurrentTest.onPageLoad, function() {
+          let mobileRoot = PlacesUtils.annotations.getItemsWithAnnotation("mobile/bookmarksRoot", {})[0];
+          return mobileRoot;
+        });
       }
     });
   },
 
   onPageLoad: function() {
     let starbutton = document.getElementById("tool-star");
     starbutton.click();
 
-    waitFor(gCurrentTest.onPopupReady1, function() { return document.getElementById("bookmark-popup").hidden == false; });
+    waitFor(gCurrentTest.onPopupReady, function() { return BookmarkPopup.box.hidden == false; });
   },
 
-  onPopupReady1: function() {
-    // Popup should no longer auto-hide, see bug 63204
-    setTimeout(gCurrentTest.onPopupGone, 3000);
+  onPopupReady: function() {
+    // Let's make it disappear again by clicking the star again
+    let starbutton = document.getElementById("tool-star");
+    starbutton.click();
+
+    waitFor(gCurrentTest.onPopupGone, function() { return BookmarkPopup.box.hidden == true; });
   },
 
   onPopupGone: function() {
-    is(document.getElementById("bookmark-popup").hidden, false, "Bookmark popup should not be auto-hidden");
-    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");
+    is(BookmarkPopup.box.hidden, true, "Bookmark popup should be hidden by clicking star");
 
     // Let's make it appear again and continue the test
     let starbutton = document.getElementById("tool-star");
     starbutton.click();
 
-    waitFor(gCurrentTest.onPopupReady3, function() { return document.getElementById("bookmark-popup").hidden == false; });
+    waitFor(gCurrentTest.onPopupReady2, function() { return BookmarkPopup.box.hidden == false; });
   },
 
-  onPopupReady3: function() {
+  onPopupReady2: function() {
     // Let's make it disappear again by clicking somewhere
     let contentarea = document.getElementById("browsers");
     EventUtils.synthesizeMouse(contentarea, contentarea.clientWidth / 2, contentarea.clientHeight / 2, {});
 
-    waitFor(gCurrentTest.onPopupGone3, function() { return document.getElementById("bookmark-popup").hidden == true; });
+    waitFor(gCurrentTest.onPopupGone2, function() { return BookmarkPopup.box.hidden == true; });
   },
 
-  onPopupGone3: function() {
+  onPopupGone2: function() {
     // Make sure it's hidden again
-    is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be hidden by clicking in content");
-    
+    is(BookmarkPopup.box.hidden, true, "Bookmark popup should be hidden by clicking in content");
+
+    BookmarkHelper.removeBookmarksForURI(getBrowser().currentURI);
     BrowserUI.closeTab(this._currentTab);
-    
+
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
 // Case: Test adding tags via star icon
 gTests.push({
   desc: "Test adding tags via star icon",
@@ -129,45 +125,50 @@ gTests.push({
       if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
         messageManager.removeMessageListener(aMessage.name, arguments.callee);
         gCurrentTest.onPageLoad();
       }
     });
   },
 
   onPageLoad: function() {
-    var starbutton = document.getElementById("tool-star");
+    let starbutton = document.getElementById("tool-star");
     starbutton.click();
 
-    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+    waitFor(gCurrentTest.onPopupReady, function() { return BookmarkPopup.box.hidden == false });
   },
 
   onPopupReady: function() {
-    var editbutton = document.getElementById("bookmark-popup-edit");
+    let editbutton = document.getElementById("bookmark-popup-edit");
     editbutton.click();
 
-    waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
+    waitFor(gCurrentTest.onEditorReady, function() {
+      let item = document.getElementById("bookmark-item");
+      return item && item.isEditing == true;
+    });
   },
 
   onEditorReady: function() {
-    var bookmarkitem = document.getElementById("bookmark-item");
+    let bookmarkitem = document.getElementById("bookmark-item");
     bookmarkitem.tags = "tagone, tag two, tag-three, tag4";
 
-    var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
+    let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
     donebutton.click();
 
     waitFor(gCurrentTest.onEditorDone, function() { return document.getElementById("bookmark-container").hidden == true; });
   },
 
   onEditorDone: function() {
-    var tagsarray = PlacesUtils.tagging.getTagsForURI(makeURI(testURL_02), {});
+    let uri = makeURI(testURL_02);
+    let tagsarray = PlacesUtils.tagging.getTagsForURI(uri, {});
     is(tagsarray.length, 4, "All tags are added.");
-    
+
+    BookmarkHelper.removeBookmarksForURI(uri);
     BrowserUI.closeTab(this._currentTab);
-    
+
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
 // Case: Test editing uri via star icon
 gTests.push({
   desc: "Test editing uri via star icon",
@@ -184,42 +185,49 @@ gTests.push({
       }
     });
   },
 
   onPageLoad: function() {
     let starbutton = document.getElementById("tool-star");
     starbutton.click();
 
-    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+    waitFor(gCurrentTest.onPopupReady, function() {
+      return BookmarkPopup.box.hidden == false &&
+             PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)) != -1;
+    });
   },
 
   onPopupReady: function() {
     let editbutton = document.getElementById("bookmark-popup-edit");
     editbutton.click();
-    
-    waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
+
+    waitFor(gCurrentTest.onEditorReady, function() {
+      let item = document.getElementById("bookmark-item");
+      return item && item.isEditing == true;
+    });
   },
 
   onEditorReady: function() {
-    let bookmarkitem = document.getElementById("bookmark-item");    
+    let bookmarkitem = document.getElementById("bookmark-item");
     bookmarkitem.spec = testURL_01;
 
     let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
     donebutton.click();
-    
+
     waitFor(gCurrentTest.onEditorDone, function() { return document.getElementById("bookmark-container").hidden == true; });
   },
 
   onEditorDone: function() {
     isnot(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01)), -1, testURL_01 + " is now bookmarked");
     is(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)), -1, testURL_02 + " is no longer bookmarked");
-    
+
+    BookmarkHelper.removeBookmarksForURI(makeURI(testURL_02));
     BrowserUI.closeTab(this._currentTab);
-    
+
     runNextTest();
   }
 });
 
 //------------------------------------------------------------------------------
 // Case: Test removing existing bookmark via popup
 gTests.push({
   desc: "Test removing existing bookmark via popup",
@@ -232,26 +240,29 @@ gTests.push({
       if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
         messageManager.removeMessageListener(aMessage.name, arguments.callee);
         gCurrentTest.onPageLoad();
       }
     });
   },
 
   onPageLoad: function() {
-    var starbutton = document.getElementById("tool-star");
+    let starbutton = document.getElementById("tool-star");
     starbutton.click();
 
-    waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
+    waitFor(gCurrentTest.onPopupReady, function() {
+      return BookmarkPopup.box.hidden == false &&
+             PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01)) != -1;
+    });
   },
 
   onPopupReady: function() {
-    var removebutton = document.getElementById("bookmark-popup-remove");
+    let removebutton = document.getElementById("bookmark-popup-remove");
     removebutton.click();
-    
-    var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
+
+    let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
     ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
 
     BrowserUI.closeTab(this._currentTab);
 
     runNextTest();
   }
 });
--- a/mobile/chrome/tests/browser_navigation.js
+++ b/mobile/chrome/tests/browser_navigation.js
@@ -127,18 +127,20 @@ gTests.push({
     function URLIsReadWrite() {
       return BrowserUI._edit.readOnly == false;
     }
 
     waitFor(function() {
       // Wait for the tab to load, then do the test
       waitFor(gCurrentTest.onPageFinish, pageLoaded(testURL_02));
 
-      is(BrowserUI._edit.value, testURL_02, "URL value should be equal to the string sent via synthesizeString");
-      EventUtils.synthesizeKey("VK_RETURN", {}, window);
+      setTimeout(function() {
+        is(BrowserUI._edit.value, testURL_02, "URL value should be equal to the string sent via synthesizeString");
+        EventUtils.synthesizeKey("VK_RETURN", {}, window);
+      }, 0);
     }, URLIsReadWrite);
   },
 
   onPageFinish: function() {
     let urlIcons = document.getElementById("urlbar-icons");
     is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
 
     // Check button states (url edit is not focused)
--- a/mobile/chrome/tests/browser_tapping.js
+++ b/mobile/chrome/tests/browser_tapping.js
@@ -242,17 +242,17 @@ gTests.push({
     info("Test a good long pan");
     clearEvents();
     EventUtils.synthesizeMouse(inputHandler, width / 2, height / 2, { type: "mousedown" });
   },
 
   contextPlainLinkTest: function() {
     waitForContextMenu(function(aJSON) {
       is(aJSON.linkTitle, "A blank page - nothing interesting", "Text content should be the content of the second link");
-      ok(checkContextTypes(["link","link-saveable","link-openable"]), "Plain link context types");
+      ok(checkContextTypes(["link", "link-saveable","link-openable"]), "Plain link context types");
     }, gCurrentTest.contextPlainImageTest);
 
     let browser = gCurrentTab.browser;
     let linkDisabled = browser.contentDocument.getElementById("link-disabled");
     let event = content.document.createEvent("PopupEvents");
     event.initEvent("contextmenu", true, true);
     linkDisabled.dispatchEvent(event);
 
@@ -271,17 +271,17 @@ gTests.push({
     let img = browser.contentDocument.getElementById("img-single");
     let event = content.document.createEvent("PopupEvents");
     event.initEvent("contextmenu", true, true);
     img.dispatchEvent(event);
   },
 
   contextNestedImageTest: function() {
     waitForContextMenu(function() {
-      ok(checkContextTypes(["link","link-saveable","image","image-shareable","image-loaded","link-openable"]), "Nested image context types");
+      ok(checkContextTypes(["link", "link-saveable","image","image-shareable","image-loaded","link-openable"]), "Nested image context types");
     }, runNextTest);
 
     let browser = gCurrentTab.browser;
     let img = browser.contentDocument.getElementById("img-nested");
     let event = content.document.createEvent("PopupEvents");
     event.initEvent("contextmenu", true, true);
     img.dispatchEvent(event);
   }