From f79b939fecf3487dd5467a2cb8261cbda5fe11b1 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Fri, 16 Oct 2009 00:00:14 -0400 Subject: [PATCH] Bug 522271: --browser-chrome Mochitests on Fennec (bookmark popup) [r=gavin.sharp] --- mobile/chrome/tests/browser_bookmarks.js | 13 ++- mobile/chrome/tests/browser_bookmarks_star.js | 97 ++++++++++++++++++- mobile/chrome/tests/browser_bookmarks_tags.js | 2 +- mobile/chrome/tests/browser_mainui.js | 20 ++-- 4 files changed, 112 insertions(+), 20 deletions(-) diff --git a/mobile/chrome/tests/browser_bookmarks.js b/mobile/chrome/tests/browser_bookmarks.js index 6622e596fc64..b48e7cc6781d 100644 --- a/mobile/chrome/tests/browser_bookmarks.js +++ b/mobile/chrome/tests/browser_bookmarks.js @@ -105,7 +105,7 @@ gTests.push({ 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); @@ -203,6 +203,7 @@ gTests.push({ // Case: Test removing existing bookmark gTests.push({ desc: "Test removing existing bookmark", + bookmarkitem: null, run: function() { // Open the bookmark list @@ -216,10 +217,14 @@ gTests.push({ 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)); diff --git a/mobile/chrome/tests/browser_bookmarks_star.js b/mobile/chrome/tests/browser_bookmarks_star.js index 86dccc727edb..5aece1dfe98a 100644 --- a/mobile/chrome/tests/browser_bookmarks_star.js +++ b/mobile/chrome/tests/browser_bookmarks_star.js @@ -45,14 +45,14 @@ function runNextTest() { } //------------------------------------------------------------------------------ -// 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(); }; @@ -63,6 +63,85 @@ gTests.push({ 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(); @@ -97,7 +176,7 @@ gTests.push({ run: function() { this._currenttab = Browser.addTab(testURL_02, true); - var handleEvent = function() { + function handleEvent() { gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true); gCurrentTest.onPageLoad(); }; @@ -108,6 +187,10 @@ gTests.push({ 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(); @@ -145,7 +228,7 @@ gTests.push({ run: function() { this._currenttab = Browser.addTab(testURL_01, true); - var handleEvent = function() { + function handleEvent() { gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true); gCurrentTest.onPageLoad(); }; @@ -156,6 +239,10 @@ gTests.push({ 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(); diff --git a/mobile/chrome/tests/browser_bookmarks_tags.js b/mobile/chrome/tests/browser_bookmarks_tags.js index b9e458f09b15..9bc39c030f2a 100644 --- a/mobile/chrome/tests/browser_bookmarks_tags.js +++ b/mobile/chrome/tests/browser_bookmarks_tags.js @@ -52,7 +52,7 @@ gTests.push({ run: function() { this._currenttab = Browser.addTab(testURL_02, true); - var handleEvent = function() { + function handleEvent() { gCurrentTest._currenttab.browser.removeEventListener("load", handleEvent, true); gCurrentTest.onPageLoad(); }; diff --git a/mobile/chrome/tests/browser_mainui.js b/mobile/chrome/tests/browser_mainui.js index 79d34b22cd92..cd03026895a5 100644 --- a/mobile/chrome/tests/browser_mainui.js +++ b/mobile/chrome/tests/browser_mainui.js @@ -6,16 +6,16 @@ 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() {