зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1366231 - Implement History.hasVisits as a wrapper of asyncHistory.isURIVisited; r=mak
Tests for the wrapper implementation added in test_hasVisits.js in toolkit/components/places/tests/history. MozReview-Commit-ID: KEW2bDTSWVY --HG-- extra : rebase_source : 453aa3dc1503c2595ed0161ad7dc350bec09111e
This commit is contained in:
Родитель
bc5b6f4ff4
Коммит
37d8c6f7e0
|
@ -514,21 +514,24 @@ this.History = Object.freeze({
|
|||
/**
|
||||
* Determine if a page has been visited.
|
||||
*
|
||||
* @param pages: (URL or nsIURI)
|
||||
* The full URI of the page.
|
||||
* or (string)
|
||||
* The full URI of the page or the GUID of the page.
|
||||
*
|
||||
* @param guidOrURI: (string) or (URL, nsIURI or href)
|
||||
* Either the full URI of the page or the GUID of the page.
|
||||
* @return (Promise)
|
||||
* A promise resolved once the operation is complete.
|
||||
* @resolve (bool)
|
||||
* `true` if the page has been visited, `false` otherwise.
|
||||
* @throws (Error)
|
||||
* If `pages` has an unexpected type or if a string provided
|
||||
* If `guidOrURI` has an unexpected type or if a string provided
|
||||
* is neither not a valid GUID nor a valid URI.
|
||||
*/
|
||||
hasVisits(page, onResult) {
|
||||
throw new Error("Method not implemented");
|
||||
hasVisits(guidOrURI) {
|
||||
guidOrURI = PlacesUtils.normalizeToURLOrGUID(guidOrURI);
|
||||
|
||||
return new Promise(resolve => {
|
||||
PlacesUtils.asyncHistory.isURIVisited(guidOrURI, (aURI, aIsVisited) => {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Tests for `History.hasVisits` as implemented in History.jsm
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function test_has_visits_error_cases() {
|
||||
Assert.throws(
|
||||
() => PlacesUtils.history.hasVisits(),
|
||||
/TypeError: Invalid url or guid: undefined/,
|
||||
"passing a null into History.hasVisits should throw a TypeError"
|
||||
);
|
||||
Assert.throws(
|
||||
() => PlacesUtils.history.hasVisits(1),
|
||||
/TypeError: Invalid url or guid: 1/,
|
||||
"passing an invalid url into History.hasVisits should throw a TypeError"
|
||||
);
|
||||
Assert.throws(
|
||||
() => PlacesUtils.history.hasVisits({}),
|
||||
/TypeError: Invalid url or guid: [object Object]/,
|
||||
`passing an invalid (not of type URI or nsIURI) object to History.hasVisits
|
||||
should throw a TypeError`
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_history_has_visits() {
|
||||
const TEST_URL = "http://mozilla.com/";
|
||||
await PlacesTestUtils.clearHistory();
|
||||
Assert.equal(await PlacesUtils.history.hasVisits(TEST_URL), false,
|
||||
"Test Url should not be in history.");
|
||||
await PlacesTestUtils.addVisits(TEST_URL);
|
||||
Assert.equal(await PlacesUtils.history.hasVisits(TEST_URL), true,
|
||||
"Test Url should be in history.");
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
Загрузка…
Ссылка в новой задаче