Skip to content

Instantly share code, notes, and snippets.

@xtroncode
Created May 26, 2017 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtroncode/78de9a9cf5f6d23cbf9542e16a424874 to your computer and use it in GitHub Desktop.
Save xtroncode/78de9a9cf5f6d23cbf9542e16a424874 to your computer and use it in GitHub Desktop.
Bugzilla id=1366231
/**
* 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.
*
* @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
* is neither not a valid GUID nor a valid URI.
*/
hasVisits(page) {
let uri = PlacesUtils.normalizeToURLOrGUID(page);
return new Promise((resolve,reject)=>{
PlacesUtils.asyncHistory.isURIVisited(uri,{
isVisited:(aURI,aIsVisited)=>{
resolve(aIsVisited);
}
});
})
}
/* 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/";
//Check for hasVisits should resolve to false
//then insert a pageinfo using History.insert
//then check for hasVisits should resolve to true
//then clearHistory using PlacesTestUtils.clearHistory();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment