summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/favicons
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/places/tests/favicons')
-rw-r--r--toolkit/components/places/tests/favicons/head_favicons.js11
-rw-r--r--toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js60
-rw-r--r--toolkit/components/places/tests/favicons/test_page-icon_protocol.js62
-rw-r--r--toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js16
4 files changed, 134 insertions, 15 deletions
diff --git a/toolkit/components/places/tests/favicons/head_favicons.js b/toolkit/components/places/tests/favicons/head_favicons.js
index d8109c66e0..afd2c4924f 100644
--- a/toolkit/components/places/tests/favicons/head_favicons.js
+++ b/toolkit/components/places/tests/favicons/head_favicons.js
@@ -53,13 +53,10 @@ function checkFaviconDataForPage(
* This function is called after the check finished.
*/
function checkFaviconMissingForPage(aPageURI, aCallback) {
- PlacesUtils.favicons.getFaviconURLForPage(
- aPageURI,
- function (aURI, aDataLen, aData, aMimeType) {
- Assert.ok(aURI === null);
- aCallback();
- }
- );
+ PlacesUtils.favicons.getFaviconURLForPage(aPageURI, function (aURI) {
+ Assert.ok(aURI === null);
+ aCallback();
+ });
}
function promiseFaviconMissingForPage(aPageURI) {
diff --git a/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js b/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js
index 1c95d63f94..c1f6689a70 100644
--- a/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js
+++ b/toolkit/components/places/tests/favicons/test_cached-favicon_mime_type.js
@@ -19,7 +19,7 @@ function streamListener(aExpectedContentType) {
}
streamListener.prototype = {
onStartRequest() {},
- onStopRequest(aRequest, aContext, aStatusCode) {
+ onStopRequest(aRequest) {
let channel = aRequest.QueryInterface(Ci.nsIChannel);
Assert.equal(
channel.contentType,
@@ -28,7 +28,7 @@ streamListener.prototype = {
);
this.done.resolve();
},
- onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
+ onDataAvailable(aRequest) {
aRequest.cancel(Cr.NS_ERROR_ABORT);
throw Components.Exception("", Cr.NS_ERROR_ABORT);
},
@@ -85,4 +85,60 @@ add_task(async function () {
let listener = new streamListener("image/png");
channel.asyncOpen(listener);
await listener.done.promise;
+
+ await PlacesUtils.history.clear();
+});
+
+add_task(async function test_userpass() {
+ info("Test whether can get favicon content regardless of user pass");
+
+ const PAGE_NORMAL = uri("http://mozilla.org/");
+ const PAGE_USERPASS = uri("http://user:pass@mozilla.org/");
+ const ICON_NORMAL = uri("http://mozilla.org/favicon.png");
+ const ICON_USERPASS = uri("http://user:pass@mozilla.org/favicon.png");
+ const CACHED_ICON_NORMAL = "cached-favicon:http://mozilla.org/favicon.png";
+ const CACHED_ICON_USERPASS =
+ "cached-favicon:http://user:pass@mozilla.org/favicon.png";
+
+ const testData = [
+ {
+ pageURI: PAGE_USERPASS,
+ iconURI: ICON_NORMAL,
+ },
+ {
+ pageURI: PAGE_NORMAL,
+ iconURI: ICON_USERPASS,
+ },
+ {
+ pageURI: PAGE_USERPASS,
+ iconURI: ICON_USERPASS,
+ },
+ ];
+
+ for (const { pageURI, iconURI } of testData) {
+ for (const loadingIconURISpec of [
+ CACHED_ICON_NORMAL,
+ CACHED_ICON_USERPASS,
+ ]) {
+ PlacesUtils.favicons.replaceFaviconDataFromDataURL(
+ iconURI,
+ testFaviconData,
+ 0,
+ systemPrincipal
+ );
+ await PlacesTestUtils.addVisits(pageURI);
+ await setFaviconForPage(pageURI, iconURI);
+
+ // Open the channel
+ let channel = NetUtil.newChannel({
+ uri: loadingIconURISpec,
+ loadUsingSystemPrincipal: true,
+ contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON,
+ });
+ let listener = new streamListener("image/png");
+ channel.asyncOpen(listener);
+ await listener.done.promise;
+ await PlacesUtils.history.clear();
+ }
+ }
});
diff --git a/toolkit/components/places/tests/favicons/test_page-icon_protocol.js b/toolkit/components/places/tests/favicons/test_page-icon_protocol.js
index 932040bafb..287484868f 100644
--- a/toolkit/components/places/tests/favicons/test_page-icon_protocol.js
+++ b/toolkit/components/places/tests/favicons/test_page-icon_protocol.js
@@ -185,11 +185,11 @@ add_task(async function page_content_process() {
let img = content.document.createElement("img");
img.src = url;
let imgPromise = new Promise((resolve, reject) => {
- img.addEventListener("error", e => {
+ img.addEventListener("error", () => {
Assert.ok(true, "Got expected load error.");
resolve();
});
- img.addEventListener("load", e => {
+ img.addEventListener("load", () => {
Assert.ok(false, "Did not expect a successful load.");
reject();
});
@@ -225,11 +225,11 @@ add_task(async function page_privileged_about_content_process() {
let img = content.document.createElement("img");
img.src = url;
let imgPromise = new Promise((resolve, reject) => {
- img.addEventListener("error", e => {
+ img.addEventListener("error", () => {
Assert.ok(false, "Did not expect an error. ");
reject();
});
- img.addEventListener("load", e => {
+ img.addEventListener("load", () => {
Assert.ok(true, "Got expected load event.");
resolve();
});
@@ -241,3 +241,57 @@ add_task(async function page_privileged_about_content_process() {
await contentPage.close();
});
+
+add_task(async function test_with_user_pass() {
+ info("Test whether can get favicon content regardless of user pass");
+ await PlacesUtils.history.clear();
+
+ const PAGE_NORMAL = uri("http://mozilla.org/");
+ const PAGE_USERPASS = uri("http://user:pass@mozilla.org/");
+ const ICON_NORMAL = uri("http://mozilla.org/favicon.png");
+ const ICON_USERPASS = uri("http://user:pass@mozilla.org/favicon.png");
+ const PAGE_ICON_NORMAL = "page-icon:http://mozilla.org/";
+ const PAGE_ICON_USERPASS = "page-icon:http://user:pass@mozilla.org/";
+
+ const testData = [
+ {
+ pageURI: PAGE_USERPASS,
+ iconURI: ICON_NORMAL,
+ },
+ {
+ pageURI: PAGE_NORMAL,
+ iconURI: ICON_USERPASS,
+ },
+ {
+ pageURI: PAGE_USERPASS,
+ iconURI: ICON_USERPASS,
+ },
+ ];
+
+ for (const { pageURI, iconURI } of testData) {
+ for (const loadingIconURISpec of [PAGE_ICON_NORMAL, PAGE_ICON_USERPASS]) {
+ PlacesUtils.favicons.replaceFaviconDataFromDataURL(
+ iconURI,
+ ICON_DATAURL,
+ 0,
+ systemPrincipal
+ );
+ await PlacesTestUtils.addVisits(pageURI);
+ await new Promise(resolve => {
+ PlacesUtils.favicons.setAndFetchFaviconForPage(
+ pageURI,
+ iconURI,
+ false,
+ PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
+ resolve,
+ Services.scriptSecurityManager.getSystemPrincipal()
+ );
+ });
+
+ let { data, contentType } = await fetchIconForSpec(loadingIconURISpec);
+ Assert.equal(contentType, gFavicon.contentType);
+ Assert.deepEqual(data, gFavicon.data, "Got the favicon data");
+ await PlacesUtils.history.clear();
+ }
+ }
+});
diff --git a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js
index 1b4ea87ec0..b2d82e65b0 100644
--- a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js
+++ b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js
@@ -53,6 +53,17 @@ let gTests = [
Services.prefs.setBoolPref("places.history.enabled", true);
},
},
+ {
+ desc: "Visit URL with login info",
+ href: "http://user:pass@example.com/with_login_info",
+ loadType: PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
+ async setup() {
+ await PlacesTestUtils.addVisits({
+ uri: this.href,
+ transition: TRANSITION_TYPED,
+ });
+ },
+ },
];
add_task(async function () {
@@ -67,6 +78,7 @@ add_task(async function () {
for (let test of gTests) {
info(test.desc);
let pageURI = PlacesUtils.toURI(test.href);
+ let exposableURI = Services.io.createExposableURI(pageURI);
await test.setup();
@@ -75,7 +87,7 @@ add_task(async function () {
"favicon-changed",
events =>
events.some(e => {
- if (e.url == pageURI.spec && e.faviconUrl == faviconURI.spec) {
+ if (e.url == exposableURI.spec && e.faviconUrl == faviconURI.spec) {
pageGuid = e.pageGuid;
return true;
}
@@ -97,7 +109,7 @@ add_task(async function () {
Assert.equal(
pageGuid,
await PlacesTestUtils.getDatabaseValue("moz_places", "guid", {
- url: pageURI,
+ url: exposableURI,
}),
"Page guid is correct"
);