toolkit/components/places/tests/favicons/head_favicons.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const Ci = Components.interfaces;
michael@0 7 const Cc = Components.classes;
michael@0 8 const Cr = Components.results;
michael@0 9 const Cu = Components.utils;
michael@0 10
michael@0 11 Cu.import("resource://gre/modules/Services.jsm");
michael@0 12
michael@0 13 // Import common head.
michael@0 14 let (commonFile = do_get_file("../head_common.js", false)) {
michael@0 15 let uri = Services.io.newFileURI(commonFile);
michael@0 16 Services.scriptloader.loadSubScript(uri.spec, this);
michael@0 17 }
michael@0 18
michael@0 19 // Put any other stuff relative to this test folder below.
michael@0 20
michael@0 21
michael@0 22 // This error icon must stay in sync with FAVICON_ERRORPAGE_URL in
michael@0 23 // nsIFaviconService.idl, aboutCertError.xhtml and netError.xhtml.
michael@0 24 const FAVICON_ERRORPAGE_URI =
michael@0 25 NetUtil.newURI("chrome://global/skin/icons/warning-16.png");
michael@0 26
michael@0 27 /**
michael@0 28 * Waits for the first OnPageChanged notification for ATTRIBUTE_FAVICON, and
michael@0 29 * verifies that it matches the expected page URI and associated favicon URI.
michael@0 30 *
michael@0 31 * This function also double-checks the GUID parameter of the notification.
michael@0 32 *
michael@0 33 * @param aExpectedPageURI
michael@0 34 * nsIURI object of the page whose favicon should change.
michael@0 35 * @param aExpectedFaviconURI
michael@0 36 * nsIURI object of the newly associated favicon.
michael@0 37 * @param aCallback
michael@0 38 * This function is called after the check finished.
michael@0 39 */
michael@0 40 function waitForFaviconChanged(aExpectedPageURI, aExpectedFaviconURI,
michael@0 41 aCallback) {
michael@0 42 let historyObserver = {
michael@0 43 __proto__: NavHistoryObserver.prototype,
michael@0 44 onPageChanged: function WFFC_onPageChanged(aURI, aWhat, aValue, aGUID) {
michael@0 45 if (aWhat != Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) {
michael@0 46 return;
michael@0 47 }
michael@0 48 PlacesUtils.history.removeObserver(this);
michael@0 49
michael@0 50 do_check_true(aURI.equals(aExpectedPageURI));
michael@0 51 do_check_eq(aValue, aExpectedFaviconURI.spec);
michael@0 52 do_check_guid_for_uri(aURI, aGUID);
michael@0 53 aCallback();
michael@0 54 }
michael@0 55 };
michael@0 56 PlacesUtils.history.addObserver(historyObserver, false);
michael@0 57 }
michael@0 58
michael@0 59 /**
michael@0 60 * Checks that the favicon for the given page matches the provided data.
michael@0 61 *
michael@0 62 * @param aPageURI
michael@0 63 * nsIURI object for the page to check.
michael@0 64 * @param aExpectedMimeType
michael@0 65 * Expected MIME type of the icon, for example "image/png".
michael@0 66 * @param aExpectedData
michael@0 67 * Expected icon data, expressed as an array of byte values.
michael@0 68 * @param aCallback
michael@0 69 * This function is called after the check finished.
michael@0 70 */
michael@0 71 function checkFaviconDataForPage(aPageURI, aExpectedMimeType, aExpectedData,
michael@0 72 aCallback) {
michael@0 73 PlacesUtils.favicons.getFaviconDataForPage(aPageURI,
michael@0 74 function (aURI, aDataLen, aData, aMimeType) {
michael@0 75 do_check_eq(aExpectedMimeType, aMimeType);
michael@0 76 do_check_true(compareArrays(aExpectedData, aData));
michael@0 77 do_check_guid_for_uri(aPageURI);
michael@0 78 aCallback();
michael@0 79 });
michael@0 80 }
michael@0 81
michael@0 82 /**
michael@0 83 * Checks that the given page has no associated favicon.
michael@0 84 *
michael@0 85 * @param aPageURI
michael@0 86 * nsIURI object for the page to check.
michael@0 87 * @param aCallback
michael@0 88 * This function is called after the check finished.
michael@0 89 */
michael@0 90 function checkFaviconMissingForPage(aPageURI, aCallback) {
michael@0 91 PlacesUtils.favicons.getFaviconURLForPage(aPageURI,
michael@0 92 function (aURI, aDataLen, aData, aMimeType) {
michael@0 93 do_check_true(aURI === null);
michael@0 94 aCallback();
michael@0 95 });
michael@0 96 }

mercurial