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.

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

mercurial