зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1094853 - Convert chrome tests in browser/components/places to Bookmarks.jsm API r=mak
This commit is contained in:
Родитель
425a83de72
Коммит
2989e9ca45
|
@ -34,47 +34,50 @@
|
|||
<![CDATA[
|
||||
|
||||
function runTest() {
|
||||
// Sanity checks.
|
||||
ok(PlacesUtils, "PlacesUtils is running in chrome context");
|
||||
ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
|
||||
ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
|
||||
"Left pane version in chrome context, " +
|
||||
"current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION );
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var fakeLeftPanes = [];
|
||||
var as = PlacesUtils.annotations;
|
||||
var bs = PlacesUtils.bookmarks;
|
||||
Task.spawn(function* () {
|
||||
// Sanity checks.
|
||||
ok(PlacesUtils, "PlacesUtils is running in chrome context");
|
||||
ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
|
||||
ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0,
|
||||
"Left pane version in chrome context, " +
|
||||
"current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION );
|
||||
|
||||
// We need 2 left pane folders to simulate a corrupt profile.
|
||||
do {
|
||||
let leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
|
||||
// Create a fake left pane folder.
|
||||
let fakeLeftPaneRoot = bs.createFolder(PlacesUtils.placesRootId, "",
|
||||
bs.DEFAULT_INDEX);
|
||||
as.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
|
||||
PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
|
||||
as.EXPIRE_NEVER);
|
||||
fakeLeftPanes.push(fakeLeftPaneRoot);
|
||||
} while (fakeLeftPanes.length < 2);
|
||||
let fakeLeftPanes = [];
|
||||
// We need 2 left pane folders to simulate a corrupt profile.
|
||||
do {
|
||||
let leftPaneItems = PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
|
||||
|
||||
// Initialize the left pane queries.
|
||||
PlacesUIUtils.leftPaneFolderId;
|
||||
// Create a fake left pane folder.
|
||||
let folder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.rootGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER
|
||||
});
|
||||
|
||||
// Check left pane.
|
||||
ok(PlacesUIUtils.leftPaneFolderId > 0,
|
||||
"Left pane folder correctly created");
|
||||
var leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
|
||||
is(leftPaneItems.length, 1,
|
||||
"We correctly have only 1 left pane folder");
|
||||
let fakeLeftPaneRoot = yield PlacesUtils.promiseItemId(folder.guid);
|
||||
PlacesUtils.annotations.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO,
|
||||
PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
fakeLeftPanes.push(folder.guid);
|
||||
} while (fakeLeftPanes.length < 2);
|
||||
|
||||
// Check that all old left pane items have been removed.
|
||||
fakeLeftPanes.forEach(function(aItemId) {
|
||||
try {
|
||||
bs.getItemTitle(aItemId);
|
||||
throw("This folder should have been removed");
|
||||
} catch (ex) {}
|
||||
});
|
||||
// Initialize the left pane queries.
|
||||
PlacesUIUtils.leftPaneFolderId;
|
||||
|
||||
// Check left pane.
|
||||
ok(PlacesUIUtils.leftPaneFolderId > 0,
|
||||
"Left pane folder correctly created");
|
||||
let leftPaneItems = PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO);
|
||||
is(leftPaneItems.length, 1,
|
||||
"We correctly have only 1 left pane folder");
|
||||
|
||||
// Check that all old left pane items have been removed.
|
||||
for (let guid of fakeLeftPanes) {
|
||||
ok(!(yield PlacesUtils.bookmarks.fetch({guid})), "This folder should have been removed");
|
||||
}
|
||||
}).then(() => SimpleTest.finish());
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
|
|
@ -42,43 +42,48 @@
|
|||
*/
|
||||
|
||||
function runTest() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
function uri(spec) {
|
||||
return ios.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Add a bookmark.
|
||||
var itemId = bs.insertBookmark(PlacesUtils.toolbarFolderId,
|
||||
uri("http://www.example.com/"),
|
||||
bs.DEFAULT_INDEX,
|
||||
"mozilla");
|
||||
|
||||
// Init panel.
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
|
||||
// We must be sure tree is initialized, so we wait for place to be set.
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var tree = gEditItemOverlay._element("folderTree");
|
||||
tree.addEventListener("DOMAttrModified", function(event) {
|
||||
if (event.attrName != "place")
|
||||
return;
|
||||
tree.removeEventListener("DOMAttrModified", arguments.callee, false);
|
||||
SimpleTest.executeSoon(function() {
|
||||
tree.view.selection.clearSelection();
|
||||
ok(document.getElementById("editBMPanel_newFolderButton").disabled,
|
||||
"New folder button is disabled if there's no selection");
|
||||
|
||||
// Cleanup.
|
||||
bs.removeItem(itemId);
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}, false);
|
||||
// Open the folder tree.
|
||||
document.getElementById("editBMPanel_foldersExpander").doCommand();
|
||||
Task.spawn(function* () {
|
||||
// Add a bookmark.
|
||||
let bm = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
url: "http://www.example.com/",
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
title: "mozilla"
|
||||
});
|
||||
|
||||
// Init panel.
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
let itemId = yield PlacesUtils.promiseItemId(bm.guid);
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
|
||||
|
||||
let tree = gEditItemOverlay._element("folderTree");
|
||||
yield openFolderTree(tree);
|
||||
|
||||
tree.view.selection.clearSelection();
|
||||
ok(document.getElementById("editBMPanel_newFolderButton").disabled,
|
||||
"New folder button is disabled if there's no selection");
|
||||
|
||||
// Cleanup.
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
}).then(() => SimpleTest.finish());
|
||||
}
|
||||
|
||||
function openFolderTree(tree) {
|
||||
return new Promise(resolve => {
|
||||
tree.addEventListener("DOMAttrModified", function onAttrModified(event) {
|
||||
if (event.attrName == "place") {
|
||||
tree.removeEventListener("DOMAttrModified", onAttrModified);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
// Open the folder tree.
|
||||
document.getElementById("editBMPanel_foldersExpander").doCommand();
|
||||
});
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
|
|
@ -37,47 +37,45 @@
|
|||
<![CDATA[
|
||||
|
||||
function runTest() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var ts = Cc["@mozilla.org/browser/tagging-service;1"].
|
||||
getService(Ci.nsITaggingService);
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
function uri(spec) {
|
||||
return ios.newURI(spec, null, null);
|
||||
}
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var testURI = uri("http://www.example.com/");
|
||||
var testTag = "foo";
|
||||
var testTagUpper = "Foo";
|
||||
Task.spawn(function* () {
|
||||
let testTag = "foo";
|
||||
let testTagUpper = "Foo";
|
||||
let testURI = Services.io.newURI("http://www.example.com/", null, null);
|
||||
|
||||
// Add a bookmark
|
||||
var itemId = bs.insertBookmark(bs.toolbarFolder,
|
||||
testURI,
|
||||
bs.DEFAULT_INDEX,
|
||||
"mozilla");
|
||||
// Add a bookmark.
|
||||
let bm = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
title: "mozilla",
|
||||
url: testURI
|
||||
});
|
||||
|
||||
// Init panel
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
// Init panel
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
let itemId = yield PlacesUtils.promiseItemId(bm.guid);
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
|
||||
// add a tag
|
||||
document.getElementById("editBMPanel_tagsField").value = testTag;
|
||||
gEditItemOverlay.onTagsFieldBlur();
|
||||
// add a tag
|
||||
document.getElementById("editBMPanel_tagsField").value = testTag;
|
||||
gEditItemOverlay.onTagsFieldBlur();
|
||||
|
||||
// test that the tag has been added in the backend
|
||||
is(ts.getTagsForURI(testURI)[0], testTag, "tags match");
|
||||
// test that the tag has been added in the backend
|
||||
is(PlacesUtils.tagging.getTagsForURI(testURI)[0], testTag, "tags match");
|
||||
|
||||
// change the tag
|
||||
document.getElementById("editBMPanel_tagsField").value = testTagUpper;
|
||||
gEditItemOverlay.onTagsFieldBlur();
|
||||
// change the tag
|
||||
document.getElementById("editBMPanel_tagsField").value = testTagUpper;
|
||||
gEditItemOverlay.onTagsFieldBlur();
|
||||
|
||||
// test that the tag has been added in the backend
|
||||
is(ts.getTagsForURI(testURI)[0], testTagUpper, "tags match");
|
||||
// test that the tag has been added in the backend
|
||||
is(PlacesUtils.tagging.getTagsForURI(testURI)[0], testTagUpper, "tags match");
|
||||
|
||||
// Cleanup.
|
||||
ts.untagURI(testURI, [testTag]);
|
||||
bs.removeItem(itemId);
|
||||
// Cleanup.
|
||||
PlacesUtils.tagging.untagURI(testURI, [testTag]);
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
}).then(() => SimpleTest.finish());
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
|
|
@ -41,26 +41,25 @@
|
|||
* Ensures that history views are updated after deleting entries.
|
||||
*/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function runTest() {
|
||||
// The mochitest page is added to history.
|
||||
PlacesTestUtils.clearHistory().then(continue_test);
|
||||
}
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function continue_test() {
|
||||
// Add some visits.
|
||||
let vtime = Date.now() * 1000;
|
||||
const ttype = PlacesUtils.history.TRANSITION_TYPED;
|
||||
let places =
|
||||
[{ uri: Services.io.newURI("http://example.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype },
|
||||
{ uri: Services.io.newURI("http://example2.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype },
|
||||
{ uri: Services.io.newURI("http://example3.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype }];
|
||||
Task.spawn(function* () {
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
|
||||
// Add some visits.
|
||||
let vtime = Date.now() * 1000;
|
||||
const ttype = PlacesUtils.history.TRANSITION_TYPED;
|
||||
let places =
|
||||
[{ uri: Services.io.newURI("http://example.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype },
|
||||
{ uri: Services.io.newURI("http://example2.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype },
|
||||
{ uri: Services.io.newURI("http://example3.tld/", null, null),
|
||||
visitDate: ++vtime, transition: ttype }];
|
||||
|
||||
yield new Promise(resolve => addVisits(places, resolve));
|
||||
|
||||
addVisits(places, function() {
|
||||
// Make a history query.
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let opts = PlacesUtils.history.getNewQueryOptions();
|
||||
|
@ -87,29 +86,28 @@
|
|||
|
||||
// First check live-update of the view when adding visits.
|
||||
places.forEach(place => place.visitDate = ++vtime);
|
||||
addVisits(places, function() {
|
||||
for (let i = 0; i < rc; i++) {
|
||||
selection.select(i);
|
||||
let node = tree.selectedNode;
|
||||
is(node.uri, places[rc - i - 1].uri.spec,
|
||||
"Found expected node at position " + i + ".");
|
||||
}
|
||||
yield new Promise(resolve => addVisits(places, resolve));
|
||||
|
||||
// Now remove the pages and verify live-update again.
|
||||
for (let i = 0; i < rc; i++) {
|
||||
selection.select(0);
|
||||
let node = tree.selectedNode;
|
||||
tree.controller.remove("Removing page");
|
||||
ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
|
||||
node.uri + " removed.");
|
||||
ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
|
||||
}
|
||||
for (let i = 0; i < rc; i++) {
|
||||
selection.select(i);
|
||||
let node = tree.selectedNode;
|
||||
is(node.uri, places[rc - i - 1].uri.spec,
|
||||
"Found expected node at position " + i + ".");
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
|
||||
});
|
||||
});
|
||||
// Now remove the pages and verify live-update again.
|
||||
for (let i = 0; i < rc; i++) {
|
||||
selection.select(0);
|
||||
let node = tree.selectedNode;
|
||||
tree.controller.remove("Removing page");
|
||||
ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
|
||||
node.uri + " removed.");
|
||||
ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
}).then(() => SimpleTest.finish());
|
||||
}
|
||||
|
||||
]]></script>
|
||||
</window>
|
||||
|
|
|
@ -44,37 +44,36 @@
|
|||
* throw.
|
||||
*/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function runTest() {
|
||||
// The mochitest page is added to history.
|
||||
PlacesTestUtils.clearHistory().then(continue_test);
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
Task.spawn(function* () {
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
|
||||
let visits = {
|
||||
uri: Services.io.newURI("http://example.tld/", null, null),
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED
|
||||
};
|
||||
yield new Promise(resolve => addVisits(visits, resolve));
|
||||
|
||||
// Make a history query.
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let opts = PlacesUtils.history.getNewQueryOptions();
|
||||
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
|
||||
|
||||
// Setup the places tree contents.
|
||||
let tree = document.getElementById("tree");
|
||||
tree.place = queryURI;
|
||||
|
||||
let rootNode = tree.result.root;
|
||||
let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
|
||||
obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
|
||||
obs.nodeTitleChanged(rootNode, rootNode.title);
|
||||
ok(true, "No exceptions thrown");
|
||||
|
||||
// Cleanup.
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
}).then(SimpleTest.finish);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
addVisits(
|
||||
{uri: Services.io.newURI("http://example.tld/", null, null),
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED},
|
||||
function() {
|
||||
// Make a history query.
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let opts = PlacesUtils.history.getNewQueryOptions();
|
||||
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
|
||||
|
||||
// Setup the places tree contents.
|
||||
let tree = document.getElementById("tree");
|
||||
tree.place = queryURI;
|
||||
|
||||
let rootNode = tree.result.root;
|
||||
let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver);
|
||||
obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount);
|
||||
obs.nodeTitleChanged(rootNode, rootNode.title);
|
||||
ok(true, "No exceptions thrown");
|
||||
|
||||
// Cleanup.
|
||||
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
|
||||
});
|
||||
}
|
||||
|
||||
]]></script>
|
||||
</window>
|
||||
|
|
|
@ -43,115 +43,126 @@
|
|||
function runTest() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
Task.spawn(function* () {
|
||||
let bs = PlacesUtils.bookmarks;
|
||||
|
||||
let tags = ["a", "b", "c", "d", "e", "f", "g",
|
||||
"h", "i", "l", "m", "n", "o", "p"];
|
||||
let tags = ["a", "b", "c", "d", "e", "f", "g",
|
||||
"h", "i", "l", "m", "n", "o", "p"];
|
||||
|
||||
// Add a bookmark and tag it.
|
||||
let uri1 = NetUtil.newURI("http://www1.mozilla.org/");
|
||||
let id1 = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.toolbarFolderId, uri1,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla"
|
||||
);
|
||||
PlacesUtils.tagging.tagURI(uri1, tags);
|
||||
|
||||
// Add a second bookmark so that tags won't disappear when unchecked.
|
||||
let uri2 = NetUtil.newURI("http://www2.mozilla.org/");
|
||||
let id2 = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.toolbarFolderId, uri2,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla"
|
||||
);
|
||||
PlacesUtils.tagging.tagURI(uri2, tags);
|
||||
|
||||
// Init panel.
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
gEditItemOverlay.initPanel(id1);
|
||||
ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
|
||||
|
||||
// Wait for the tags selector to be open.
|
||||
let tagsSelectorRow = document.getElementById("editBMPanel_tagsSelectorRow");
|
||||
tagsSelectorRow.addEventListener("DOMAttrModified", function (event) {
|
||||
tagsSelectorRow.removeEventListener("DOMAttrModified", arguments.callee, false);
|
||||
SimpleTest.executeSoon(function () {
|
||||
let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
|
||||
|
||||
// Go by two so there is some untouched tag in the middle.
|
||||
for (let i = 8; i < tags.length; i += 2) {
|
||||
tagsSelector.selectedIndex = i;
|
||||
let listItem = tagsSelector.selectedItem;
|
||||
SimpleTest.isnot(listItem, null, "Valid listItem found");
|
||||
|
||||
tagsSelector.ensureElementIsVisible(listItem);
|
||||
let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
|
||||
|
||||
SimpleTest.ok(listItem.checked, "Item is checked " + i);
|
||||
let selectedTag = listItem.label;
|
||||
|
||||
// Uncheck the tag.
|
||||
listItem.checked = false;
|
||||
SimpleTest.is(visibleIndex,
|
||||
tagsSelector.getIndexOfFirstVisibleRow(),
|
||||
"Scroll position did not change");
|
||||
|
||||
// The listbox is rebuilt, so we have to get the new element.
|
||||
let newItem = tagsSelector.selectedItem;
|
||||
SimpleTest.isnot(newItem, null, "Valid new listItem found");
|
||||
SimpleTest.ok(!newItem.checked, "New listItem is unchecked " + i);
|
||||
SimpleTest.is(newItem.label, selectedTag,
|
||||
"Correct tag is still selected");
|
||||
|
||||
// Check the tag.
|
||||
newItem.checked = true;
|
||||
SimpleTest.is(visibleIndex,
|
||||
tagsSelector.getIndexOfFirstVisibleRow(),
|
||||
"Scroll position did not change");
|
||||
}
|
||||
|
||||
// Remove the second bookmark, then nuke some of the tags.
|
||||
PlacesUtils.bookmarks.removeItem(id2);
|
||||
|
||||
// Doing this backwords tests more interesting paths.
|
||||
for (let i = tags.length - 1; i >= 0 ; i -= 2) {
|
||||
tagsSelector.selectedIndex = i;
|
||||
let listItem = tagsSelector.selectedItem;
|
||||
SimpleTest.isnot(listItem, null, "Valid listItem found");
|
||||
|
||||
tagsSelector.ensureElementIsVisible(listItem);
|
||||
let firstVisibleTag = tags[tagsSelector.getIndexOfFirstVisibleRow()];
|
||||
|
||||
SimpleTest.ok(listItem.checked, "Item is checked " + i);
|
||||
let selectedTag = listItem.label;
|
||||
|
||||
// Uncheck the tag.
|
||||
listItem.checked = false;
|
||||
|
||||
// Ensure the first visible tag is still visible in the list.
|
||||
let firstVisibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
|
||||
let lastVisibleIndex = firstVisibleIndex + tagsSelector.getNumberOfVisibleRows() -1;
|
||||
let expectedTagIndex = tags.indexOf(firstVisibleTag);
|
||||
SimpleTest.ok(expectedTagIndex >= firstVisibleIndex &&
|
||||
expectedTagIndex <= lastVisibleIndex,
|
||||
"Scroll position is correct");
|
||||
|
||||
// The listbox is rebuilt, so we have to get the new element.
|
||||
let newItem = tagsSelector.selectedItem;
|
||||
SimpleTest.isnot(newItem, null, "Valid new listItem found");
|
||||
SimpleTest.ok(newItem.checked, "New listItem is checked " + i);
|
||||
SimpleTest.is(tagsSelector.selectedItem.label,
|
||||
tags[Math.min(i + 1, tags.length - 2)],
|
||||
"The next tag is now selected");
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
PlacesUtils.bookmarks.removeItem(id1);
|
||||
|
||||
SimpleTest.finish();
|
||||
// Add a bookmark and tag it.
|
||||
let uri1 = Services.io.newURI("http://www1.mozilla.org/", null, null);
|
||||
let bm1 = yield bs.insert({
|
||||
parentGuid: bs.toolbarGuid,
|
||||
index: bs.DEFAULT_INDEX,
|
||||
type: bs.TYPE_BOOKMARK,
|
||||
title: "mozilla",
|
||||
url: uri1.spec
|
||||
});
|
||||
}, false);
|
||||
PlacesUtils.tagging.tagURI(uri1, tags);
|
||||
|
||||
// Add a second bookmark so that tags won't disappear when unchecked.
|
||||
let uri2 = Services.io.newURI("http://www2.mozilla.org/", null, null);
|
||||
let bm2 = yield bs.insert({
|
||||
parentGuid: bs.toolbarGuid,
|
||||
index: bs.DEFAULT_INDEX,
|
||||
type: bs.TYPE_BOOKMARK,
|
||||
title: "mozilla",
|
||||
url: uri2.spec
|
||||
});
|
||||
PlacesUtils.tagging.tagURI(uri2, tags);
|
||||
|
||||
// Init panel.
|
||||
ok(gEditItemOverlay, "gEditItemOverlay is in context");
|
||||
let id1 = yield PlacesUtils.promiseItemId(bm1.guid);
|
||||
gEditItemOverlay.initPanel(id1);
|
||||
ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized");
|
||||
|
||||
yield openTagSelector();
|
||||
let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
|
||||
|
||||
// Go by two so there is some untouched tag in the middle.
|
||||
for (let i = 8; i < tags.length; i += 2) {
|
||||
tagsSelector.selectedIndex = i;
|
||||
let listItem = tagsSelector.selectedItem;
|
||||
isnot(listItem, null, "Valid listItem found");
|
||||
|
||||
tagsSelector.ensureElementIsVisible(listItem);
|
||||
let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
|
||||
|
||||
ok(listItem.checked, "Item is checked " + i);
|
||||
let selectedTag = listItem.label;
|
||||
|
||||
// Uncheck the tag.
|
||||
listItem.checked = false;
|
||||
is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(),
|
||||
"Scroll position did not change");
|
||||
|
||||
// The listbox is rebuilt, so we have to get the new element.
|
||||
let newItem = tagsSelector.selectedItem;
|
||||
isnot(newItem, null, "Valid new listItem found");
|
||||
ok(!newItem.checked, "New listItem is unchecked " + i);
|
||||
is(newItem.label, selectedTag, "Correct tag is still selected");
|
||||
|
||||
// Check the tag.
|
||||
newItem.checked = true;
|
||||
is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(),
|
||||
"Scroll position did not change");
|
||||
}
|
||||
|
||||
// Remove the second bookmark, then nuke some of the tags.
|
||||
yield bs.remove(bm2.guid);
|
||||
|
||||
// Doing this backwords tests more interesting paths.
|
||||
for (let i = tags.length - 1; i >= 0 ; i -= 2) {
|
||||
tagsSelector.selectedIndex = i;
|
||||
let listItem = tagsSelector.selectedItem;
|
||||
isnot(listItem, null, "Valid listItem found");
|
||||
|
||||
tagsSelector.ensureElementIsVisible(listItem);
|
||||
let firstVisibleTag = tags[tagsSelector.getIndexOfFirstVisibleRow()];
|
||||
|
||||
ok(listItem.checked, "Item is checked " + i);
|
||||
let selectedTag = listItem.label;
|
||||
|
||||
// Uncheck the tag.
|
||||
listItem.checked = false;
|
||||
|
||||
// Ensure the first visible tag is still visible in the list.
|
||||
let firstVisibleIndex = tagsSelector.getIndexOfFirstVisibleRow();
|
||||
let lastVisibleIndex = firstVisibleIndex + tagsSelector.getNumberOfVisibleRows() -1;
|
||||
let expectedTagIndex = tags.indexOf(firstVisibleTag);
|
||||
ok(expectedTagIndex >= firstVisibleIndex &&
|
||||
expectedTagIndex <= lastVisibleIndex,
|
||||
"Scroll position is correct");
|
||||
|
||||
// The listbox is rebuilt, so we have to get the new element.
|
||||
let newItem = tagsSelector.selectedItem;
|
||||
isnot(newItem, null, "Valid new listItem found");
|
||||
ok(newItem.checked, "New listItem is checked " + i);
|
||||
is(tagsSelector.selectedItem.label,
|
||||
tags[Math.min(i + 1, tags.length - 2)],
|
||||
"The next tag is now selected");
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
yield bs.remove(bm1.guid);
|
||||
}).then(SimpleTest.finish).catch(alert);
|
||||
}
|
||||
|
||||
function openTagSelector() {
|
||||
// Wait for the tags selector to be open.
|
||||
let promise = new Promise(resolve => {
|
||||
let row = document.getElementById("editBMPanel_tagsSelectorRow");
|
||||
row.addEventListener("DOMAttrModified", function onAttrModified() {
|
||||
row.removeEventListener("DOMAttrModified", onAttrModified);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
// Open the tags selector.
|
||||
document.getElementById("editBMPanel_tagsSelectorExpander").doCommand();
|
||||
|
||||
return promise;
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
|
|
@ -34,163 +34,170 @@
|
|||
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
function runTest()
|
||||
{
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
function checkTagsSelector(aAvailableTags, aCheckedTags) {
|
||||
is(PlacesUtils.tagging.allTags.length, aAvailableTags.length,
|
||||
"tagging service is in sync.");
|
||||
let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
|
||||
let children = tagsSelector.childNodes;
|
||||
is(children.length, aAvailableTags.length,
|
||||
"Found expected number of tags in the tags selector");
|
||||
|
||||
const TEST_URI = NetUtil.newURI("http://www.test.me/");
|
||||
const TEST_URI2 = NetUtil.newURI("http://www.test.again.me/");
|
||||
const TEST_TAG = "test-tag";
|
||||
Array.forEach(children, function (aChild) {
|
||||
let tag = aChild.getAttribute("label");
|
||||
ok(true, "Found tag '" + tag + "' in the selector");
|
||||
ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag");
|
||||
let checked = aChild.getAttribute("checked") == "true";
|
||||
is(checked, aCheckedTags.indexOf(tag) != -1,
|
||||
"Tag is correctly marked");
|
||||
});
|
||||
}
|
||||
|
||||
ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context");
|
||||
function runTest() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// Open the tags selector.
|
||||
document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false;
|
||||
Task.spawn(function* () {
|
||||
const TEST_URI = Services.io.newURI("http://www.test.me/", null, null);
|
||||
const TEST_URI2 = Services.io.newURI("http://www.test.again.me/", null, null);
|
||||
const TEST_TAG = "test-tag";
|
||||
|
||||
function checkTagsSelector(aAvailableTags, aCheckedTags)
|
||||
{
|
||||
is(PlacesUtils.tagging.allTags.length, aAvailableTags.length,
|
||||
"tagging service is in sync.");
|
||||
let tagsSelector = document.getElementById("editBMPanel_tagsSelector");
|
||||
let children = tagsSelector.childNodes;
|
||||
is(children.length, aAvailableTags.length,
|
||||
"Found expected number of tags in the tags selector");
|
||||
Array.forEach(children, function (aChild) {
|
||||
let tag = aChild.getAttribute("label");
|
||||
ok(true, "Found tag '" + tag + "' in the selector");
|
||||
ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag");
|
||||
let checked = aChild.getAttribute("checked") == "true";
|
||||
is(checked, aCheckedTags.indexOf(tag) != -1,
|
||||
"Tag is correctly marked");
|
||||
ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context");
|
||||
|
||||
// Open the tags selector.
|
||||
document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false;
|
||||
|
||||
// Add a bookmark.
|
||||
let bm = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: TEST_URI.spec,
|
||||
title: "test.me"
|
||||
});
|
||||
}
|
||||
|
||||
// Add a bookmark.
|
||||
let itemId = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.unfiledBookmarksFolderId, TEST_URI,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "test.me"
|
||||
);
|
||||
// Init panel.
|
||||
itemId = yield PlacesUtils.promiseItemId(bm.guid);
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
|
||||
// Init panel.
|
||||
gEditItemOverlay.initPanel(itemId);
|
||||
// Add a tag.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
|
||||
// Add a tag.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added tag to a single bookmark");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing a single bookmark shows the added tag");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added tag to a single bookmark");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing a single bookmark shows the added tag");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
// Remove tag.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"The tag has been removed");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing a single bookmark should not show any tag");
|
||||
checkTagsSelector([], []);
|
||||
|
||||
// Remove tag.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"The tag has been removed");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing a single bookmark should not show any tag");
|
||||
checkTagsSelector([], []);
|
||||
// Add a second bookmark.
|
||||
let bm2 = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
title: "test.again.me",
|
||||
url: TEST_URI2.spec
|
||||
});
|
||||
|
||||
// Add a second bookmark.
|
||||
let itemId2 = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.unfiledBookmarksFolderId, TEST_URI2,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "test.again.me"
|
||||
);
|
||||
// Init panel with multiple bookmarks.
|
||||
itemId2 = yield PlacesUtils.promiseItemId(bm2.guid);
|
||||
gEditItemOverlay.initPanel([itemId, itemId2]);
|
||||
|
||||
// Init panel with multiple bookmarks.
|
||||
gEditItemOverlay.initPanel([itemId, itemId2]);
|
||||
// Add a tag to the first bookmark.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added a tag to the first bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
|
||||
// Add a tag to the first bookmark.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added a tag to the first bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
|
||||
// Add a tag to the second bookmark.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
|
||||
"Correctly added a tag to the second bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing multiple bookmarks should show matching tags.");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
// Add a tag to the second bookmark.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
|
||||
"Correctly added a tag to the second bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing multiple bookmarks should show matching tags.");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
|
||||
// Remove tag from the first bookmark.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the first bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
// Remove tag from the first bookmark.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the first bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
|
||||
// Remove tag from the second bookmark.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
|
||||
"Correctly removed tag from the second bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([], []);
|
||||
// Remove tag from the second bookmark.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
|
||||
"Correctly removed tag from the second bookmark.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple bookmarks without matching tags should not show any tag.");
|
||||
checkTagsSelector([], []);
|
||||
|
||||
// Init panel with a nsIURI entry.
|
||||
gEditItemOverlay.initPanel(TEST_URI);
|
||||
// Init panel with a nsIURI entry.
|
||||
gEditItemOverlay.initPanel(TEST_URI);
|
||||
|
||||
// Add a tag.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added tag to the first entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing a single nsIURI entry shows the added tag");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
// Add a tag.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Correctly added tag to the first entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing a single nsIURI entry shows the added tag");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
|
||||
// Remove tag.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the nsIURI entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing a single nsIURI entry should not show any tag");
|
||||
checkTagsSelector([], []);
|
||||
// Remove tag.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the nsIURI entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing a single nsIURI entry should not show any tag");
|
||||
checkTagsSelector([], []);
|
||||
|
||||
// Init panel with multiple nsIURI entries.
|
||||
gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]);
|
||||
// Init panel with multiple nsIURI entries.
|
||||
gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]);
|
||||
|
||||
// Add a tag to the first entry.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Tag correctly added.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
// Add a tag to the first entry.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG,
|
||||
"Tag correctly added.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
|
||||
// Add a tag to the second entry.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
|
||||
"Tag correctly added.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing multiple nsIURIs should show matching tags");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
// Add a tag to the second entry.
|
||||
PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG,
|
||||
"Tag correctly added.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG,
|
||||
"Editing multiple nsIURIs should show matching tags");
|
||||
checkTagsSelector([TEST_TAG], [TEST_TAG]);
|
||||
|
||||
// Remove tag from the first entry.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the first entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
// Remove tag from the first entry.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined,
|
||||
"Correctly removed tag from the first entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([TEST_TAG], []);
|
||||
|
||||
// Remove tag from the second entry.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
|
||||
"Correctly removed tag from the second entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([], []);
|
||||
|
||||
// Cleanup.
|
||||
PlacesUtils.bookmarks.removeFolderChildren(
|
||||
PlacesUtils.unfiledBookmarksFolderId
|
||||
);
|
||||
// Remove tag from the second entry.
|
||||
PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]);
|
||||
is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined,
|
||||
"Correctly removed tag from the second entry.");
|
||||
is(document.getElementById("editBMPanel_tagsField").value, "",
|
||||
"Editing multiple nsIURIs without matching tags should not show any tag.");
|
||||
checkTagsSelector([], []);
|
||||
|
||||
// Cleanup.
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
yield PlacesUtils.bookmarks.remove(bm2.guid);
|
||||
}).then(SimpleTest.finish);
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
|
|
@ -38,29 +38,49 @@
|
|||
*/
|
||||
|
||||
function runTest() {
|
||||
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
|
||||
NetUtil.newURI("place:folder=UNFILED_BOOKMARKS"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
"shortcut");
|
||||
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
|
||||
NetUtil.newURI("place:folder=UNFILED_BOOKMARKS&maxResults=10"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
"query");
|
||||
let folderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
|
||||
"folder",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
let itemId = PlacesUtils.bookmarks.insertBookmark(folderId,
|
||||
NetUtil.newURI("http://www.mozilla.org/"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
"bookmark");
|
||||
// Setup the places tree contents.
|
||||
var tree = document.getElementById("tree");
|
||||
tree.place = "place:folder=UNFILED_BOOKMARKS";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// Select the last bookmark.
|
||||
tree.selectItems([itemId]);
|
||||
is (tree.selectedNode.itemId, itemId, "The right node was selected");
|
||||
Task.spawn(function* () {
|
||||
yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "place:folder=UNFILED_BOOKMARKS",
|
||||
title: "shortcut"
|
||||
});
|
||||
|
||||
yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "place:folder=UNFILED_BOOKMARKS&maxResults=10",
|
||||
title: "query"
|
||||
});
|
||||
|
||||
let folder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER,
|
||||
title: "folder"
|
||||
});
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: folder.guid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://www.mozilla.org/",
|
||||
title: "bookmark"
|
||||
});
|
||||
|
||||
// Setup the places tree contents.
|
||||
let tree = document.getElementById("tree");
|
||||
tree.place = "place:folder=UNFILED_BOOKMARKS";
|
||||
|
||||
// Select the last bookmark.
|
||||
let itemId = yield PlacesUtils.promiseItemId(bm.guid);
|
||||
tree.selectItems([itemId]);
|
||||
is (tree.selectedNode.itemId, itemId, "The right node was selected");
|
||||
}).then(SimpleTest.finish);
|
||||
}
|
||||
|
||||
]]></script>
|
||||
</window>
|
||||
|
|
|
@ -50,62 +50,69 @@
|
|||
* Ensures that date in places treeviews is correctly formatted.
|
||||
*/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function runTest() {
|
||||
// The mochitest page is added to history.
|
||||
PlacesTestUtils.clearHistory().then(continue_test);
|
||||
}
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function continue_test() {
|
||||
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||
let ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||
getService(Ci.nsIScriptableDateFormat);
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
return Services.io.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
var midnight = new Date();
|
||||
midnight.setHours(0);
|
||||
midnight.setMinutes(0);
|
||||
midnight.setSeconds(0);
|
||||
midnight.setMilliseconds(0);
|
||||
Task.spawn(function* () {
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
|
||||
let midnight = new Date();
|
||||
midnight.setHours(0);
|
||||
midnight.setMinutes(0);
|
||||
midnight.setSeconds(0);
|
||||
midnight.setMilliseconds(0);
|
||||
|
||||
// Add a visit 1ms before midnight, a visit at midnight, and
|
||||
// a visit 1ms after midnight.
|
||||
yield new Promise(resolve => addVisits(
|
||||
[{uri: uri("http://before.midnight.com/"),
|
||||
visitDate: (midnight.getTime() - 1) * 1000,
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED},
|
||||
{uri: uri("http://at.midnight.com/"),
|
||||
visitDate: (midnight.getTime()) * 1000,
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED},
|
||||
{uri: uri("http://after.midnight.com/"),
|
||||
visitDate: (midnight.getTime() + 1) * 1000,
|
||||
transition: PlacesUtils.history.TRANSITION_TYPED}],
|
||||
resolve));
|
||||
|
||||
function addVisitsCallback() {
|
||||
// add a bookmark to the midnight visit
|
||||
var itemId = bs.insertBookmark(bs.toolbarFolder,
|
||||
uri("http://at.midnight.com/"),
|
||||
bs.DEFAULT_INDEX,
|
||||
"A bookmark at midnight");
|
||||
let bm = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
url: "http://at.midnight.com/",
|
||||
title: "A bookmark at midnight",
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK
|
||||
});
|
||||
|
||||
// Make a history query.
|
||||
var query = hs.getNewQuery();
|
||||
var opts = hs.getNewQueryOptions();
|
||||
var queryURI = hs.queriesToQueryString([query], 1, opts);
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let opts = PlacesUtils.history.getNewQueryOptions();
|
||||
let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
|
||||
|
||||
// Setup the places tree contents.
|
||||
var tree = document.getElementById("tree");
|
||||
let tree = document.getElementById("tree");
|
||||
tree.place = queryURI;
|
||||
|
||||
// loop through the rows and check formatting
|
||||
var treeView = tree.view;
|
||||
var rc = treeView.rowCount;
|
||||
let treeView = tree.view;
|
||||
let rc = treeView.rowCount;
|
||||
ok(rc >= 3, "Rows found");
|
||||
var columns = tree.columns;
|
||||
let columns = tree.columns;
|
||||
ok(columns.count > 0, "Columns found");
|
||||
for (var r = 0; r < rc; r++) {
|
||||
var node = treeView.nodeForTreeIndex(r);
|
||||
for (let r = 0; r < rc; r++) {
|
||||
let node = treeView.nodeForTreeIndex(r);
|
||||
ok(node, "Places node found");
|
||||
for (var ci = 0; ci < columns.count; ci++) {
|
||||
var c = columns.getColumnAt(ci);
|
||||
var text = treeView.getCellText(r, c);
|
||||
for (let ci = 0; ci < columns.count; ci++) {
|
||||
let c = columns.getColumnAt(ci);
|
||||
let text = treeView.getCellText(r, c);
|
||||
switch (c.element.getAttribute("anonid")) {
|
||||
case "title":
|
||||
// The title can differ, we did not set any title so we would
|
||||
|
@ -118,9 +125,9 @@
|
|||
is(text, node.uri, "Uri is correct");
|
||||
break;
|
||||
case "date":
|
||||
var timeObj = new Date(node.time / 1000);
|
||||
let timeObj = new Date(node.time / 1000);
|
||||
// Default is short date format.
|
||||
var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
|
||||
let dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
|
||||
// For today's visits we don't show date portion.
|
||||
if (node.uri == "http://at.midnight.com/" ||
|
||||
node.uri == "http://after.midnight.com/")
|
||||
|
@ -132,7 +139,7 @@
|
|||
// a redirecting uri could be put in the tree while we test.
|
||||
break;
|
||||
}
|
||||
var timeStr = ds.FormatDateTime("", dateFormat,
|
||||
let timeStr = ds.FormatDateTime("", dateFormat,
|
||||
Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
|
||||
timeObj.getFullYear(), timeObj.getMonth() + 1,
|
||||
timeObj.getDate(), timeObj.getHours(),
|
||||
|
@ -146,26 +153,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
bs.removeItem(itemId);
|
||||
PlacesTestUtils.clearHistory().then(SimpleTest.finish);
|
||||
}
|
||||
|
||||
// Add a visit 1ms before midnight, a visit at midnight, and
|
||||
// a visit 1ms after midnight.
|
||||
addVisits(
|
||||
[{uri: uri("http://before.midnight.com/"),
|
||||
visitDate: (midnight.getTime() - 1) * 1000,
|
||||
transition: hs.TRANSITION_TYPED},
|
||||
{uri: uri("http://at.midnight.com/"),
|
||||
visitDate: (midnight.getTime()) * 1000,
|
||||
transition: hs.TRANSITION_TYPED},
|
||||
{uri: uri("http://after.midnight.com/"),
|
||||
visitDate: (midnight.getTime() + 1) * 1000,
|
||||
transition: hs.TRANSITION_TYPED}],
|
||||
addVisitsCallback);
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
}).then(SimpleTest.finish);
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
||||
|
|
Загрузка…
Ссылка в новой задаче