Bug 739217 - Part 5: Toolkit replacements of synchronous isVisited with asynchronous isURIVisited. r=mak

This commit is contained in:
Andres Hernandez 2013-02-04 10:58:54 -06:00
Родитель 9eee2578dd
Коммит df4f6bd855
7 изменённых файлов: 594 добавлений и 527 удалений

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

@ -38,27 +38,27 @@ function test() {
} }
function checkPlaces(aWindow, aIsPrivate, aCallback) { function checkPlaces(aWindow, aIsPrivate, aCallback) {
// Updates the place items count
placeItemsCount = getPlacesItemsCount(aWindow);
// History items should be retrievable by query // History items should be retrievable by query
checkHistoryItems(aWindow); Task.spawn(checkHistoryItems).then(function() {
// Updates the place items count
placeItemsCount = getPlacesItemsCount(aWindow);
// Create Bookmark
let bookmarkTitle = "title " + windowCount;
let bookmarkKeyword = "keyword " + windowCount;
let bookmarkUri = NetUtil.newURI("http://test-a-" + windowCount + ".com/");
createBookmark(aWindow, bookmarkUri, bookmarkTitle, bookmarkKeyword);
placeItemsCount++;
windowCount++;
ok(PlacesUtils.bookmarks.isBookmarked(bookmarkUri),
"Bookmark should be bookmarked, data should be retrievable");
is(bookmarkKeyword, PlacesUtils.bookmarks.getKeywordForURI(bookmarkUri),
"Check bookmark uri keyword");
is(getPlacesItemsCount(aWindow), placeItemsCount,
"Check the new bookmark items count");
is(isBookmarkAltered(aWindow), false, "Check if bookmark has been visited");
// Create Bookmark aCallback();
let bookmarkTitle = "title " + windowCount; });
let bookmarkKeyword = "keyword " + windowCount;
let bookmarkUri = NetUtil.newURI("http://test-a-" + windowCount + ".com/");
createBookmark(aWindow, bookmarkUri, bookmarkTitle, bookmarkKeyword);
placeItemsCount++;
windowCount++;
ok(aWindow.PlacesUtils.bookmarks.isBookmarked(bookmarkUri),
"Bookmark should be bookmarked, data should be retrievable");
is(bookmarkKeyword, aWindow.PlacesUtils.bookmarks.getKeywordForURI(bookmarkUri),
"Check bookmark uri keyword");
is(getPlacesItemsCount(aWindow), placeItemsCount,
"Check the new bookmark items count");
is(isBookmarkAltered(aWindow), false, "Check if bookmark has been visited");
aCallback();
} }
clearHistory(function() { clearHistory(function() {
@ -141,15 +141,16 @@ function fillHistoryVisitedURI(aWin, aCallback) {
aWin, aCallback); aWin, aCallback);
} }
function checkHistoryItems(aWin) { function checkHistoryItems() {
visitedURIs.forEach(function (visitedUri) { for (let i = 0; i < visitedURIs.length; i++) {
ok(aWin.PlacesUtils.bhistory.isVisited(NetUtil.newURI(visitedUri)), ""); let visitedUri = visitedURIs[i];
ok((yield promiseIsURIVisited(NetUtil.newURI(visitedUri))), "");
if (/embed/.test(visitedUri)) { if (/embed/.test(visitedUri)) {
is(!!pageInDatabase(visitedUri), false, "Check if URI is in database"); is(!!pageInDatabase(visitedUri), false, "Check if URI is in database");
} else { } else {
ok(!!pageInDatabase(visitedUri), "Check if URI is in database"); ok(!!pageInDatabase(visitedUri), "Check if URI is in database");
} }
}); }
} }
/** /**

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

@ -7,6 +7,8 @@ Components.utils.import("resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise", XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/commonjs/sdk/core/promise.js"); "resource://gre/modules/commonjs/sdk/core/promise.js");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
/** /**
* Allows waiting for an observer notification once. * Allows waiting for an observer notification once.
@ -346,3 +348,22 @@ function whenNewWindowLoaded(aOptions, aCallback) {
aCallback(win); aCallback(win);
}, false); }, false);
} }
/**
* Asynchronously check a url is visited.
*
* @param aURI The URI.
* @param aExpectedValue The expected value.
* @return {Promise}
* @resolves When the check has been added successfully.
* @rejects JavaScript exception.
*/
function promiseIsURIVisited(aURI, aExpectedValue) {
let deferred = Promise.defer();
PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) {
deferred.resolve(aIsVisited);
});
return deferred.promise;
}

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

@ -915,19 +915,15 @@ function promiseAddVisits(aPlaceInfo)
/** /**
* Asynchronously check a url is visited. * Asynchronously check a url is visited.
* *
* @param aURI * @param aURI The URI.
* The URI.
*
* @return {Promise} * @return {Promise}
* @resolves When the check has been added successfully. * @resolves When the check has been added successfully.
* @rejects JavaScript exception. * @rejects JavaScript exception.
*/ */
function promiseIsURIVisited(aURI) function promiseIsURIVisited(aURI) {
{
let deferred = Promise.defer(); let deferred = Promise.defer();
let history = Cc["@mozilla.org/browser/history;1"]
.getService(Ci.mozIAsyncHistory); PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) {
history.isURIVisited(aURI, function(aURI, aIsVisited) {
deferred.resolve(aIsVisited); deferred.resolve(aIsVisited);
}); });

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

@ -43,10 +43,10 @@ add_task(function test_execute()
// check that all links are marked as visited // check that all links are marked as visited
count_visited_URIs.forEach(function (visited_uri) { count_visited_URIs.forEach(function (visited_uri) {
do_check_eq(PlacesUtils.bhistory.isVisited(uri(visited_uri)), true); do_check_true(yield promiseIsURIVisited(uri(visited_uri)));
}); });
notcount_visited_URIs.forEach(function (visited_uri) { notcount_visited_URIs.forEach(function (visited_uri) {
do_check_eq(PlacesUtils.bhistory.isVisited(uri(visited_uri)), true); do_check_true(yield promiseIsURIVisited(uri(visited_uri)));
}); });
// check that visit_count does not take in count embed and downloads // check that visit_count does not take in count embed and downloads

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -17,7 +17,6 @@ const FINISHED_MAINTENANCE_NOTIFICATION_TOPIC = "places-maintenance-finished";
// Get services and database connection // Get services and database connection
let hs = PlacesUtils.history; let hs = PlacesUtils.history;
let bh = PlacesUtils.bhistory;
let bs = PlacesUtils.bookmarks; let bs = PlacesUtils.bookmarks;
let ts = PlacesUtils.tagging; let ts = PlacesUtils.tagging;
let as = PlacesUtils.annotations; let as = PlacesUtils.annotations;
@ -1289,24 +1288,28 @@ tests.push({
asyncCheck: function (aCallback) { asyncCheck: function (aCallback) {
// Check that all items are correct // Check that all items are correct
do_check_true(bh.isVisited(this._uri1)); PlacesUtils.asyncHistory.isURIVisited(this._uri1, function(aURI, aIsVisited) {
do_check_true(bh.isVisited(this._uri2)); do_check_true(aIsVisited);
PlacesUtils.asyncHistory.isURIVisited(this._uri2, function(aURI, aIsVisited) {
do_check_true(aIsVisited);
do_check_eq(bs.getBookmarkURI(this._bookmarkId).spec, this._uri1.spec); do_check_eq(bs.getBookmarkURI(this._bookmarkId).spec, this._uri1.spec);
do_check_eq(bs.getItemIndex(this._folderId), 0); do_check_eq(bs.getItemIndex(this._folderId), 0);
do_check_eq(bs.getItemType(this._folderId), bs.TYPE_FOLDER); do_check_eq(bs.getItemType(this._folderId), bs.TYPE_FOLDER);
do_check_eq(bs.getItemType(this._separatorId), bs.TYPE_SEPARATOR); do_check_eq(bs.getItemType(this._separatorId), bs.TYPE_SEPARATOR);
do_check_eq(ts.getTagsForURI(this._uri1).length, 1); do_check_eq(ts.getTagsForURI(this._uri1).length, 1);
do_check_eq(bs.getKeywordForBookmark(this._bookmarkId), "testkeyword"); do_check_eq(bs.getKeywordForBookmark(this._bookmarkId), "testkeyword");
do_check_eq(as.getPageAnnotation(this._uri2, "anno"), "anno"); do_check_eq(as.getPageAnnotation(this._uri2, "anno"), "anno");
do_check_eq(as.getItemAnnotation(this._bookmarkId, "anno"), "anno"); do_check_eq(as.getItemAnnotation(this._bookmarkId, "anno"), "anno");
fs.getFaviconURLForPage(this._uri2, function (aFaviconURI) { fs.getFaviconURLForPage(this._uri2, function (aFaviconURI) {
do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI)); do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI));
aCallback(); aCallback();
}); });
}.bind(this));
}.bind(this));
} }
}); });

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

@ -46,14 +46,15 @@ var tests = [
} }
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return true."); print("asyncHistory.isURIVisited should return true.");
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_true(aIsVisited);
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be positive.") print("Frecency should be positive.")
do_check_true(frecencyForUrl(TEST_URI) > 0); do_check_true(frecencyForUrl(TEST_URI) > 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },
@ -98,14 +99,15 @@ var tests = [
} }
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return true."); print("asyncHistory.isURIVisited should return true.");
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_true(aIsVisited);
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be positive.") print("Frecency should be positive.")
do_check_true(frecencyForUrl(TEST_URI) > 0); do_check_true(frecencyForUrl(TEST_URI) > 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },
@ -143,14 +145,15 @@ var tests = [
} }
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return true."); print("asyncHistory.isURIVisited should return true.");
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_true(aIsVisited);
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be positive.") print("Frecency should be positive.")
do_check_true(frecencyForUrl(TEST_URI) > 0); do_check_true(frecencyForUrl(TEST_URI) > 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },
@ -195,14 +198,15 @@ var tests = [
} }
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return true."); print("asyncHistory.isURIVisited should return true.");
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_true(aIsVisited);
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be positive.") print("Frecency should be positive.")
do_check_true(frecencyForUrl(TEST_URI) > 0); do_check_true(frecencyForUrl(TEST_URI) > 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },
@ -235,10 +239,11 @@ var tests = [
do_check_eq(resultRoot.childCount, 0); do_check_eq(resultRoot.childCount, 0);
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return false."); print("asyncHistory.isURIVisited should return false.");
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_false(aIsVisited);
run_next_test(); run_next_test();
});
} }
}, },
@ -270,14 +275,15 @@ var tests = [
do_check_eq(resultRoot.childCount, 0); do_check_eq(resultRoot.childCount, 0);
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return false."); print("asyncHistory.isURIVisited should return false.");
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(PLACE_URI, function(aURI, aIsVisited) {
isVisited(PLACE_URI)); do_check_false(aIsVisited);
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be zero.") print("Frecency should be zero.")
do_check_eq(frecencyForUrl(PLACE_URL), 0); do_check_eq(frecencyForUrl(PLACE_URL), 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },
@ -317,17 +323,18 @@ var tests = [
do_check_eq(resultRoot.childCount, 0); do_check_eq(resultRoot.childCount, 0);
resultRoot.containerOpen = false; resultRoot.containerOpen = false;
print("nsIGlobalHistory2.isVisited should return false."); print("asyncHistory.isURIVisited should return false.");
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
isVisited(TEST_URI)); do_check_false(aIsVisited);
print("nsINavBookmarksService.isBookmarked should return true."); print("nsINavBookmarksService.isBookmarked should return true.");
do_check_true(bmsvc.isBookmarked(TEST_URI)); do_check_true(bmsvc.isBookmarked(TEST_URI));
promiseAsyncUpdates().then(function () { promiseAsyncUpdates().then(function () {
print("Frecency should be negative.") print("Frecency should be negative.")
do_check_true(frecencyForUrl(TEST_URI) < 0); do_check_true(frecencyForUrl(TEST_URI) < 0);
run_next_test(); run_next_test();
});
}); });
} }
}, },