46
function waitForPageShow(aCallback) {
47
messageManager.addMessageListener("pageshow", function(aMessage) {
48
if (gCurrentTest._currentTab.browser.currentURI.spec != "about:blank") {
49
messageManager.removeMessageListener(aMessage.name, arguments.callee);
50
setTimeout(aCallback, 0);
55
function waitForNavigationPanel(aCallback, aWaitForHide) {
56
let evt = aWaitForHide ? "NavigationPanelHidden" : "NavigationPanelShown";
57
info("waitFor " + evt + "(" + Components.stack.caller + ")");
58
window.addEventListener(evt, function(aEvent) {
59
info("receive " + evt);
60
window.removeEventListener(aEvent.type, arguments.callee, false);
61
setTimeout(aCallback, 0);
46
65
//------------------------------------------------------------------------------
47
66
// Case: Test adding a bookmark with the Star button
49
68
desc: "Test adding a bookmark with the Star button",
53
this._currenttab = Browser.addTab(testURL_01, true);
72
this._currentTab = Browser.addTab(testURL_01, true);
55
74
// Need to wait until the page is loaded
56
this._currenttab.browser.addEventListener("load",
58
gCurrentTest._currenttab.browser.removeEventListener("load", arguments.callee, true);
59
gCurrentTest.onPageReady();
75
waitForPageShow(gCurrentTest.onPageReady);
64
78
onPageReady: function() {
65
var starbutton = document.getElementById("tool-star");
68
var bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
69
ok(bookmarkItem != -1, testURL_01 + " should be added.");
71
Browser.closeTab(gCurrentTest._currenttab);
79
let starbutton = document.getElementById("tool-star");
82
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
83
ok(bookmark != -1, testURL_01 + " should be added.");
85
Browser.closeTab(gCurrentTest._currentTab);
77
91
//------------------------------------------------------------------------------
78
92
// Case: Test clicking on a bookmark loads the web page
80
94
desc: "Test clicking on a bookmark loads the web page",
84
this._currenttab = Browser.addTab("about:blank", true);
98
BrowserUI.closeAutoComplete(true);
99
this._currentTab = Browser.addTab(testURL_02, true);
86
101
// Need to wait until the page is loaded
87
this._currenttab.browser.addEventListener("load",
89
gCurrentTest._currenttab.browser.removeEventListener("load", arguments.callee, true);
90
gCurrentTest.onPageReady();
102
waitForPageShow(gCurrentTest.onPageReady);
95
105
onPageReady: function() {
96
// Open the bookmark list
106
// Wait for the bookmarks to load, then do the test
107
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
108
BrowserUI.doCommand("cmd_bookmarks");
99
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmarklist-container").hidden == false; });
102
111
onBookmarksReady: function() {
103
// Create a listener for the opening bookmark
104
gCurrentTest._currenttab.browser.addEventListener("pageshow",
106
gCurrentTest._currenttab.browser.removeEventListener("pageshow", arguments.callee, true);
107
todo_is(gCurrentTest._currenttab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");
109
Browser.closeTab(gCurrentTest._currenttab);
115
var bookmarkitems = document.getElementById("bookmark-items");
116
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
112
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
113
bookmarkitem.control.scrollBoxObject.ensureElementIsVisible(bookmarkitem);
117
115
isnot(bookmarkitem, null, "Found the bookmark");
118
116
is(bookmarkitem.getAttribute("uri"), testURL_01, "Bookmark has the right URL via attribute");
119
117
is(bookmarkitem.spec, testURL_01, "Bookmark has the right URL via property");
121
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
119
// Create a listener for the opening bookmark
120
waitForPageShow(function() {
121
is(gCurrentTest._currentTab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");
122
Browser.closeTab(gCurrentTest._currentTab);
127
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
125
131
//------------------------------------------------------------------------------
128
134
desc: "Test editing URI of existing bookmark",
130
136
run: function() {
131
// Open the bookmark list
137
// Wait for the bookmarks to load, then do the test
138
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
139
BrowserUI.doCommand("cmd_bookmarks");
142
onBookmarksReady: function() {
134
143
// Go into edit mode
135
BookmarkList.toggleManage();
144
let bookmark = BookmarkList.panel.items[0];
145
bookmark.startEditing();
137
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
147
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
140
onBookmarksReady: function() {
141
var bookmarkitems = document.getElementById("bookmark-items");
142
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_01);
143
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
145
var uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
150
onEditorReady: function() {
151
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
152
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
154
let uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
146
155
uritextbox.value = testURL_02;
148
var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
157
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
149
158
donebutton.click();
151
var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
160
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
152
161
is(bookmark, -1, testURL_01 + " should no longer in bookmark");
153
162
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
154
163
isnot(bookmark, -1, testURL_02 + " is in bookmark");
156
BookmarkList.close();
165
BrowserUI.activePanel = null;
162
171
//------------------------------------------------------------------------------
163
172
// Case: Test editing title of existing bookmark
165
174
desc: "Test editing title of existing bookmark",
167
176
run: function() {
168
// Open the bookmark list
177
// Wait for the bookmarks to load, then do the test
178
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
179
BrowserUI.doCommand("cmd_bookmarks");
182
onBookmarksReady: function() {
171
183
// Go into edit mode
172
BookmarkList.toggleManage();
184
let bookmark = BookmarkList.panel.items[0];
185
bookmark.startEditing();
174
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
187
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
177
onBookmarksReady: function() {
178
var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
190
onEditorReady: function() {
191
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
179
192
is(PlacesUtils.bookmarks.getItemTitle(bookmark), "Browser Blank Page 01", "Title remains the same.");
181
var bookmarkitems = document.getElementById("bookmark-items");
182
var bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
183
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
185
var titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
186
var newtitle = "Changed Title";
194
let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
195
EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
197
let titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
198
let newtitle = "Changed Title";
187
199
titletextbox.value = newtitle;
189
var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
201
let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
190
202
donebutton.click();
192
204
isnot(PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02)), -1, testURL_02 + " is still in bookmark.");
193
205
is(PlacesUtils.bookmarks.getItemTitle(bookmark), newtitle, "Title is changed.");
195
BookmarkList.close();
207
BrowserUI.activePanel = null;
204
216
desc: "Test removing existing bookmark",
205
217
bookmarkitem: null,
207
219
run: function() {
208
// Open the bookmark list
220
// Wait for the bookmarks to load, then do the test
221
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
222
BrowserUI.doCommand("cmd_bookmarks");
225
onBookmarksReady: function() {
211
226
// Go into edit mode
212
BookmarkList.toggleManage();
214
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
217
onBookmarksReady: function() {
218
var bookmarkitems = document.getElementById("bookmark-items");
219
gCurrentTest.bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
220
gCurrentTest.bookmarkitem.click();
222
waitFor(gCurrentTest.onEditorReady, function() { return gCurrentTest.bookmarkitem.isEditing == true; });
227
let bookmark = BookmarkList.panel.items[0];
228
bookmark.startEditing();
230
waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
225
233
onEditorReady: function() {
226
var removebutton = document.getAnonymousElementByAttribute(gCurrentTest.bookmarkitem, "anonid", "remove-button");
227
removebutton.click();
229
var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
234
let bookmark = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
237
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
230
238
ok(bookmark == -1, testURL_02 + " should no longer in bookmark");
231
239
bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
232
240
ok(bookmark == -1, testURL_01 + " should no longer in bookmark");
234
BookmarkList.close();
242
BrowserUI.activePanel = null;
251
259
Ci.nsINavBookmarksService.DEFAULT_INDEX,
254
// Open the bookmark list
258
BookmarkList.toggleManage();
260
waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
262
// Wait for the bookmarks to load, then do the test
263
waitForNavigationPanel(gCurrentTest.onBookmarksReady);
264
BrowserUI.doCommand("cmd_bookmarks");
263
267
onBookmarksReady: function() {
269
let bookmarksPanel = BookmarkList.panel;
270
let bookmark = bookmarksPanel.items[0];
271
bookmark.startEditing();
264
273
// Is the "desktop" folder showing?
265
var first = BookmarkList._bookmarks._children.firstChild;
266
is(first.itemId, BookmarkList._bookmarks._desktopFolderId, "Desktop folder is showing");
274
let first = bookmarksPanel._children.firstChild;
275
is(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is showing");
268
277
// Is the "desktop" folder in edit mode?
269
278
is(first.isEditing, false, "Desktop folder is not in edit mode");
272
280
// Do not allow the "desktop" folder to be editable by tap
273
EventUtils.synthesizeMouse(first, first.clientWidth / 2, first.clientHeight / 2, {});
281
EventUtils.synthesizeMouse(first, first.width / 2, first.height / 2, {});
275
283
// A tap on the "desktop" folder _should_ open the folder, not put it into edit mode.
276
284
// So we need to get the first item again.
277
first = BookmarkList._bookmarks._children.firstChild;
285
first = bookmarksPanel._children.firstChild;
279
287
// It should not be the "desktop" folder
280
isnot(first.itemId, BookmarkList._bookmarks._desktopFolderId, "Desktop folder is not showing after mouse click");
288
isnot(first.itemId, bookmarksPanel._desktopFolderId, "Desktop folder is not showing after mouse click");
282
290
// But it should be one of the other readonly bookmark roots
283
isnot(BookmarkList._bookmarks._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
285
BookmarkList.close();
291
isnot(bookmarksPanel._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
287
293
PlacesUtils.bookmarks.removeItem(gCurrentTest.bmId);
295
BrowserUI.activePanel = null;