2009-09-02 07:22:50 -07:00
|
|
|
/*
|
|
|
|
* Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
|
|
|
|
* code in mobile/chrome/content in terms of integration with Places
|
|
|
|
* component, specifically for bookmark management.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
var gTests = [];
|
|
|
|
var gCurrentTest = null;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
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-08-24 01:33:43 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test appearance and behavior of the bookmark popup
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test appearance and behavior of the bookmark popup",
|
2010-08-24 01:33:43 -07:00
|
|
|
_currentTab: null,
|
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
run: function() {
|
2010-08-24 01:33:43 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_02, true);
|
|
|
|
|
|
|
|
messageManager.addMessageListener("pageshow",
|
|
|
|
function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
gCurrentTest.onPageLoad();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPageLoad: function() {
|
2010-08-24 01:33:43 -07:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2009-10-15 21:00:14 -07:00
|
|
|
starbutton.click();
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupReady1, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupReady1: function() {
|
|
|
|
// Popup should auto-hide after 2 seconds on the initial bookmark with star
|
|
|
|
setTimeout(gCurrentTest.onPopupGone, 3000);
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupGone: function() {
|
|
|
|
// Make sure it's hidden again
|
|
|
|
is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be auto-hidden");
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
// Let's make it appear again and continue the test
|
2010-08-24 01:33:43 -07:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2009-10-15 21:00:14 -07:00
|
|
|
starbutton.click();
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupReady2, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
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; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupGone2: function() {
|
|
|
|
// Make sure it's hidden again
|
|
|
|
is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be hidden by clicking star");
|
2010-09-16 12:29:03 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
// Let's make it appear again and continue the test
|
2010-09-16 12:29:03 -07:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2009-10-15 21:00:14 -07:00
|
|
|
starbutton.click();
|
2010-09-16 12:29:03 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupReady3, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
|
|
|
|
|
|
|
onPopupReady3: function() {
|
|
|
|
// Let's make it disappear again by clicking somewhere
|
2010-09-16 12:29:03 -07:00
|
|
|
let contentarea = document.getElementById("browsers");
|
2009-10-15 21:00:14 -07:00
|
|
|
EventUtils.synthesizeMouse(contentarea, contentarea.clientWidth / 2, contentarea.clientHeight / 2, {});
|
2010-09-16 12:29:03 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupGone3, function() { return document.getElementById("bookmark-popup").hidden == true; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupGone3: function() {
|
|
|
|
// Make sure it's hidden again
|
|
|
|
is(document.getElementById("bookmark-popup").hidden, true, "Bookmark popup should be hidden by clicking in content");
|
|
|
|
|
2010-08-24 01:33:43 -07:00
|
|
|
BrowserUI.closeTab(this._currentTab);
|
2009-10-15 21:00:14 -07:00
|
|
|
|
|
|
|
runNextTest();
|
2010-08-24 01:33:43 -07:00
|
|
|
}
|
2009-10-15 21:00:14 -07:00
|
|
|
});
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test adding tags via star icon
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test adding tags via star icon",
|
2010-08-24 01:33:43 -07:00
|
|
|
_currentTab: null,
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
run: function() {
|
2010-08-24 01:33:43 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_02, true);
|
|
|
|
|
|
|
|
messageManager.addMessageListener("pageshow",
|
|
|
|
function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
gCurrentTest.onPageLoad();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
onPageLoad: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
var starbutton = document.getElementById("tool-star");
|
2009-09-02 07:22:50 -07:00
|
|
|
starbutton.click();
|
2009-10-15 21:00:14 -07:00
|
|
|
|
|
|
|
waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupReady: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
var editbutton = document.getElementById("bookmark-popup-edit");
|
|
|
|
editbutton.click();
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
onEditorReady: function() {
|
|
|
|
var bookmarkitem = document.getElementById("bookmark-item");
|
|
|
|
bookmarkitem.tags = "tagone, tag two, tag-three, tag4";
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
|
2009-09-02 07:22:50 -07:00
|
|
|
donebutton.click();
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
waitFor(gCurrentTest.onEditorDone, function() { return document.getElementById("bookmark-container").hidden == true; });
|
|
|
|
},
|
|
|
|
|
|
|
|
onEditorDone: function() {
|
2010-03-01 13:10:31 -08:00
|
|
|
var tagsarray = PlacesUtils.tagging.getTagsForURI(makeURI(testURL_02), {});
|
2009-09-02 07:22:50 -07:00
|
|
|
is(tagsarray.length, 4, "All tags are added.");
|
|
|
|
|
2010-08-24 01:33:43 -07:00
|
|
|
BrowserUI.closeTab(this._currentTab);
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
runNextTest();
|
2010-08-24 01:33:43 -07:00
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test editing uri via star icon
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test editing uri via star icon",
|
2010-08-24 01:33:43 -07:00
|
|
|
_currentTab: null,
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
run: function() {
|
2010-08-24 01:33:43 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_02, true);
|
|
|
|
|
|
|
|
messageManager.addMessageListener("pageshow",
|
|
|
|
function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
gCurrentTest.onPageLoad();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-09-02 07:22:50 -07:00
|
|
|
onPageLoad: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let starbutton = document.getElementById("tool-star");
|
2010-08-24 01:33:43 -07:00
|
|
|
starbutton.click();
|
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupReady: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let editbutton = document.getElementById("bookmark-popup-edit");
|
2009-10-14 15:43:20 -07:00
|
|
|
editbutton.click();
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
waitFor(gCurrentTest.onEditorReady, function() { return document.getElementById("bookmark-item").isEditing == true; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
onEditorReady: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmarkitem = document.getElementById("bookmark-item");
|
2009-10-14 15:43:20 -07:00
|
|
|
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
|
2009-09-02 07:22:50 -07:00
|
|
|
uritextbox.value = testURL_01;
|
|
|
|
|
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
|
|
|
waitFor(gCurrentTest.onEditorDone, function() { return document.getElementById("bookmark-container").hidden == true; });
|
|
|
|
},
|
|
|
|
|
|
|
|
onEditorDone: function() {
|
2010-03-01 13:10:31 -08:00
|
|
|
isnot(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01)), -1, testURL_01 + " is now bookmarked");
|
|
|
|
is(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)), -1, testURL_02 + " is no longer bookmarked");
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2010-08-24 01:33:43 -07:00
|
|
|
BrowserUI.closeTab(this._currentTab);
|
2009-09-02 07:22:50 -07:00
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
runNextTest();
|
2010-08-24 01:33:43 -07:00
|
|
|
}
|
2009-10-14 15:43:20 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Test removing existing bookmark via popup
|
|
|
|
gTests.push({
|
|
|
|
desc: "Test removing existing bookmark via popup",
|
2010-08-24 01:33:43 -07:00
|
|
|
_currentTab: null,
|
2009-10-14 15:43:20 -07:00
|
|
|
run: function() {
|
2010-08-24 01:33:43 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, true);
|
|
|
|
|
|
|
|
messageManager.addMessageListener("pageshow",
|
|
|
|
function(aMessage) {
|
|
|
|
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
|
|
|
|
messageManager.removeMessageListener(aMessage.name, arguments.callee);
|
|
|
|
gCurrentTest.onPageLoad();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-10-14 15:43:20 -07:00
|
|
|
onPageLoad: function() {
|
|
|
|
var starbutton = document.getElementById("tool-star");
|
2010-08-24 01:33:43 -07:00
|
|
|
starbutton.click();
|
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
waitFor(gCurrentTest.onPopupReady, function() { return document.getElementById("bookmark-popup").hidden == false; });
|
|
|
|
},
|
2010-08-24 01:33:43 -07:00
|
|
|
|
2009-10-15 21:00:14 -07:00
|
|
|
onPopupReady: function() {
|
2009-10-14 15:43:20 -07:00
|
|
|
var removebutton = document.getElementById("bookmark-popup-remove");
|
|
|
|
removebutton.click();
|
|
|
|
|
2010-03-01 13:10:31 -08:00
|
|
|
var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
2009-10-14 15:43:20 -07:00
|
|
|
ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
|
|
|
|
|
2010-08-24 01:33:43 -07:00
|
|
|
BrowserUI.closeTab(this._currentTab);
|
2009-10-14 15:43:20 -07:00
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
2009-09-02 07:22:50 -07:00
|
|
|
});
|