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
|
|
|
|
2009-09-02 14:22:50 +00:00
|
|
|
var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
|
|
|
|
var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
|
|
|
|
|
|
|
|
// 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 {
|
2009-11-19 19:40:54 +00:00
|
|
|
PlacesUtils.bookmarks.removeFolderChildren(BookmarkList.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-07-28 20:31:07 +00:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, 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
|
|
|
|
BookmarkList.show();
|
|
|
|
|
|
|
|
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmarklist-container").hidden == false; });
|
|
|
|
},
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
onBookmarksReady: function() {
|
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-07-28 20:31:07 +00:00
|
|
|
var bookmarkitems = document.getElementById("bookmark-items");
|
2009-10-14 22:43:20 +00:00
|
|
|
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
|
|
|
|
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");
|
|
|
|
|
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 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
|
|
|
|
BookmarkList.show();
|
2009-09-02 14:22:50 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
// Go into edit mode
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = document.getElementById("bookmark-items").items[0];
|
|
|
|
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() {
|
|
|
|
var bookmarkitems = document.getElementById("bookmark-items");
|
|
|
|
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
|
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
|
|
|
|
|
|
|
|
var uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
|
|
|
|
uritextbox.value = testURL_02;
|
|
|
|
|
|
|
|
var 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
|
|
|
var 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
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
BookmarkList.close();
|
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
|
|
|
|
BookmarkList.show();
|
|
|
|
|
|
|
|
// Go into edit mode
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = document.getElementById("bookmark-items").items[0];
|
|
|
|
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-03-01 21:10:31 +00:00
|
|
|
var 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
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
var bookmarkitems = document.getElementById("bookmark-items");
|
|
|
|
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
|
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
var titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
|
|
|
|
var newtitle = "Changed Title";
|
2009-09-02 14:22:50 +00:00
|
|
|
titletextbox.value = newtitle;
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
var 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
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
BookmarkList.close();
|
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
|
|
|
|
BookmarkList.show();
|
|
|
|
|
|
|
|
// Go into edit mode
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = document.getElementById("bookmark-items").items[0];
|
|
|
|
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() {
|
|
|
|
var bookmarkitems = document.getElementById("bookmark-items");
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
|
|
|
|
bookmark.remove();
|
2009-09-02 14:22:50 +00:00
|
|
|
|
2010-03-01 21:10:31 +00:00
|
|
|
var 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");
|
|
|
|
|
2009-10-14 22:43:20 +00:00
|
|
|
BookmarkList.close();
|
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
|
|
|
|
BookmarkList.show();
|
|
|
|
|
|
|
|
// Go into edit mode
|
2010-07-28 20:31:07 +00:00
|
|
|
let bookmark = document.getElementById("bookmark-items").items[0];
|
|
|
|
bookmark.startEditing();
|
2010-04-27 05:10:52 +00:00
|
|
|
|
|
|
|
// Is the "desktop" folder showing?
|
|
|
|
var first = BookmarkList._bookmarks._children.firstChild;
|
|
|
|
is(first.itemId, BookmarkList._bookmarks._desktopFolderId, "Desktop folder is showing");
|
|
|
|
|
|
|
|
// 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
|
|
|
|
EventUtils.synthesizeMouse(first, first.clientWidth / 2, first.clientHeight / 2, {});
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
first = BookmarkList._bookmarks._children.firstChild;
|
|
|
|
|
|
|
|
// It should not be the "desktop" folder
|
|
|
|
isnot(first.itemId, BookmarkList._bookmarks._desktopFolderId, "Desktop folder is not showing after mouse click");
|
|
|
|
|
|
|
|
// But it should be one of the other readonly bookmark roots
|
|
|
|
isnot(BookmarkList._bookmarks._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
|
2010-07-28 20:31:07 +00:00
|
|
|
|
2010-04-27 05:10:52 +00:00
|
|
|
BookmarkList.close();
|
|
|
|
|
|
|
|
PlacesUtils.bookmarks.removeItem(gCurrentTest.bmId);
|
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
});
|