toolkit/components/places/tests/chrome/test_favicon_annotations.xul

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 <?xml version="1.0"?>
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 * This file tests the moz-anno protocol, which was added in Bug 316077 and how
michael@0 7 * it loads favicons.
michael@0 8 -->
michael@0 9
michael@0 10 <window title="Favicon Annotation Protocol Test"
michael@0 11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 12 onload="test();">
michael@0 13
michael@0 14 <script type="application/javascript"
michael@0 15 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 16 <script type="application/javascript"
michael@0 17 src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"/>
michael@0 18 <script type="application/javascript"
michael@0 19 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 20
michael@0 21 <script type="application/javascript">
michael@0 22 <![CDATA[
michael@0 23
michael@0 24 const Cc = Components.classes;
michael@0 25 const Ci = Components.interfaces;
michael@0 26 const Cr = Components.results;
michael@0 27
michael@0 28 let fs = Cc["@mozilla.org/browser/favicon-service;1"].
michael@0 29 getService(Ci.nsIFaviconService);
michael@0 30
michael@0 31 // Test descriptions that will be printed in the case of failure.
michael@0 32 let testDescriptions = [
michael@0 33 "moz-anno URI with no data in the database loads default icon",
michael@0 34 "URI added to the database is properly loaded",
michael@0 35 ];
michael@0 36
michael@0 37 // URIs to load (will be compared with expectedURIs of the same index).
michael@0 38 let testURIs = [
michael@0 39 "http://mozilla.org/2009/made-up-favicon/places-rocks/",
michael@0 40 "http://mozilla.org/should-be-barney/",
michael@0 41 ];
michael@0 42
michael@0 43 // URIs to load for expected results.
michael@0 44 let expectedURIs = [
michael@0 45 fs.defaultFavicon.spec,
michael@0 46 "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%D6IDATx%DAb%FC%FF%FF%3F%03%25%00%20%80%98%909%EF%DF%BFg%EF%EC%EC%FC%AD%AC%AC%FC%DF%95%91%F1%BF%89%89%C9%7F%20%FF%D7%EA%D5%AB%B7%DF%BBwO%16%9B%01%00%01%C4%00r%01%08%9F9s%C6%CD%D8%D8%F8%BF%0B%03%C3%FF3%40%BC%0A%88%EF%02q%1A%10%BB%40%F1%AAU%ABv%C1%D4%C30%40%00%81%89%993g%3E%06%1A%F6%3F%14%AA%11D%97%03%F1%7Fc%08%0D%E2%2B))%FD%17%04%89%A1%19%00%10%40%0C%D00%F8%0F3%00%C8%F8%BF%1B%E4%0Ac%88a%E5%60%17%19%FF%0F%0D%0D%05%1B%02v%D9%DD%BB%0A0%03%00%02%08%AC%B9%A3%A3%E3%17%03%D4v%90%01%EF%18%106%C3%0Cz%07%C5%BB%A1%DE%82y%07%20%80%A0%A6%08B%FCn%0C1%60%26%D4%20d%C3VA%C3%06%26%BE%0A%EA-%80%00%82%B9%E0%F7L4%0D%EF%90%F8%C6%60%2F%0A%82%BD%01%13%07%0700%D0%01%02%88%11%E4%02P%B41%DC%BB%C7%D0%014%0D%E8l%06W%20%06%BA%88%A1%1C%1AS%15%40%7C%16%CA6.%2Fgx%BFg%0F%83%CB%D9%B3%0C%7B%80%7C%80%00%02%BB%00%E8%9F%ED%20%1B%3A%A0%A6%9F%81%DA%DC%01%C5%B0%80%ED%80%FA%BF%BC%BC%FC%3F%83%12%90%9D%96%F6%1F%20%80%18%DE%BD%7B%C7%0E%8E%05AD%20%FEGr%A6%A0%A0%E0%7F%25P%80%02%9D%0F%D28%13%18%23%C6%C0%B0%02E%3D%C8%F5%00%01%04%8F%05P%A8%BA%40my%87%E4%12c%A8%8D%20%8B%D0%D3%00%08%03%04%10%9C%01R%E4%82d%3B%C8%A0%99%C6%90%90%C6%A5%19%84%01%02%08%9E%17%80%C9x%F7%7B%A0%DBVC%F9%A0%C0%5C%7D%16%2C%CE%00%F4%C6O%5C%99%09%20%800L%04y%A5%03%1A%95%A0%80%05%05%14.%DBA%18%20%80%18)%CD%CE%00%01%06%00%0C'%94%C7%C0k%C9%2C%00%00%00%00IEND%AEB%60%82",
michael@0 47 ];
michael@0 48
michael@0 49
michael@0 50 /**
michael@0 51 * The event listener placed on our test windows used to determine when it is
michael@0 52 * safe to compare the two windows.
michael@0 53 */
michael@0 54 let _results = [];
michael@0 55 function loadEventHandler()
michael@0 56 {
michael@0 57 _results.push(snapshotWindow(window));
michael@0 58
michael@0 59 loadNextTest();
michael@0 60 }
michael@0 61
michael@0 62 /**
michael@0 63 * This runs the comparison.
michael@0 64 */
michael@0 65 function compareResults(aIndex, aImage1, aImage2)
michael@0 66 {
michael@0 67 let [correct, data1, data2] = compareSnapshots(aImage1, aImage2, true);
michael@0 68 SimpleTest.ok(correct,
michael@0 69 "Test '" + testDescriptions[aIndex] + "' matches expectations. " +
michael@0 70 "Data from window 1 is '" + data1 + "'. " +
michael@0 71 "Data from window 2 is '" + data2 + "'");
michael@0 72 }
michael@0 73
michael@0 74 /**
michael@0 75 * Loads the next set of URIs to compare against.
michael@0 76 */
michael@0 77 let _counter = -1;
michael@0 78 function loadNextTest()
michael@0 79 {
michael@0 80 _counter++;
michael@0 81 // If we have no more tests, finish.
michael@0 82 if (_counter / 2 == testDescriptions.length) {
michael@0 83 for (let i = 0; i < _results.length; i = i + 2)
michael@0 84 compareResults(i / 2, _results[i], _results[i + 1]);
michael@0 85
michael@0 86 SimpleTest.finish();
michael@0 87 return;
michael@0 88 }
michael@0 89
michael@0 90 let nextURI = function() {
michael@0 91 let index = Math.floor(_counter / 2);
michael@0 92 if ((_counter % 2) == 0)
michael@0 93 return "moz-anno:favicon:" + testURIs[index];
michael@0 94 return expectedURIs[index];
michael@0 95 }
michael@0 96
michael@0 97 let img = document.getElementById("favicon");
michael@0 98 img.setAttribute("src", nextURI());
michael@0 99 }
michael@0 100
michael@0 101 function test()
michael@0 102 {
michael@0 103 SimpleTest.waitForExplicitFinish();
michael@0 104 let db = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 105 getService(Ci.nsPIPlacesDatabase).
michael@0 106 DBConnection;
michael@0 107
michael@0 108 // Empty any old favicons
michael@0 109 db.executeSimpleSQL("DELETE FROM moz_favicons");
michael@0 110
michael@0 111 let ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 112 getService(Ci.nsIIOService);
michael@0 113 let uri = function(aSpec) {
michael@0 114 return ios.newURI(aSpec, null, null);
michael@0 115 };
michael@0 116
michael@0 117 let pageURI = uri("http://example.com/favicon_annotations");
michael@0 118 let history = Cc["@mozilla.org/browser/history;1"]
michael@0 119 .getService(Ci.mozIAsyncHistory);
michael@0 120 history.updatePlaces(
michael@0 121 {
michael@0 122 uri: pageURI,
michael@0 123 visits: [{ transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED,
michael@0 124 visitDate: Date.now() * 1000
michael@0 125 }],
michael@0 126 },
michael@0 127 {
michael@0 128 handleError: function UP_handleError() {
michael@0 129 ok(false, "Unexpected error in adding visit.");
michael@0 130 },
michael@0 131 handleResult: function () {},
michael@0 132 handleCompletion: function UP_handleCompletion() {
michael@0 133 // Set the favicon data. Note that the "moz-anno:" protocol requires
michael@0 134 // the favicon to be stored in the database, but the
michael@0 135 // replaceFaviconDataFromDataURL function will not save the favicon
michael@0 136 // unless it is associated with a page. Thus, we must associate the
michael@0 137 // icon with a page explicitly in order for it to be visible through
michael@0 138 // the protocol.
michael@0 139 fs.replaceFaviconDataFromDataURL(uri(testURIs[1]), expectedURIs[1],
michael@0 140 (Date.now() + 60 * 60 * 24 * 1000) * 1000);
michael@0 141 fs.setAndFetchFaviconForPage(pageURI, uri(testURIs[1]), true,
michael@0 142 fs.FAVICON_LOAD_NON_PRIVATE);
michael@0 143
michael@0 144 // And start our test process.
michael@0 145 loadNextTest();
michael@0 146 }
michael@0 147 }
michael@0 148 );
michael@0 149
michael@0 150
michael@0 151 }
michael@0 152
michael@0 153 ]]>
michael@0 154 </script>
michael@0 155
michael@0 156 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 157 <img id="favicon" onload="loadEventHandler();"/>
michael@0 158 <p id="display"></p>
michael@0 159 <div id="content" style="display:none;"></div>
michael@0 160 <pre id="test"></pre>
michael@0 161 </body>
michael@0 162 </window>

mercurial