~ubuntu-branches/ubuntu/trusty/fennec/trusty

« back to all changes in this revision

Viewing changes to mobile/chrome/tests/browser_bookmarks.js

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-01-26 20:31:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110126203140-zcg54f8ost2vmrxr
Tags: 4.0~b3-0ubuntu1
* New upstream release v4.0 B3 (FENNEC_4_0b3_RELEASE)

* Update build-depends for xulrunner-2.0
  - update debian/control
* Update mozclient to point to the mobile-browser repo
  - update debian/mozclient/fennec.conf
* Build with "--with-system-libxul"
  - update debian/rules
* Add launcher script, based on the one used in Firefox but with the
  unnecessary bits stripped out
  - add debian/fennec.sh
  - update debian/rules
* Refresh patches for new version
  - update debian/patches/bump_gecko_versions_in_application.ini.patch
  - update debian/patches/ubuntu_codes_google.patch
  - update debian/patches/installer.patch
* Drop unneeded patches
  - remove debian/patches/nspr_flags_by_pkg_config_hack.patch
  - remove debian/patches/xul191_l10n.patch
  - update debian/patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome 
 
2
 * Bug 486490 - Fennec browser-chrome tests to verify correct implementation of chrome
3
3
 *              code in mobile/chrome/content in terms of integration with Places
4
4
 *              component, specifically for bookmark management.
5
5
 */
6
6
 
7
 
var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
8
 
var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
 
7
var testURL_01 = chromeRoot + "browser_blank_01.html";
 
8
var testURL_02 = chromeRoot + "browser_blank_02.html";
9
9
 
10
10
// A queue to order the tests and a handle for each test
11
11
var gTests = [];
17
17
  // The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
18
18
  // We call "finish()" when the tests are finished
19
19
  waitForExplicitFinish();
20
 
  
 
20
 
21
21
  // Start the tests
22
22
  runNextTest();
23
23
}
34
34
  else {
35
35
    // Cleanup. All tests are completed at this point
36
36
    try {
37
 
      PlacesUtils.bookmarks.removeFolderChildren(BookmarkList.mobileRoot);
 
37
      PlacesUtils.bookmarks.removeFolderChildren(BookmarkList.panel.mobileRoot);
38
38
    }
39
39
    finally {
40
40
      // We must finialize the tests
43
43
  }
44
44
}
45
45
 
 
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);
 
51
    }
 
52
  });
 
53
}
 
54
 
 
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);
 
62
  }, false);
 
63
}
 
64
 
46
65
//------------------------------------------------------------------------------
47
66
// Case: Test adding a bookmark with the Star button
48
67
gTests.push({
49
68
  desc: "Test adding a bookmark with the Star button",
50
 
  _currenttab: null,
 
69
  _currentTab: null,
51
70
 
52
71
  run: function() {
53
 
    this._currenttab = Browser.addTab(testURL_01, true);
 
72
    this._currentTab = Browser.addTab(testURL_01, true);
54
73
 
55
74
    // Need to wait until the page is loaded
56
 
    this._currenttab.browser.addEventListener("load", 
57
 
    function() {
58
 
      gCurrentTest._currenttab.browser.removeEventListener("load", arguments.callee, true);
59
 
      gCurrentTest.onPageReady();
60
 
    }, 
61
 
    true);
 
75
    waitForPageShow(gCurrentTest.onPageReady);
62
76
  },
63
 
  
 
77
 
64
78
  onPageReady: function() {
65
 
    var starbutton = document.getElementById("tool-star");
66
 
    starbutton.click();    
67
 
    
68
 
    var bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
69
 
    ok(bookmarkItem != -1, testURL_01 + " should be added.");
70
 
 
71
 
    Browser.closeTab(gCurrentTest._currenttab);
72
 
    
 
79
    let starbutton = document.getElementById("tool-star");
 
80
    starbutton.click();
 
81
 
 
82
    let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
 
83
    ok(bookmark != -1, testURL_01 + " should be added.");
 
84
 
 
85
    Browser.closeTab(gCurrentTest._currentTab);
 
86
 
73
87
    runNextTest();
74
 
  }  
 
88
  }
75
89
});
76
90
 
77
91
//------------------------------------------------------------------------------
78
92
// Case: Test clicking on a bookmark loads the web page
79
93
gTests.push({
80
94
  desc: "Test clicking on a bookmark loads the web page",
81
 
  _currenttab: null,
 
95
  _currentTab: null,
82
96
 
83
97
  run: function() {
84
 
    this._currenttab = Browser.addTab("about:blank", true);
 
98
    BrowserUI.closeAutoComplete(true);
 
99
    this._currentTab = Browser.addTab(testURL_02, true);
85
100
 
86
101
    // Need to wait until the page is loaded
87
 
    this._currenttab.browser.addEventListener("load", 
88
 
    function() {
89
 
      gCurrentTest._currenttab.browser.removeEventListener("load", arguments.callee, true);
90
 
      gCurrentTest.onPageReady();
91
 
    }, 
92
 
    true);
 
102
    waitForPageShow(gCurrentTest.onPageReady);
93
103
  },
94
104
 
95
105
  onPageReady: function() {
96
 
    // Open the bookmark list
97
 
    BookmarkList.show();
 
106
    // Wait for the bookmarks to load, then do the test
 
107
    waitForNavigationPanel(gCurrentTest.onBookmarksReady);
 
108
    BrowserUI.doCommand("cmd_bookmarks");
 
109
  },
98
110
 
99
 
    waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmarklist-container").hidden == false; });
100
 
  },
101
 
  
102
111
  onBookmarksReady: function() {
103
 
    // Create a listener for the opening bookmark  
104
 
    gCurrentTest._currenttab.browser.addEventListener("pageshow", 
105
 
      function() {
106
 
        gCurrentTest._currenttab.browser.removeEventListener("pageshow", arguments.callee, true);
107
 
        todo_is(gCurrentTest._currenttab.browser.currentURI.spec, testURL_01, "Opened the right bookmark");      
108
 
 
109
 
        Browser.closeTab(gCurrentTest._currenttab);
110
 
 
111
 
        runNextTest();
112
 
      }, 
113
 
      true);
114
 
 
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);
 
114
 
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");
120
118
 
121
 
    EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.clientWidth / 2, bookmarkitem.clientHeight / 2, {});
122
 
  }  
 
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);
 
123
 
 
124
      runNextTest();
 
125
    });
 
126
 
 
127
    EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
 
128
  }
123
129
});
124
130
 
125
131
//------------------------------------------------------------------------------
128
134
  desc: "Test editing URI of existing bookmark",
129
135
 
130
136
  run: function() {
131
 
    // Open the bookmark list
132
 
    BookmarkList.show();
 
137
    // Wait for the bookmarks to load, then do the test
 
138
    waitForNavigationPanel(gCurrentTest.onBookmarksReady);
 
139
    BrowserUI.doCommand("cmd_bookmarks");
 
140
  },
133
141
 
 
142
  onBookmarksReady: function() {
134
143
    // Go into edit mode
135
 
    BookmarkList.toggleManage();
 
144
    let bookmark = BookmarkList.panel.items[0];
 
145
    bookmark.startEditing();
136
146
 
137
 
    waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
 
147
    waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
138
148
  },
139
 
  
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, {});
144
 
 
145
 
    var uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
 
149
 
 
150
  onEditorReady: function() {
 
151
    let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_01);
 
152
    EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
 
153
 
 
154
    let uritextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "uri");
146
155
    uritextbox.value = testURL_02;
147
156
 
148
 
    var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
 
157
    let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
149
158
    donebutton.click();
150
159
 
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");
155
 
    
156
 
    BookmarkList.close();
157
 
    
 
164
 
 
165
    BrowserUI.activePanel = null;
 
166
 
158
167
    runNextTest();
159
 
  }  
 
168
  }
160
169
});
161
170
 
162
171
//------------------------------------------------------------------------------
163
172
// Case: Test editing title of existing bookmark
164
173
gTests.push({
165
174
  desc: "Test editing title of existing bookmark",
166
 
  
 
175
 
167
176
  run: function() {
168
 
    // Open the bookmark list
169
 
    BookmarkList.show();
 
177
    // Wait for the bookmarks to load, then do the test
 
178
    waitForNavigationPanel(gCurrentTest.onBookmarksReady);
 
179
    BrowserUI.doCommand("cmd_bookmarks");
 
180
  },
170
181
 
 
182
  onBookmarksReady: function() {
171
183
    // Go into edit mode
172
 
    BookmarkList.toggleManage();
 
184
    let bookmark = BookmarkList.panel.items[0];
 
185
    bookmark.startEditing();
173
186
 
174
 
    waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
 
187
    waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
175
188
  },
176
 
  
177
 
  onBookmarksReady: function() {
178
 
    var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
 
189
 
 
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.");
180
 
    
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, {});
184
 
    
185
 
    var titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
186
 
    var newtitle = "Changed Title";
 
193
 
 
194
    let bookmarkitem = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
 
195
    EventUtils.synthesizeMouse(bookmarkitem, bookmarkitem.width / 2, bookmarkitem.height / 2, {});
 
196
 
 
197
    let titletextbox = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "name");
 
198
    let newtitle = "Changed Title";
187
199
    titletextbox.value = newtitle;
188
 
    
189
 
    var donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
 
200
 
 
201
    let donebutton = document.getAnonymousElementByAttribute(bookmarkitem, "anonid", "done-button");
190
202
    donebutton.click();
191
203
 
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.");
194
 
    
195
 
    BookmarkList.close();
196
 
    
 
206
 
 
207
    BrowserUI.activePanel = null;
 
208
 
197
209
    runNextTest();
198
210
  }
199
211
});
203
215
gTests.push({
204
216
  desc: "Test removing existing bookmark",
205
217
  bookmarkitem: null,
206
 
  
 
218
 
207
219
  run: function() {
208
 
    // Open the bookmark list
209
 
    BookmarkList.show();
 
220
    // Wait for the bookmarks to load, then do the test
 
221
    waitForNavigationPanel(gCurrentTest.onBookmarksReady);
 
222
    BrowserUI.doCommand("cmd_bookmarks");
 
223
  },
210
224
 
 
225
  onBookmarksReady: function() {
211
226
    // Go into edit mode
212
 
    BookmarkList.toggleManage();
213
 
 
214
 
    waitFor(gCurrentTest.onBookmarksReady, function() { return document.getElementById("bookmark-items").manageUI == true; });
215
 
  },
216
 
  
217
 
  onBookmarksReady: function() {
218
 
    var bookmarkitems = document.getElementById("bookmark-items");
219
 
    gCurrentTest.bookmarkitem = document.getAnonymousElementByAttribute(bookmarkitems, "uri", testURL_02);
220
 
    gCurrentTest.bookmarkitem.click();
221
 
 
222
 
    waitFor(gCurrentTest.onEditorReady, function() { return gCurrentTest.bookmarkitem.isEditing == true; });
223
 
  },
224
 
  
 
227
    let bookmark = BookmarkList.panel.items[0];
 
228
    bookmark.startEditing();
 
229
 
 
230
    waitFor(gCurrentTest.onEditorReady, function() { return bookmark.isEditing == true; });
 
231
  },
 
232
 
225
233
  onEditorReady: function() {
226
 
    var removebutton = document.getAnonymousElementByAttribute(gCurrentTest.bookmarkitem, "anonid", "remove-button");
227
 
    removebutton.click();
228
 
    
229
 
    var bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
 
234
    let bookmark = document.getAnonymousElementByAttribute(BookmarkList.panel, "uri", testURL_02);
 
235
    bookmark.remove();
 
236
 
 
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");
233
241
 
234
 
    BookmarkList.close();
 
242
    BrowserUI.activePanel = null;
235
243
 
236
244
    runNextTest();
237
245
  }
242
250
gTests.push({
243
251
  desc: "Test editing title of desktop folder",
244
252
  bmId: null,
245
 
  
 
253
 
246
254
  run: function() {
247
255
    // Add a bookmark to the desktop area so the desktop folder is displayed
248
256
    gCurrentTest.bmId = PlacesUtils.bookmarks
251
259
                                                   Ci.nsINavBookmarksService.DEFAULT_INDEX,
252
260
                                                   testURL_02);
253
261
 
254
 
    // Open the bookmark list
255
 
    BookmarkList.show();
256
 
 
257
 
    // Go into edit mode
258
 
    BookmarkList.toggleManage();
259
 
 
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");
261
265
  },
262
 
  
 
266
 
263
267
  onBookmarksReady: function() {
 
268
    // Go into edit mode
 
269
    let bookmarksPanel = BookmarkList.panel;
 
270
    let bookmark = bookmarksPanel.items[0];
 
271
    bookmark.startEditing();
 
272
 
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");
267
276
 
268
277
    // Is the "desktop" folder in edit mode?
269
278
    is(first.isEditing, false, "Desktop folder is not in edit mode");
270
279
 
271
 
 
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, {});
274
282
 
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;
278
286
 
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");
281
289
 
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");
284
 
    
285
 
    BookmarkList.close();
 
291
    isnot(bookmarksPanel._readOnlyFolders.indexOf(parseInt(first.itemId)), -1, "Desktop subfolder is showing after mouse click");
286
292
 
287
293
    PlacesUtils.bookmarks.removeItem(gCurrentTest.bmId);
288
294
 
 
295
    BrowserUI.activePanel = null;
289
296
    runNextTest();
290
297
  }
291
298
});