Bug 752218 - Replace usage of AddURI with updatePlaces. r=mak

This commit is contained in:
Raymond Lee 2013-01-17 10:28:26 +08:00
Родитель ecb5e3e307
Коммит b8ddec986c
5 изменённых файлов: 62 добавлений и 60 удалений

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

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

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

@ -11,8 +11,6 @@ function run_test()
add_task(function test_execute()
{
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var testURI = uri("wyciwyg://nodontjudgeabookbyitscover");
try
@ -22,9 +20,4 @@ add_task(function test_execute()
} catch (ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
// Adding wyciwyg URIs should raise NS_ERROR_ILLEGAL_VALUE.
}
// test codepath of docshell caller
histsvc.QueryInterface(Ci.nsIGlobalHistory2);
placeID = histsvc.addURI(testURI, false, false, null);
do_check_false(placeID > 0);
});

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

@ -7,8 +7,6 @@
// Get history services
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var gh = histsvc.QueryInterface(Ci.nsIGlobalHistory2);
var bh = histsvc.QueryInterface(Ci.nsIBrowserHistory);
/**
* Checks to see that a URI is in the database.

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

@ -4,45 +4,36 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get history service
try {
var gh = Cc["@mozilla.org/browser/global-history;2"].
getService(Ci.nsIGlobalHistory2);
} catch(ex) {
do_throw("Could not get the global history service\n");
}
function add_uri_to_history(aURI, aCheckForGuid) {
var referrer = uri("about:blank");
gh.addURI(aURI,
false, // not redirect
true, // top level
referrer);
if (aCheckForGuid === undefined) {
do_check_guid_for_uri(aURI);
}
function run_test()
{
run_next_test();
}
// main
function run_test() {
add_task(function test_execute()
{
var referrer = uri("about:blank");
// add a http:// uri
var uri1 = uri("http://mozilla.com");
add_uri_to_history(uri1);
do_check_true(gh.isVisited(uri1));
yield promiseAddVisits({uri: uri1, referrer: referrer});
do_check_guid_for_uri(uri1);
do_check_true(yield promiseIsURIVisited(uri1));
// add a https:// uri
var uri2 = uri("https://etrade.com");
add_uri_to_history(uri2);
do_check_true(gh.isVisited(uri2));
yield promiseAddVisits({uri: uri2, referrer: referrer});
do_check_guid_for_uri(uri2);
do_check_true(yield promiseIsURIVisited(uri2));
// add a ftp:// uri
var uri3 = uri("ftp://ftp.mozilla.org");
add_uri_to_history(uri3);
do_check_true(gh.isVisited(uri3));
yield promiseAddVisits({uri: uri3, referrer: referrer});
do_check_guid_for_uri(uri3);
do_check_true(yield promiseIsURIVisited(uri3));
// check if a nonexistent uri is visited
var uri4 = uri("http://foobarcheese.com");
do_check_false(gh.isVisited(uri4));
do_check_false(yield promiseIsURIVisited(uri4));
// check that certain schemes never show up as visited
// even if we attempt to add them to history
@ -60,7 +51,7 @@ function run_test() {
"wyciwyg:/0/http://mozilla.org",
"javascript:alert('hello wolrd!');",
];
URLS.forEach(function(currentURL) {
for (let currentURL of URLS) {
try {
var cantAddUri = uri(currentURL);
}
@ -71,8 +62,13 @@ function run_test() {
do_log_info("Could not construct URI for '" + currentURL + "'; ignoring");
}
if (cantAddUri) {
add_uri_to_history(cantAddUri, false);
do_check_false(gh.isVisited(cantAddUri));
try {
yield promiseAddVisits({uri: cantAddUri, referrer: referrer});
do_throw("Should have generated an exception.");
} catch(ex if ex && ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
}
do_check_false(yield promiseIsURIVisited(cantAddUri));
}
});
}
}
});

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

@ -4,13 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get global history service
try {
var gh = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
} catch(ex) {
do_throw("Could not get global history service\n");
}
// Get history service
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
@ -18,13 +11,6 @@ try {
do_throw("Could not get history service\n");
}
function add_uri_to_history(aURI) {
gh.addURI(aURI,
false, // not redirect
true, // top level
null); // no referrer, so that we'll use the markPageAs hint
}
var gVisits = [{url: "http://www.mozilla.com/",
transition: histsvc.TRANSITION_TYPED},
{url: "http://www.google.com/",
@ -32,22 +18,28 @@ var gVisits = [{url: "http://www.mozilla.com/",
{url: "http://www.espn.com/",
transition: histsvc.TRANSITION_LINK}];
// main
function run_test() {
function run_test()
{
run_next_test();
}
add_task(function test_execute()
{
for each (var visit in gVisits) {
if (visit.transition == histsvc.TRANSITION_TYPED)
gh.markPageAsTyped(uri(visit.url));
histsvc.markPageAsTyped(uri(visit.url));
else if (visit.transition == histsvc.TRANSITION_BOOKMARK)
gh.markPageAsFollowedBookmark(uri(visit.url))
histsvc.markPageAsFollowedBookmark(uri(visit.url))
else {
// because it is a top level visit with no referrer,
// it will result in TRANSITION_LINK
}
add_uri_to_history(uri(visit.url));
yield promiseAddVisits({uri: uri(visit.url),
transition: visit.transition});
}
do_test_pending();
}
});
// create and add history observer
var observer = {