зеркало из https://github.com/mozilla/gecko-dev.git
Bug 739217 - Part 5: Toolkit replacements of synchronous isVisited with asynchronous isURIVisited. r=mak
This commit is contained in:
Родитель
9eee2578dd
Коммит
df4f6bd855
|
@ -38,11 +38,10 @@ function test() {
|
|||
}
|
||||
|
||||
function checkPlaces(aWindow, aIsPrivate, aCallback) {
|
||||
// History items should be retrievable by query
|
||||
Task.spawn(checkHistoryItems).then(function() {
|
||||
// Updates the place items count
|
||||
placeItemsCount = getPlacesItemsCount(aWindow);
|
||||
// History items should be retrievable by query
|
||||
checkHistoryItems(aWindow);
|
||||
|
||||
// Create Bookmark
|
||||
let bookmarkTitle = "title " + windowCount;
|
||||
let bookmarkKeyword = "keyword " + windowCount;
|
||||
|
@ -50,15 +49,16 @@ function test() {
|
|||
createBookmark(aWindow, bookmarkUri, bookmarkTitle, bookmarkKeyword);
|
||||
placeItemsCount++;
|
||||
windowCount++;
|
||||
ok(aWindow.PlacesUtils.bookmarks.isBookmarked(bookmarkUri),
|
||||
ok(PlacesUtils.bookmarks.isBookmarked(bookmarkUri),
|
||||
"Bookmark should be bookmarked, data should be retrievable");
|
||||
is(bookmarkKeyword, aWindow.PlacesUtils.bookmarks.getKeywordForURI(bookmarkUri),
|
||||
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");
|
||||
|
||||
aCallback();
|
||||
});
|
||||
}
|
||||
|
||||
clearHistory(function() {
|
||||
|
@ -141,15 +141,16 @@ function fillHistoryVisitedURI(aWin, aCallback) {
|
|||
aWin, aCallback);
|
||||
}
|
||||
|
||||
function checkHistoryItems(aWin) {
|
||||
visitedURIs.forEach(function (visitedUri) {
|
||||
ok(aWin.PlacesUtils.bhistory.isVisited(NetUtil.newURI(visitedUri)), "");
|
||||
function checkHistoryItems() {
|
||||
for (let i = 0; i < visitedURIs.length; i++) {
|
||||
let visitedUri = visitedURIs[i];
|
||||
ok((yield promiseIsURIVisited(NetUtil.newURI(visitedUri))), "");
|
||||
if (/embed/.test(visitedUri)) {
|
||||
is(!!pageInDatabase(visitedUri), false, "Check if URI is in database");
|
||||
} else {
|
||||
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",
|
||||
"resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
/**
|
||||
* Allows waiting for an observer notification once.
|
||||
|
@ -346,3 +348,22 @@ function whenNewWindowLoaded(aOptions, aCallback) {
|
|||
aCallback(win);
|
||||
}, 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.
|
||||
*
|
||||
* @param aURI
|
||||
* The URI.
|
||||
*
|
||||
* @param aURI The URI.
|
||||
* @return {Promise}
|
||||
* @resolves When the check has been added successfully.
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aURI)
|
||||
{
|
||||
function promiseIsURIVisited(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
let history = Cc["@mozilla.org/browser/history;1"]
|
||||
.getService(Ci.mozIAsyncHistory);
|
||||
history.isURIVisited(aURI, function(aURI, aIsVisited) {
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@ add_task(function test_execute()
|
|||
|
||||
// check that all links are marked as visited
|
||||
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) {
|
||||
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
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -17,7 +17,6 @@ const FINISHED_MAINTENANCE_NOTIFICATION_TOPIC = "places-maintenance-finished";
|
|||
|
||||
// Get services and database connection
|
||||
let hs = PlacesUtils.history;
|
||||
let bh = PlacesUtils.bhistory;
|
||||
let bs = PlacesUtils.bookmarks;
|
||||
let ts = PlacesUtils.tagging;
|
||||
let as = PlacesUtils.annotations;
|
||||
|
@ -1289,8 +1288,10 @@ tests.push({
|
|||
|
||||
asyncCheck: function (aCallback) {
|
||||
// Check that all items are correct
|
||||
do_check_true(bh.isVisited(this._uri1));
|
||||
do_check_true(bh.isVisited(this._uri2));
|
||||
PlacesUtils.asyncHistory.isURIVisited(this._uri1, function(aURI, aIsVisited) {
|
||||
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.getItemIndex(this._folderId), 0);
|
||||
|
@ -1307,6 +1308,8 @@ tests.push({
|
|||
do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI));
|
||||
aCallback();
|
||||
});
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -46,15 +46,16 @@ var tests = [
|
|||
}
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return true.");
|
||||
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return true.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_true(aIsVisited);
|
||||
|
||||
promiseAsyncUpdates().then(function () {
|
||||
print("Frecency should be positive.")
|
||||
do_check_true(frecencyForUrl(TEST_URI) > 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -98,15 +99,16 @@ var tests = [
|
|||
}
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return true.");
|
||||
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return true.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_true(aIsVisited);
|
||||
|
||||
promiseAsyncUpdates().then(function () {
|
||||
print("Frecency should be positive.")
|
||||
do_check_true(frecencyForUrl(TEST_URI) > 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -143,15 +145,16 @@ var tests = [
|
|||
}
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return true.");
|
||||
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return true.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_true(aIsVisited);
|
||||
|
||||
promiseAsyncUpdates().then(function () {
|
||||
print("Frecency should be positive.")
|
||||
do_check_true(frecencyForUrl(TEST_URI) > 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -195,15 +198,16 @@ var tests = [
|
|||
}
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return true.");
|
||||
do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return true.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_true(aIsVisited);
|
||||
|
||||
promiseAsyncUpdates().then(function () {
|
||||
print("Frecency should be positive.")
|
||||
do_check_true(frecencyForUrl(TEST_URI) > 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -235,10 +239,11 @@ var tests = [
|
|||
do_check_eq(resultRoot.childCount, 0);
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return false.");
|
||||
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return false.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_false(aIsVisited);
|
||||
run_next_test();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -270,15 +275,16 @@ var tests = [
|
|||
do_check_eq(resultRoot.childCount, 0);
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return false.");
|
||||
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(PLACE_URI));
|
||||
print("asyncHistory.isURIVisited should return false.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(PLACE_URI, function(aURI, aIsVisited) {
|
||||
do_check_false(aIsVisited);
|
||||
|
||||
promiseAsyncUpdates().then(function () {
|
||||
print("Frecency should be zero.")
|
||||
do_check_eq(frecencyForUrl(PLACE_URL), 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -317,9 +323,9 @@ var tests = [
|
|||
do_check_eq(resultRoot.childCount, 0);
|
||||
resultRoot.containerOpen = false;
|
||||
|
||||
print("nsIGlobalHistory2.isVisited should return false.");
|
||||
do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2).
|
||||
isVisited(TEST_URI));
|
||||
print("asyncHistory.isURIVisited should return false.");
|
||||
PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) {
|
||||
do_check_false(aIsVisited);
|
||||
|
||||
print("nsINavBookmarksService.isBookmarked should return true.");
|
||||
do_check_true(bmsvc.isBookmarked(TEST_URI));
|
||||
|
@ -329,6 +335,7 @@ var tests = [
|
|||
do_check_true(frecencyForUrl(TEST_URI) < 0);
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче