Bug 864757 - Metro test fixes r=jmathies
authorRodrigo Silveira <rsilveira@mozilla.com>
Mon, 29 Apr 2013 20:42:44 -0700
changeset 130659 5f90a20c173e465944a36865f38b73f0e6fcd667
parent 130658 db0abc62a0fd1c46a22f6b5e06416f82eaf89999
child 130660 fdc122c78f1d682aad9bb4def03a62d1b7c12ea5
push id1579
push userphilringnalda@gmail.com
push dateSat, 04 May 2013 04:38:04 +0000
treeherderfx-team@a56432a42a41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmathies
bugs864757
milestone23.0a1
Bug 864757 - Metro test fixes r=jmathies
browser/metro/base/tests/mochitest/browser_context_menu_tests.js
browser/metro/base/tests/mochitest/browser_context_ui.js
browser/metro/base/tests/mochitest/browser_history.js
browser/metro/base/tests/mochitest/head.js
browser/metro/base/tests/mochitest/res/textblock01.html
--- a/browser/metro/base/tests/mochitest/browser_context_menu_tests.js
+++ b/browser/metro/base/tests/mochitest/browser_context_menu_tests.js
@@ -292,17 +292,17 @@ gTests.push({
     yield promise;
 
     // should *not* be visible
     ok(!ContextMenuUI._menuPopup._visible, "is visible");
 
     // the test above will invoke the app bar
     yield hideContextUI();
 
-    Browser.closeTab(Browser.selectedTab);
+    Browser.closeTab(Browser.selectedTab, { forceClose: true });
     purgeEventQueue();
   }
 });
 
 gTests.push({
   desc: "checks for context menu positioning when browser shifts",
   run: function test() {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@@ -340,17 +340,17 @@ gTests.push({
     let notificationHeight = notification.boxObject.height;
 
     checkContextMenuPositionRange(ContextMenuUI._panel, 65, 80, notificationHeight +  155, notificationHeight + 180);
 
     promise = waitForEvent(document, "popuphidden");
     ContextMenuUI.hide();
     yield promise;
 
-    Browser.closeTab(Browser.selectedTab);
+    Browser.closeTab(Browser.selectedTab, { forceClose: true });
   }
 });
 
 // Image context menu tests
 gTests.push({
   desc: "image context menu",
   run: function test() {
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@@ -487,18 +487,17 @@ gTests.push({
     yield popupPromise;
     let event = yield tabPromise;
 
     purgeEventQueue();
 
     let imagetab = Browser.getTabFromChrome(event.originalTarget);
     ok(imagetab != null, "tab created");
 
-    Browser.closeTab(imagetab);
-    yield waitForEvent(imagetab.chromeTab.parentNode, "TabRemove");
+    Browser.closeTab(imagetab, { forceClose: true });
   }
 });
 
 gTests.push({
   desc: "tests for subframe positioning",
   run: function test() {
     info(chromeRoot + "browser_context_menu_tests_03.html");
     yield addTab(chromeRoot + "browser_context_menu_tests_03.html");
--- a/browser/metro/base/tests/mochitest/browser_context_ui.js
+++ b/browser/metro/base/tests/mochitest/browser_context_ui.js
@@ -77,17 +77,17 @@ gTests.push({
     is(ContextUI.isExpanded, false, "Tab bar is not visible");
 
     let edit = document.getElementById("urlbar-edit");
     is(edit.value, "about:", "Location field contains the page URL");
     ok(document.commandDispatcher.focusedElement, edit.inputField, "Location field is focused");
     is(edit.selectionStart, 0, "Location field is selected");
     is(edit.selectionEnd, edit.value.length, "Location field is selected");
 
-    Browser.closeTab(tab);
+    Browser.closeTab(tab, { forceClose: true });
   }
 });
 
 function doEdgeUIGesture() {
   let event = document.createEvent("Events");
   event.initEvent("MozEdgeUIGesture", true, false);
   window.dispatchEvent(event);
 }
--- a/browser/metro/base/tests/mochitest/browser_history.js
+++ b/browser/metro/base/tests/mochitest/browser_history.js
@@ -230,16 +230,18 @@ gTests.push({
     // --------- delete item 2 for realz
 
     let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
 
     let promise = waitForEvent(Elements.appbar, "transitionend", null, Elements.appbar);
     sendContextMenuClickToElement(window, item, 10, 10);
     yield promise;
 
+    yield waitForCondition(() => !deleteButton.hidden);
+
     ok(!deleteButton.hidden, "Delete button is visible.");
 
     let promise = waitForCondition(() => !restoreButton.hidden);
     EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
     yield promise;
 
     item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
 
@@ -312,16 +314,18 @@ gTests.push({
     let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
 
     let promise = waitForEvent(Elements.appbar, "transitionend", null, Elements.appbar);
     sendContextMenuClickToElement(window, item1, 10, 10);
     sendContextMenuClickToElement(window, item2, 10, 10);
     sendContextMenuClickToElement(window, item3, 10, 10);
     yield promise;
 
+    yield waitForCondition(() => !deleteButton.hidden);
+
     ok(!deleteButton.hidden, "Delete button is visible.");
 
     let promise = waitForCondition(() => !restoreButton.hidden);
     EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
     yield promise;
 
     item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
     item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
--- a/browser/metro/base/tests/mochitest/head.js
+++ b/browser/metro/base/tests/mochitest/head.js
@@ -152,20 +152,20 @@ function clearSelection(aTarget) {
 /*=============================================================================
   Asynchronous Metro ui helpers
 =============================================================================*/
 
 function hideContextUI()
 {
   purgeEventQueue();
   if (ContextUI.isVisible) {
-    info("is visible, waiting...");
     let promise = waitForEvent(Elements.tray, "transitionend", null, Elements.tray);
     if (ContextUI.dismiss())
     {
+      info("ContextUI dismissed, waiting...");
       return promise;
     }
     return true;
   }
 }
 
 function showNavBar()
 {
@@ -184,16 +184,18 @@ function fireAppBarDisplayEvent()
   gWindow.dispatchEvent(event);
   purgeEventQueue();
   return promise;
 }
 
 /*=============================================================================
   Asynchronous test helpers
 =============================================================================*/
+let gOpenedTabs = [];
+
 /**
  *  Loads a URL in a new tab asynchronously.
  *
  * Usage:
  *    Task.spawn(function() {
  *      let tab = yield addTab("http://example.com/");
  *      ok(Browser.selectedTab == tab, "the new tab is selected");
  *    });
@@ -203,22 +205,37 @@ function fireAppBarDisplayEvent()
  */
 function addTab(aUrl) {
   return Task.spawn(function() {
     info("Opening "+aUrl+" in a new tab");
     let tab = Browser.addTab(aUrl, true);
     yield tab.pageShowPromise;
 
     is(tab.browser.currentURI.spec, aUrl, aUrl + " is loaded");
-    registerCleanupFunction(function() Browser.closeTab(tab));
+
+    yield hideContextUI();
+
+    gOpenedTabs.push(tab);
+
     throw new Task.Result(tab);
   });
 }
 
 /**
+ * Cleans up tabs left open by addTab().
+ * This is being called at runTests() after the test loop.
+ */
+function cleanUpOpenedTabs() {
+  let tab;
+  while(tab = gOpenedTabs.shift()) {
+    Browser.closeTab(Browser.getTabFromChrome(tab.chromeTab), { forceClose: true })
+  }
+}
+
+/**
  * Waits a specified number of miliseconds for a specified event to be
  * fired on a specified element.
  *
  * Usage:
  *    let receivedEvent = waitForEvent(element, "eventName");
  *    // Do some processing here that will cause the event to be fired
  *    // ...
  *    // Now yield until the Promise is fulfilled
@@ -645,16 +662,17 @@ function purgeEventQueue() {
 /*=============================================================================
   Test-running helpers
 =============================================================================*/
 let gCurrentTest = null;
 let gTests = [];
 
 function runTests() {
   waitForExplicitFinish();
+
   Task.spawn(function() {
     while((gCurrentTest = gTests.shift())){
       try {
         if ('function' == typeof gCurrentTest.setUp) {
           info("SETUP " + gCurrentTest.desc);
           yield Task.spawn(gCurrentTest.setUp.bind(gCurrentTest));
         }
         try {
@@ -667,16 +685,36 @@ function runTests() {
           }
         }
       } catch (ex) {
         ok(false, "runTests: Task failed - " + ex + ' at ' + ex.stack);
       } finally {
         info("END " + gCurrentTest.desc);
       }
     }
+
+    try {
+      cleanUpOpenedTabs();
+
+      let badTabs = [];
+      Browser.tabs.forEach(function(item, index, array) {
+        let location = item.browser.currentURI.spec;
+        if (index == 0 && location == "about:blank")
+          return;
+        ok(false, "Left over tab after test: '" + location + "'");
+        badTabs.push(item);
+      });
+
+      badTabs.forEach(function(item, index, array) {
+        Browser.closeTab(item, { forceClose: true });
+      });
+    } catch (ex) {
+      ok(false, "Cleanup tabs failed - " + ex);
+    }
+
     finish();
   });
 }
 
 function stubMethod(aObj, aMethod) {
   let origFunc = aObj[aMethod];
   let func = function() {
     func.calledWith = Array.slice(arguments);
--- a/browser/metro/base/tests/mochitest/res/textblock01.html
+++ b/browser/metro/base/tests/mochitest/res/textblock01.html
@@ -1,15 +1,15 @@
 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8" />
 </head>
 <body>
-<div id="content">
+<div id="content" style="font-size: 105%">
     <p>(start of paragraph)
     Alice was beginning to get very (break)<br>
     tired of sitting by her sister on the bank, and of having nothing to do: once or twice she (span)
     <span>(start of span) had peeped into the book her sister was reading (end of span)</span>,
     but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice
     `without pictures or conversation?' (break)<br> 
     (end of paragraph)</p>
     (in between paragraphs)