michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: // Import common head. michael@0: let (commonFile = do_get_file("../head_common.js", false)) { michael@0: let uri = Services.io.newFileURI(commonFile); michael@0: Services.scriptloader.loadSubScript(uri.spec, this); michael@0: } michael@0: michael@0: // Put any other stuff relative to this test folder below. michael@0: michael@0: michael@0: // This error icon must stay in sync with FAVICON_ERRORPAGE_URL in michael@0: // nsIFaviconService.idl, aboutCertError.xhtml and netError.xhtml. michael@0: const FAVICON_ERRORPAGE_URI = michael@0: NetUtil.newURI("chrome://global/skin/icons/warning-16.png"); michael@0: michael@0: /** michael@0: * Waits for the first OnPageChanged notification for ATTRIBUTE_FAVICON, and michael@0: * verifies that it matches the expected page URI and associated favicon URI. michael@0: * michael@0: * This function also double-checks the GUID parameter of the notification. michael@0: * michael@0: * @param aExpectedPageURI michael@0: * nsIURI object of the page whose favicon should change. michael@0: * @param aExpectedFaviconURI michael@0: * nsIURI object of the newly associated favicon. michael@0: * @param aCallback michael@0: * This function is called after the check finished. michael@0: */ michael@0: function waitForFaviconChanged(aExpectedPageURI, aExpectedFaviconURI, michael@0: aCallback) { michael@0: let historyObserver = { michael@0: __proto__: NavHistoryObserver.prototype, michael@0: onPageChanged: function WFFC_onPageChanged(aURI, aWhat, aValue, aGUID) { michael@0: if (aWhat != Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) { michael@0: return; michael@0: } michael@0: PlacesUtils.history.removeObserver(this); michael@0: michael@0: do_check_true(aURI.equals(aExpectedPageURI)); michael@0: do_check_eq(aValue, aExpectedFaviconURI.spec); michael@0: do_check_guid_for_uri(aURI, aGUID); michael@0: aCallback(); michael@0: } michael@0: }; michael@0: PlacesUtils.history.addObserver(historyObserver, false); michael@0: } michael@0: michael@0: /** michael@0: * Checks that the favicon for the given page matches the provided data. michael@0: * michael@0: * @param aPageURI michael@0: * nsIURI object for the page to check. michael@0: * @param aExpectedMimeType michael@0: * Expected MIME type of the icon, for example "image/png". michael@0: * @param aExpectedData michael@0: * Expected icon data, expressed as an array of byte values. michael@0: * @param aCallback michael@0: * This function is called after the check finished. michael@0: */ michael@0: function checkFaviconDataForPage(aPageURI, aExpectedMimeType, aExpectedData, michael@0: aCallback) { michael@0: PlacesUtils.favicons.getFaviconDataForPage(aPageURI, michael@0: function (aURI, aDataLen, aData, aMimeType) { michael@0: do_check_eq(aExpectedMimeType, aMimeType); michael@0: do_check_true(compareArrays(aExpectedData, aData)); michael@0: do_check_guid_for_uri(aPageURI); michael@0: aCallback(); michael@0: }); michael@0: } michael@0: michael@0: /** michael@0: * Checks that the given page has no associated favicon. michael@0: * michael@0: * @param aPageURI michael@0: * nsIURI object for the page to check. michael@0: * @param aCallback michael@0: * This function is called after the check finished. michael@0: */ michael@0: function checkFaviconMissingForPage(aPageURI, aCallback) { michael@0: PlacesUtils.favicons.getFaviconURLForPage(aPageURI, michael@0: function (aURI, aDataLen, aData, aMimeType) { michael@0: do_check_true(aURI === null); michael@0: aCallback(); michael@0: }); michael@0: }