2009-09-02 14:22:50 +00:00
|
|
|
/*
|
2010-07-28 20:31:07 +00:00
|
|
|
* Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
|
2009-09-02 14:22:50 +00:00
|
|
|
* code in mobile/chrome/content in terms of integration with Places
|
|
|
|
* component, specifically for bookmark management.
|
|
|
|
*/
|
2010-03-01 21:10:31 +00:00
|
|
|
|
2010-10-01 18:33:00 +00:00
|
|
|
var testURL_01 = chromeRoot + "browser_blank_01.html";
|
|
|
|
var testURL_02 = chromeRoot + "browser_blank_02.html";
|
2009-09-02 14:22:50 +00:00
|
|
|
|
|
|
|
// A queue to order the tests and a handle for each test
|
2009-10-14 22:43:20 +00:00
|
|
|
var gTests = [];
|
|
|
|
var gCurrentTest = null;
|
2009-09-02 14:22:50 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2009-10-14 22:43:20 +00:00
|
|
|
// Entry point (must be named "test")
|
2009-09-02 14:22:50 +00:00
|
|
|
function test() {
|
2009-10-14 22:43:20 +00:00
|
|
|
// The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
|
|
|
|
// We call "finish()" when the tests are finished
|
|
|
|
waitForExplicitFinish();
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
// Start the tests
|
2009-09-02 14:22:50 +00: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 22:43:20 +00:00
|
|
|
info(gCurrentTest.desc);
|
2009-09-02 14:22:50 +00:00
|
|
|
gCurrentTest.run();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Cleanup. All tests are completed at this point
|
2009-10-14 22:43:20 +00:00
|
|
|
try {
|
2010-08-24 08:43:50 +00:00
|
|
|
PlacesUtils.bookmarks.removeFolderChildren(BookmarkList.panel.mobileRoot);
|
2009-10-14 22:43:20 +00:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
// We must finialize the tests
|
|
|
|
finish();
|
|
|
|
}
|
2009-09-02 14:22:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test adding a bookmark with the Star button
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test adding a bookmark with the Star button",
|
2010-07-28 20:31:07 +00:00
|
|
|
_currentTab: null,
|
2009-09-02 14:22:50 +00:00
|
|
|
|
|
|
|
run: function() {
|
2010-07-28 20:31:07 +00:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, true);
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2009-09-02 14:22:50 +00:00
|
|
|
// Need to wait until the page is loaded
|
2010-07-26 19:45:36 +00:00
|
|
|
messageManager.addMessageListener("pageshow",
|
2010-07-28 20:31:07 +00:00
|
|
|
function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
2010-07-26 19:45:36 +00:00
|
|
|
gCurrentTest.onPageReady();
|
|
|
|
}
|
|
|
|
});
|
2009-09-02 14:22:50 +00:00
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onPageReady: function() {
|
2010-07-28 20:31:07 +00:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2010-07-26 19:45:36 +00:00
|
|
|
starbutton.click();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
|
|
|
ok(bookmark != -1, testURL_01 + " should be added.");
|
|
|
|
|
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
runNextTest();
|
2010-07-28 20:31:07 +00:00
|
|
|
}
|
2009-09-02 14:22:50 +00: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 08:33:43 +00:00
|
|
|
_currentTab: null,
|
2009-09-02 14:22:50 +00:00
|
|
|
|
|
|
|
run: function() {
|
2010-09-30 18:07:37 +00:00
|
|
|
this._currentTab = Browser.addTab(testURL_02, true);
|
2009-10-14 22:43:20 +00:00
|
|
|
|
|
|
|
// Need to wait until the page is loaded
|
2010-07-28 20:31:07 +00:00
|
|
|
messageManager.addMessageListener("pageshow", function(aMessage) {
|
2010-08-24 08:33:43 +00:00
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
gCurrentTest.onPageReady();
|
|
|
|
}
|
2010-07-26 19:45:36 +00:00
|
|
|
});
|
2009-09-02 14:22:50 +00:00
|
|
|
},
|
2009-10-14 22:43:20 +00:00
|
|
|
|
|
|
|
onPageReady: function() {
|
|
|
|
// Open the bookmark list
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
waitFor(gCurrentTest.onBookmarksReady, function() { return BrowserUI.activePanel == BookmarkList });
|
2009-10-14 22:43:20 +00:00
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onBookmarksReady: function() {
|
2010-09-30 18:07:37 +00: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 20:31:07 +00:00
|
|
|
// Create a listener for the opening bookmark
|
|
|
|
messageManager.addMessageListener("pageshow", function(aMessage) {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
is(gCurrentTest._currentTab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
runNextTest();
|
|
|
|
});
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-09-28 21:16:01 +00:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2010-07-28 20:31:07 +00:00
|
|
|
}
|
2009-09-02 14:22:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing URI of existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing URI of existing bookmark",
|
|
|
|
|
|
|
|
run: function() {
|
2009-10-14 22:43:20 +00:00
|
|
|
// Open the bookmark list
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2009-09-02 14:22:50 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
// Go into edit mode
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 20:31:07 +00:00
|
|
|
bookmark.startEditing();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
waitFor(gCurrentTest.onBookmarksReady, function() { return bookmark.isEditing == true; });
|
2009-10-14 22:43:20 +00:00
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onBookmarksReady: function() {
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
|
2010-09-28 21:16:01 +00:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
|
2009-10-14 22:43:20 +00:00
|
|
|
uritextbox.value = testURL_02;
|
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
|
2009-09-02 14:22:50 +00:00
|
|
|
donebutton.click();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
2009-10-14 22:43:20 +00:00
|
|
|
is(bookmark, -1, testURL_01 + " should no longer in bookmark");
|
2010-03-01 21:10:31 +00:00
|
|
|
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-10-14 22:43:20 +00:00
|
|
|
isnot(bookmark, -1, testURL_02 + " is in bookmark");
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.activePanel = null;
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
runNextTest();
|
2010-07-28 20:31:07 +00:00
|
|
|
}
|
2009-09-02 14:22:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing title of existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing title of existing bookmark",
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-09-02 14:22:50 +00:00
|
|
|
run: function() {
|
2009-10-14 22:43:20 +00:00
|
|
|
// Open the bookmark list
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2009-10-14 22:43:20 +00:00
|
|
|
|
|
|
|
// Go into edit mode
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 20:31:07 +00:00
|
|
|
bookmark.startEditing();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
waitFor(gCurrentTest.onBookmarksReady, function() { return bookmark.isEditing == true; });
|
2009-10-14 22:43:20 +00:00
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onBookmarksReady: function() {
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-10-14 22:43:20 +00:00
|
|
|
is(PlacesUtils.bookmarks.getItemTitle(bookmark), "Browser Blank Page 01", "Title remains the same.");
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
|
2010-09-28 21:16:01 +00:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
|
|
|
|
let newtitle = "Changed Title";
|
2009-09-02 14:22:50 +00:00
|
|
|
titletextbox.value = newtitle;
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
|
2009-09-02 14:22:50 +00:00
|
|
|
donebutton.click();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-03-01 21:10:31 +00:00
|
|
|
isnot(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)), -1, testURL_02 + " is still in bookmark.");
|
2009-09-02 14:22:50 +00:00
|
|
|
is(PlacesUtils.bookmarks.getItemTitle(bookmark), newtitle, "Title is changed.");
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.activePanel = null;
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
runNextTest();
|
|
|
|
}
|
2009-09-02 14:22:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test removing existing bookmark
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test removing existing bookmark",
|
2009-10-16 04:00:14 +00:00
|
|
|
bookmarkitem: null,
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-09-02 14:22:50 +00:00
|
|
|
run: function() {
|
2009-10-14 22:43:20 +00:00
|
|
|
// Open the bookmark list
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2009-10-14 22:43:20 +00:00
|
|
|
|
|
|
|
// Go into edit mode
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = BookmarkList.panel.items[0];
|
2010-07-28 20:31:07 +00:00
|
|
|
bookmark.startEditing();
|
2009-10-14 22:43:20 +00:00
|
|
|
|
2010-07-28 20:31:07 +00:00
|
|
|
waitFor(gCurrentTest.onBookmarksReady, function() { return bookmark.isEditing == true; });
|
2009-09-02 14:22:50 +00:00
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onBookmarksReady: function() {
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
|
2010-07-28 20:31:07 +00:00
|
|
|
bookmark.remove();
|
2009-09-02 14:22:50 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
2009-09-02 14:22:50 +00:00
|
|
|
ok(bookmark == -1, testURL_02 + " should no longer in bookmark");
|
2010-03-01 21:10:31 +00:00
|
|
|
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
2009-09-02 14:22:50 +00:00
|
|
|
ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
|
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.activePanel = null;
|
2009-09-02 14:22:50 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
runNextTest();
|
|
|
|
}
|
2009-09-02 14:22:50 +00:00
|
|
|
});
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing title of desktop folder
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing title of desktop folder",
|
|
|
|
bmId: null,
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-04-27 05:10:52 +00: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);
|
|
|
|
|
|
|
|
// Open the bookmark list
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.doCommand("cmd_bookmarks");
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
// Go into edit mode
|
2010-08-24 08:43:50 +00:00
|
|
|
let bookmarksPanel = BookmarkList.panel;
|
|
|
|
let bookmark = bookmarksPanel.items[0];
|
2010-07-28 20:31:07 +00:00
|
|
|
bookmark.startEditing();
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
// Is the "desktop" folder showing?
|
2010-08-24 08:43:50 +00:00
|
|
|
let first = bookmarksPanel._children.firstChild;
|
|
|
|
is(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is showing");
|
2010-04-27 05:10:52 +00: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 21:16:01 +00:00
|
|
|
EventUtils.synthesizeMouse(first, first.width / 2, first.height / 2, {});
|
2010-04-27 05:10:52 +00: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 08:43:50 +00:00
|
|
|
first = bookmarksPanel._children.firstChild;
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
// It should not be the "desktop" folder
|
2010-08-24 08:43:50 +00:00
|
|
|
isnot(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is not showing after mouse click");
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
// But it should be one of the other readonly bookmark roots
|
2010-08-24 08:43:50 +00:00
|
|
|
isnot(bookmarksPanel._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
|
2010-04-27 05:10:52 +00:00
|
|
|
|
2010-08-24 08:43:50 +00:00
|
|
|
BrowserUI.activePanel = null;
|
2010-04-27 05:10:52 +00:00
|
|
|
PlacesUtils.bookmarks.removeItem(gCurrentTest.bmId);
|
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
});
|