toolkit/components/places/tests/favicons/test_favicons_conversions.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * This file tests the image conversions done by the favicon service.
michael@0 6 */
michael@0 7
michael@0 8 ////////////////////////////////////////////////////////////////////////////////
michael@0 9 /// Globals
michael@0 10
michael@0 11 // The pixel values we get on Windows are sometimes +/- 1 value compared to
michael@0 12 // other platforms, so we need to skip some image content tests.
michael@0 13 let isWindows = ("@mozilla.org/windows-registry-key;1" in Cc);
michael@0 14
michael@0 15 /**
michael@0 16 * Checks the conversion of the given test image file.
michael@0 17 *
michael@0 18 * @param aFileName
michael@0 19 * File that contains the favicon image, located in the test folder.
michael@0 20 * @param aFileMimeType
michael@0 21 * MIME type of the image contained in the file.
michael@0 22 * @param aFileLength
michael@0 23 * Expected length of the file.
michael@0 24 * @param aExpectConversion
michael@0 25 * If false, the icon should be stored as is. If true, the expected data
michael@0 26 * is loaded from a file named "expected-" + aFileName + ".png".
michael@0 27 * @param aVaryOnWindows
michael@0 28 * Indicates that the content of the converted image can be different on
michael@0 29 * Windows and should not be checked on that platform.
michael@0 30 * @param aCallback
michael@0 31 * This function is called after the check finished.
michael@0 32 */
michael@0 33 function checkFaviconDataConversion(aFileName, aFileMimeType, aFileLength,
michael@0 34 aExpectConversion, aVaryOnWindows,
michael@0 35 aCallback) {
michael@0 36 let pageURI = NetUtil.newURI("http://places.test/page/" + aFileName);
michael@0 37 promiseAddVisits({ uri: pageURI, transition: TRANSITION_TYPED }).then(
michael@0 38 function () {
michael@0 39 let faviconURI = NetUtil.newURI("http://places.test/icon/" + aFileName);
michael@0 40 let fileData = readFileOfLength(aFileName, aFileLength);
michael@0 41
michael@0 42 PlacesUtils.favicons.replaceFaviconData(faviconURI, fileData, fileData.length,
michael@0 43 aFileMimeType);
michael@0 44 PlacesUtils.favicons.setAndFetchFaviconForPage(pageURI, faviconURI, true,
michael@0 45 PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
michael@0 46 function CFDC_verify(aURI, aDataLen, aData, aMimeType) {
michael@0 47 if (!aExpectConversion) {
michael@0 48 do_check_true(compareArrays(aData, fileData));
michael@0 49 do_check_eq(aMimeType, aFileMimeType);
michael@0 50 } else {
michael@0 51 if (!aVaryOnWindows || !isWindows) {
michael@0 52 let expectedFile = do_get_file("expected-" + aFileName + ".png");
michael@0 53 do_check_true(compareArrays(aData, readFileData(expectedFile)));
michael@0 54 }
michael@0 55 do_check_eq(aMimeType, "image/png");
michael@0 56 }
michael@0 57
michael@0 58 aCallback();
michael@0 59 });
michael@0 60 });
michael@0 61 }
michael@0 62
michael@0 63 ////////////////////////////////////////////////////////////////////////////////
michael@0 64 /// Tests
michael@0 65
michael@0 66 function run_test() {
michael@0 67 run_next_test();
michael@0 68 }
michael@0 69
michael@0 70 add_test(function test_storing_a_normal_16x16_icon() {
michael@0 71 // 16x16 png, 286 bytes.
michael@0 72 checkFaviconDataConversion("favicon-normal16.png", "image/png", 286,
michael@0 73 false, false, run_next_test);
michael@0 74 });
michael@0 75
michael@0 76 add_test(function test_storing_a_normal_32x32_icon() {
michael@0 77 // 32x32 png, 344 bytes.
michael@0 78 checkFaviconDataConversion("favicon-normal32.png", "image/png", 344,
michael@0 79 false, false, run_next_test);
michael@0 80 });
michael@0 81
michael@0 82 add_test(function test_storing_an_oversize_16x16_icon() {
michael@0 83 // in: 16x16 ico, 1406 bytes.
michael@0 84 // out: 16x16 png
michael@0 85 checkFaviconDataConversion("favicon-big16.ico", "image/x-icon", 1406,
michael@0 86 true, false, run_next_test);
michael@0 87 });
michael@0 88
michael@0 89 add_test(function test_storing_an_oversize_4x4_icon() {
michael@0 90 // in: 4x4 jpg, 4751 bytes.
michael@0 91 // out: 16x16 png
michael@0 92 checkFaviconDataConversion("favicon-big4.jpg", "image/jpeg", 4751,
michael@0 93 true, false, run_next_test);
michael@0 94 });
michael@0 95
michael@0 96 add_test(function test_storing_an_oversize_32x32_icon() {
michael@0 97 // in: 32x32 jpg, 3494 bytes.
michael@0 98 // out: 16x16 png
michael@0 99 checkFaviconDataConversion("favicon-big32.jpg", "image/jpeg", 3494,
michael@0 100 true, true, run_next_test);
michael@0 101 });
michael@0 102
michael@0 103 add_test(function test_storing_an_oversize_48x48_icon() {
michael@0 104 // in: 48x48 ico, 56646 bytes.
michael@0 105 // (howstuffworks.com icon, contains 13 icons with sizes from 16x16 to
michael@0 106 // 48x48 in varying depths)
michael@0 107 // out: 16x16 png
michael@0 108 checkFaviconDataConversion("favicon-big48.ico", "image/x-icon", 56646,
michael@0 109 true, false, run_next_test);
michael@0 110 });
michael@0 111
michael@0 112 add_test(function test_storing_an_oversize_64x64_icon() {
michael@0 113 // in: 64x64 png, 10698 bytes.
michael@0 114 // out: 16x16 png
michael@0 115 checkFaviconDataConversion("favicon-big64.png", "image/png", 10698,
michael@0 116 true, false, run_next_test);
michael@0 117 });
michael@0 118
michael@0 119 add_test(function test_scaling_an_oversize_160x3_icon() {
michael@0 120 // in: 160x3 jpg, 5095 bytes.
michael@0 121 // out: 16x16 png
michael@0 122 checkFaviconDataConversion("favicon-scale160x3.jpg", "image/jpeg", 5095,
michael@0 123 true, false, run_next_test);
michael@0 124 });
michael@0 125
michael@0 126 add_test(function test_scaling_an_oversize_3x160_icon() {
michael@0 127 // in: 3x160 jpg, 5059 bytes.
michael@0 128 // out: 16x16 png
michael@0 129 checkFaviconDataConversion("favicon-scale3x160.jpg", "image/jpeg", 5059,
michael@0 130 true, false, run_next_test);
michael@0 131 });

mercurial