Bug 529062 - Re-enable browser_views_liveupdate.js test on Mac, and make it check title changes too, r=mano

This commit is contained in:
Marco Bonardo 2010-03-05 09:26:39 -08:00
Родитель a258572db5
Коммит 6b1b3e420d
1 изменённых файлов: 44 добавлений и 25 удалений

Просмотреть файл

@ -50,8 +50,9 @@ function test() {
ok(PlacesUIUtils, "PlacesUIUtils in context");
// Open bookmarks menu.
var menu = document.getElementById("bookmarksMenu");
menu.open = true;
var popup = document.getElementById("bookmarksMenuPopup");
ok(popup, "Menu popup element exists");
fakeOpenPopup(popup);
// Open bookmarks sidebar.
var sidebar = document.getElementById("sidebar");
@ -63,6 +64,18 @@ function test() {
toggleSidebar("viewBookmarksSidebar", true);
}
/**
* Simulates popup opening causing it to populate.
* We cannot just use menu.open, since it would not work on Mac due to native menubar.
*/
function fakeOpenPopup(aPopup) {
var popupEvent = document.createEvent("MouseEvent");
popupEvent.initMouseEvent("popupshowing", true, true, window, 0,
0, 0, 0, 0, false, false, false, false,
0, null);
aPopup.dispatchEvent(popupEvent);
}
/**
* Adds bookmarks observer, and executes a bunch of bookmarks operations.
*/
@ -73,12 +86,14 @@ function startTest() {
var addedBookmarks = [];
// MENU
ok(true, "*** Acting on menu bookmarks");
info("*** Acting on menu bookmarks");
var id = bs.insertBookmark(bs.bookmarksMenuFolder,
PlacesUtils._uri("http://bm1.mozilla.org/"),
bs.DEFAULT_INDEX,
"bm1");
addedBookmarks.push(id);
// Test live update of title.
bs.setItemTitle(id, "bm1_edited");
id = bs.insertBookmark(bs.bookmarksMenuFolder,
PlacesUtils._uri("place:"),
bs.DEFAULT_INDEX,
@ -98,12 +113,14 @@ function startTest() {
bs.moveItem(id, bs.bookmarksMenuFolder, 0);
// TOOLBAR
ok(true, "*** Acting on toolbar bookmarks");
info("*** Acting on toolbar bookmarks");
id = bs.insertBookmark(bs.toolbarFolder,
PlacesUtils._uri("http://tb1.mozilla.org/"),
bs.DEFAULT_INDEX,
"tb1");
addedBookmarks.push(id);
// Test live update of title.
bs.setItemTitle(id, "tb1_edited");
id = bs.insertBookmark(bs.toolbarFolder,
PlacesUtils._uri("place:"),
bs.DEFAULT_INDEX,
@ -123,12 +140,14 @@ function startTest() {
bs.moveItem(id, bs.toolbarFolder, 0);
// UNSORTED
ok(true, "*** Acting on unsorted bookmarks");
info("*** Acting on unsorted bookmarks");
id = bs.insertBookmark(bs.unfiledBookmarksFolder,
PlacesUtils._uri("http://ub1.mozilla.org/"),
bs.DEFAULT_INDEX,
"ub1");
addedBookmarks.push(id);
// Test live update of title.
bs.setItemTitle(id, "ub1_edited");
id = bs.insertBookmark(bs.unfiledBookmarksFolder,
PlacesUtils._uri("place:"),
bs.DEFAULT_INDEX,
@ -165,10 +184,6 @@ function startTest() {
* Restores browser state and calls finish.
*/
function finishTest() {
// Close bookmarks menu.
var menu = document.getElementById("bookmarksMenu");
menu.open = false;
// Close bookmarks sidebar.
toggleSidebar("viewBookmarksSidebar", false);
@ -191,13 +206,11 @@ var bookmarksObserver = {
onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex,
aItemType) {
var views = getViewsForFolder(aFolderId);
ok(views.length > 0, "Found affected views: " + views);
ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
// Check that item has been added in the correct position.
for (var i = 0; i < views.length; i++) {
var node = null;
var index = null;
[node, index] = searchItemInView(aItemId, views[i]);
var [node, index] = searchItemInView(aItemId, views[i]);
isnot(node, null, "Found new Places node in " + views[i]);
is(index, aIndex, "Node is at index " + index);
}
@ -206,7 +219,7 @@ var bookmarksObserver = {
onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex,
aItemType) {
var views = getViewsForFolder(aFolderId);
ok(views.length > 0, "Found affected views: " + views);
ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
// Check that item has been removed.
for (var i = 0; i < views.length; i++) {
var node = null;
@ -237,7 +250,21 @@ var bookmarksObserver = {
onEndUpdateBatch: function PSB_onEndUpdateBatch() {},
onBeforeItemRemoved: function PSB_onBeforeItemRemoved(aItemId) {},
onItemVisited: function() {},
onItemChanged: function PSB_onItemChanged() {}
onItemChanged: function PSB_onItemChanged(aItemId, aProperty, aIsAnnotationProperty, aValue) {
if (aProperty !== "title")
return;
var views = getViewsForFolder(PlacesUtils.bookmarks.getFolderIdForItem(aItemId));
ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
// Check that item has been moved in the correct position.
for (var i = 0; i < views.length; i++) {
var [node, index] = searchItemInView(aItemId, views[i]);
isnot(node, null, "Found new Places node in " + views[i]);
is(node.title, aValue, "Node has correct title: " + aValue);
}
}
};
/**
@ -250,8 +277,6 @@ var bookmarksObserver = {
* @returns [node, index] or [null, null] if not found.
*/
function searchItemInView(aItemId, aView) {
var node = null;
var index = null;
switch (aView) {
case "toolbar":
return getNodeForToolbarItem(aItemId);
@ -333,11 +358,9 @@ function getNodeForMenuItem(aItemId) {
// different position. Search only folders
if (PlacesUtils.nodeIsFolder(child.node)) {
var popup = child.lastChild;
// XXX Why is this needed on Linux and Mac?
popup.showPopup(popup);
child.open = true;
fakeOpenPopup(popup);
var foundNode = findNode(popup);
popup.hidePopup();
child.open = false;
if (foundNode[0] != null)
return foundNode;
@ -357,7 +380,6 @@ function getNodeForMenuItem(aItemId) {
* @returns [node, index] or [null, null] if not found.
*/
function getNodeForSidebarItem(aItemId) {
ok(true, "getNodeForSidebar");
var sidebar = document.getElementById("sidebar");
var tree = sidebar.contentDocument.getElementById("bookmarks-view");
@ -426,9 +448,6 @@ function getViewsForFolder(aFolderId) {
return ["toolbar", "sidebar"]
break;
case PlacesUtils.bookmarksMenuFolderId:
// XXX Skip menu tests on Mac, due to native menubar.
if (navigator.platform.toLowerCase().indexOf("mac") != -1)
return ["sidebar"];
return ["menu", "sidebar"]
break;
case PlacesUtils.unfiledBookmarksFolderId: