2009-09-02 07:22:50 -07:00
|
|
|
/*
|
2010-07-28 13:31:07 -07:00
|
|
|
* Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
|
2009-09-02 07:22:50 -07:00
|
|
|
* code in mobile/chrome/content in terms of integration with Places
|
|
|
|
* component, specifically for bookmark management.
|
|
|
|
*/
|
2010-03-01 13:10:31 -08:00
|
|
|
|
2010-10-01 11:33:00 -07:00
|
|
|
var testURL_01 = chromeRoot + "browser_blank_01.html";
|
|
|
|
var testURL_02 = chromeRoot + "browser_blank_02.html";
|
2009-09-02 07:22:50 -07:00
|
|
|
|
|
|
|
// A queue to order the tests and a handle for each test
|
2009-10-14 15:43:20 -07:00
|
|
|
var gTests = [];
|
|
|
|
var gCurrentTest = null;
|
2009-09-02 07:22:50 -07:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2009-10-14 15:43:20 -07:00
|
|
|
// Entry point (must be named "test")
|
2009-09-02 07:22:50 -07:00
|
|
|
function test() {
|
2009-10-14 15:43:20 -07:00
|
|
|
// The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
|
|
|
|
// We call "finish()" when the tests are finished
|
|
|
|
waitForExplicitFinish();
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
// Start the tests
|
2009-09-02 07:22:50 -07:00
|
|
|
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();
|
2009-10-14 15:43:20 -07:00
|
|
|
info(gCurrentTest.desc);
|
2009-09-02 07:22:50 -07:00
|
|
|
gCurrentTest.run();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Cleanup. All tests are completed at this point
|
2009-10-14 15:43:20 -07:00
|
|
|
try {
|
2010-08-24 01:43:50 -07:00
|
|
|
PlacesUtils.bookmarks.removeFolderChildren(BookmarkList.panel.mobileRoot);
|
2009-10-14 15:43:20 -07:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
// We must finialize the tests
|
|
|
|
finish();
|
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 09:28:27 -08:00
|
|
|
function waitForPageShow(aCallback) {
|
|
|
|
messageManager.addMessageListener("pageshow", function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
setTimeout(aCallback, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitForNavigationPanel(aCallback, aWaitForHide) {
|
|
|
|
let evt = aWaitForHide ? "NavigationPanelHidden" : "NavigationPanelShown";
|
|
|
|
info("waitFor " + evt + "(" + Components.stack.caller + ")");
|
|
|
|
window.addEventListener(evt, function(aEvent) {
|
|
|
|
info("receive " + evt);
|
|
|
|
window.removeEventListener(aEvent.type, arguments.callee, false);
|
|
|
|
setTimeout(aCallback, 0);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test adding a bookmark with the Star button
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test adding a bookmark with the Star button",
|
2010-07-28 13:31:07 -07:00
|
|
|
_currentTab: null,
|
2009-09-02 07:22:50 -07:00
|
|
|
|
|
|
|
run: function() {
|
2010-07-28 13:31:07 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, true);
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
// Need to wait until the page is loaded
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForPageShow(gCurrentTest.onPageReady);
|
2009-09-02 07:22:50 -07:00
|
|
|
},
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
onPageReady: function() {
|
2010-07-28 13:31:07 -07:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2010-07-26 12:45:36 -07:00
|
|
|
starbutton.click();
|
2010-12-30 09:58:31 -08:00
|
|
|
window.addEventListener("BookmarkCreated", function(aEvent) {
|
|
|
|
window.removeEventListener(aEvent.type, arguments.callee, false);
|
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
|
|
|
ok(bookmark != -1, testURL_01 + " should be added.");
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-12-30 09:58:31 -08:00
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-12-30 09:58:31 -08:00
|
|
|
runNextTest();
|
|
|
|
}, false);
|
2010-07-28 13:31:07 -07:00
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test clicking on a bookmark loads the web page
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test clicking on a bookmark loads the web page",
|
2010-08-24 01:33:43 -07:00
|
|
|
_currentTab: null,
|
2009-09-02 07:22:50 -07:00
|
|
|
|
|
|
|
run: function() {
|
2010-11-17 13:29:05 -08:00
|
|
|
BrowserUI.closeAutoComplete(true);
|
2010-09-30 11:07:37 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_02, true);
|
2009-10-14 15:43:20 -07:00
|
|
|
|
|
|
|
// Need to wait until the page is loaded
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForPageShow(gCurrentTest.onPageReady);
|
2009-09-02 07:22:50 -07:00
|
|
|
},
|
2009-10-14 15:43:20 -07:00
|
|
|
|
|
|
|
onPageReady: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
// Wait for the bookmarks to load, then do the test
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
|
2010-08-24 01:43:50 -07:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2009-10-14 15:43:20 -07:00
|
|
|
},
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
onBookmarksReady: function() {
|
2010-09-30 11:07:37 -07:00
|
|
|
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
|
|
|
|
bookmarkitem.control.scrollBoxObject.ensureElementIsVisible(bookmarkitem);
|
|
|
|
|
|
|
|
isnot(bookmarkitem, null, "Found the bookmark");
|
|
|
|
is(bookmarkitem.getAttribute("uri"), testURL_01, "Bookmark has the right URL via attribute");
|
|
|
|
is(bookmarkitem.spec, testURL_01, "Bookmark has the right URL via property");
|
|
|
|
|
2010-07-28 13:31:07 -07:00
|
|
|
// Create a listener for the opening bookmark
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForPageShow(function() {
|
2011-06-11 11:35:56 -07:00
|
|
|
if (Services.appinfo.OS == "Android")
|
|
|
|
todo_is(gCurrentTest._currentTab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");
|
|
|
|
else
|
|
|
|
is(gCurrentTest._currentTab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");
|
|
|
|
|
2010-07-28 13:31:07 -07:00
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-07-28 13:31:07 -07:00
|
|
|
runNextTest();
|
|
|
|
});
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-09-28 14:16:01 -07:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2010-07-28 13:31:07 -07:00
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing URI of existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing URI of existing bookmark",
|
|
|
|
|
|
|
|
run: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
// Wait for the bookmarks to load, then do the test
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
|
2010-08-24 01:43:50 -07:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2010-10-14 06:15:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onBookmarksReady: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
// Go into edit mode
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 13:31:07 -07:00
|
|
|
bookmark.startEditing();
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
|
2009-10-14 15:43:20 -07:00
|
|
|
},
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
onEditorReady: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
|
2010-09-28 14:16:01 -07:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
|
2009-10-14 15:43:20 -07:00
|
|
|
uritextbox.value = testURL_02;
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
|
2009-09-02 07:22:50 -07:00
|
|
|
donebutton.click();
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
2009-10-14 15:43:20 -07:00
|
|
|
is(bookmark, -1, testURL_01 + " should no longer in bookmark");
|
2010-03-01 13:10:31 -08:00
|
|
|
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-10-14 15:43:20 -07:00
|
|
|
isnot(bookmark, -1, testURL_02 + " is in bookmark");
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2011-09-01 10:04:29 -07:00
|
|
|
AwesomeScreen.activePanel = null;
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
runNextTest();
|
2010-07-28 13:31:07 -07:00
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing title of existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing title of existing bookmark",
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
run: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
// Wait for the bookmarks to load, then do the test
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
|
2010-08-24 01:43:50 -07:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2010-10-14 06:15:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onBookmarksReady: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
// Go into edit mode
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 13:31:07 -07:00
|
|
|
bookmark.startEditing();
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
|
2009-10-14 15:43:20 -07:00
|
|
|
},
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
onEditorReady: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-10-14 15:43:20 -07:00
|
|
|
is(PlacesUtils.bookmarks.getItemTitle(bookmark), "Browser Blank Page 01", "Title remains the same.");
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
|
2010-09-28 14:16:01 -07:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
|
|
|
|
let newtitle = "Changed Title";
|
2009-09-02 07:22:50 -07:00
|
|
|
titletextbox.value = newtitle;
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
|
2009-09-02 07:22:50 -07:00
|
|
|
donebutton.click();
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-03-01 13:10:31 -08:00
|
|
|
isnot(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)), -1, testURL_02 + " is still in bookmark.");
|
2009-09-02 07:22:50 -07:00
|
|
|
is(PlacesUtils.bookmarks.getItemTitle(bookmark), newtitle, "Title is changed.");
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2011-09-01 10:04:29 -07:00
|
|
|
AwesomeScreen.activePanel = null;
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
runNextTest();
|
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test removing existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test removing existing bookmark",
|
2009-10-15 21:00:14 -07:00
|
|
|
bookmarkitem: null,
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
run: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
// Wait for the bookmarks to load, then do the test
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
|
2010-08-24 01:43:50 -07:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2010-10-14 06:15:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onBookmarksReady: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
// Go into edit mode
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 13:31:07 -07:00
|
|
|
bookmark.startEditing();
|
2009-10-14 15:43:20 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
|
2009-09-02 07:22:50 -07:00
|
|
|
},
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
onEditorReady: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
|
2010-07-28 13:31:07 -07:00
|
|
|
bookmark.remove();
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-09-02 07:22:50 -07:00
|
|
|
ok(bookmark == -1, testURL_02 + " should no longer in bookmark");
|
2010-03-01 13:10:31 -08:00
|
|
|
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
2009-09-02 07:22:50 -07:00
|
|
|
ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
|
|
|
|
|
2011-09-01 10:04:29 -07:00
|
|
|
AwesomeScreen.activePanel = null;
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
runNextTest();
|
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing title of desktop folder
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing title of desktop folder",
|
|
|
|
bmId: null,
|
2010-07-28 13:31:07 -07:00
|
|
|
|
2010-04-26 22:10:52 -07:00
|
|
|
run: function() {
|
|
|
|
// Add a bookmark to the desktop area so the desktop folder is displayed
|
|
|
|
gCurrentTest.bmId = PlacesUtils.bookmarks
|
|
|
|
.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
|
|
|
|
makeURI(testURL_02),
|
|
|
|
Ci.nsINavBookmarksService.DEFAULT_INDEX,
|
|
|
|
testURL_02);
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
// Wait for the bookmarks to load, then do the test
|
2010-12-07 09:28:27 -08:00
|
|
|
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
|
2010-08-24 01:43:50 -07:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2010-10-14 06:15:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onBookmarksReady: function() {
|
2010-04-26 22:10:52 -07:00
|
|
|
// Go into edit mode
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmarksPanel = BookmarkList.panel;
|
|
|
|
let bookmark = bookmarksPanel.items[0];
|
2010-07-28 13:31:07 -07:00
|
|
|
bookmark.startEditing();
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
// Is the "desktop" folder showing?
|
2010-08-24 01:43:50 -07:00
|
|
|
let first = bookmarksPanel._children.firstChild;
|
|
|
|
is(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is showing");
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
// Is the "desktop" folder in edit mode?
|
|
|
|
is(first.isEditing, false, "Desktop folder is not in edit mode");
|
|
|
|
|
|
|
|
// Do not allow the "desktop" folder to be editable by tap
|
2010-09-28 14:16:01 -07:00
|
|
|
EventUtils.synthesizeMouse(first, first.width / 2, first.height / 2, {});
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
// A tap on the "desktop" folder _should_ open the folder, not put it into edit mode.
|
|
|
|
// So we need to get the first item again.
|
2010-08-24 01:43:50 -07:00
|
|
|
first = bookmarksPanel._children.firstChild;
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
// It should not be the "desktop" folder
|
2010-08-24 01:43:50 -07:00
|
|
|
isnot(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is not showing after mouse click");
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
// But it should be one of the other readonly bookmark roots
|
2010-08-24 01:43:50 -07:00
|
|
|
isnot(bookmarksPanel._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
|
2010-04-26 22:10:52 -07:00
|
|
|
|
|
|
|
PlacesUtils.bookmarks.removeItem(gCurrentTest.bmId);
|
|
|
|
|
2011-09-01 10:04:29 -07:00
|
|
|
AwesomeScreen.activePanel = null;
|
2010-04-26 22:10:52 -07:00
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
});
|