|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * This file tests getFaviconDataForPage. |
|
6 */ |
|
7 |
|
8 //////////////////////////////////////////////////////////////////////////////// |
|
9 /// Globals |
|
10 |
|
11 const FAVICON_URI = NetUtil.newURI(do_get_file("favicon-normal32.png")); |
|
12 const FAVICON_DATA = readFileData(do_get_file("favicon-normal32.png")); |
|
13 const FAVICON_MIMETYPE = "image/png"; |
|
14 |
|
15 //////////////////////////////////////////////////////////////////////////////// |
|
16 /// Tests |
|
17 |
|
18 function run_test() |
|
19 { |
|
20 // Check that the favicon loaded correctly before starting the actual tests. |
|
21 do_check_eq(FAVICON_DATA.length, 344); |
|
22 run_next_test(); |
|
23 } |
|
24 |
|
25 add_test(function test_normal() |
|
26 { |
|
27 let pageURI = NetUtil.newURI("http://example.com/normal"); |
|
28 |
|
29 promiseAddVisits(pageURI).then(function () { |
|
30 PlacesUtils.favicons.setAndFetchFaviconForPage( |
|
31 pageURI, FAVICON_URI, true, |
|
32 PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, |
|
33 function () { |
|
34 PlacesUtils.favicons.getFaviconDataForPage(pageURI, |
|
35 function (aURI, aDataLen, aData, aMimeType) { |
|
36 do_check_true(aURI.equals(FAVICON_URI)); |
|
37 do_check_eq(FAVICON_DATA.length, aDataLen); |
|
38 do_check_true(compareArrays(FAVICON_DATA, aData)); |
|
39 do_check_eq(FAVICON_MIMETYPE, aMimeType); |
|
40 run_next_test(); |
|
41 }); |
|
42 }); |
|
43 }); |
|
44 }); |
|
45 |
|
46 add_test(function test_missing() |
|
47 { |
|
48 let pageURI = NetUtil.newURI("http://example.com/missing"); |
|
49 |
|
50 PlacesUtils.favicons.getFaviconDataForPage(pageURI, |
|
51 function (aURI, aDataLen, aData, aMimeType) { |
|
52 // Check also the expected data types. |
|
53 do_check_true(aURI === null); |
|
54 do_check_true(aDataLen === 0); |
|
55 do_check_true(aData.length === 0); |
|
56 do_check_true(aMimeType === ""); |
|
57 run_next_test(); |
|
58 }); |
|
59 }); |