Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Test that the onmozbrowsericonchange event works.
5 "use strict";
7 SimpleTest.waitForExplicitFinish();
8 browserElementTestHelpers.setEnabledPref(true);
9 browserElementTestHelpers.addPermission();
11 function createHtml(link) {
12 return 'data:text/html,<html><head>' + link + '<body></body></html>';
13 }
15 function createLink(name, sizes) {
16 var s = sizes ? 'sizes="' + sizes + '"' : '';
17 return '<link rel="icon" type="image/png" ' + s + ' href="http://example.com/' + name + '.png">';
18 }
20 function runTest() {
21 var iframe1 = document.createElement('iframe');
22 SpecialPowers.wrap(iframe1).mozbrowser = true;
23 document.body.appendChild(iframe1);
25 // iframe2 is a red herring; we modify its favicon but don't listen for
26 // iconchanges; we want to make sure that its iconchange events aren't
27 // picked up by the listener on iframe1.
28 var iframe2 = document.createElement('iframe');
29 SpecialPowers.wrap(iframe2).mozbrowser = true;
30 document.body.appendChild(iframe2);
32 // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't
33 // get any iconchange events on it.
34 var iframe3 = document.createElement('iframe');
35 document.body.appendChild(iframe3);
37 var numIconChanges = 0;
39 iframe1.addEventListener('mozbrowsericonchange', function(e) {
41 numIconChanges++;
43 if (numIconChanges == 1) {
44 is(e.detail.href, 'http://example.com/myicon.png');
46 // We should recieve iconchange events when the user creates new links
47 // to a favicon, but only when we listen for them
48 SpecialPowers.getBrowserFrameMessageManager(iframe1)
49 .loadFrameScript("data:,content.document.title='New title';",
50 /* allowDelayedLoad = */ false);
52 SpecialPowers.getBrowserFrameMessageManager(iframe1)
53 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/newicon.png>')",
54 /* allowDelayedLoad = */ false);
56 SpecialPowers.getBrowserFrameMessageManager(iframe2)
57 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/newicon.png>')",
58 /* allowDelayedLoad = */ false);
59 }
60 else if (numIconChanges == 2) {
61 is(e.detail.href, 'http://example.com/newicon.png');
63 // Full new pages should trigger iconchange events
64 iframe1.src = createHtml(createLink('3rdicon'));
65 }
66 else if (numIconChanges == 3) {
67 is(e.detail.href, 'http://example.com/3rdicon.png');
69 // the rel attribute can have various space seperated values, make
70 // sure we only pick up correct values for 'icon'
71 SpecialPowers.getBrowserFrameMessageManager(iframe1)
72 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=shortcuticon href=http://example.com/newicon.png>')",
73 /* allowDelayedLoad = */ false);
74 // Test setting a page with multiple links elements
75 iframe1.src = createHtml(createLink('another') + createLink('icon'));
76 }
77 else if (numIconChanges == 4) {
78 is(e.detail.href, 'http://example.com/another.png');
79 // 2 events will be triggered by previous test, wait for next
80 }
81 else if (numIconChanges == 5) {
82 is(e.detail.href, 'http://example.com/icon.png');
84 // Make sure icon check is case insensitive
85 SpecialPowers.getBrowserFrameMessageManager(iframe1)
86 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=ICON href=http://example.com/ucaseicon.png>')",
87 /* allowDelayedLoad = */ false);
88 }
89 else if (numIconChanges == 6) {
90 is(e.detail.href, 'http://example.com/ucaseicon.png');
91 iframe1.src = createHtml(createLink('testsize', '50x50'));
92 }
93 else if (numIconChanges == 7) {
94 is(e.detail.href, 'http://example.com/testsize.png');
95 is(e.detail.sizes, '50x50');
96 SimpleTest.finish();
97 } else {
98 ok(false, 'Too many iconchange events.');
99 }
100 });
102 iframe3.addEventListener('mozbrowsericonchange', function(e) {
103 ok(false, 'Should not get a iconchange event for iframe3.');
104 });
107 iframe1.src = createHtml(createLink('myicon'));
108 // We should not recieve icon change events for either of the below iframes
109 iframe2.src = createHtml(createLink('myicon'));
110 iframe3.src = createHtml(createLink('myicon'));
112 }
114 addEventListener('testready', runTest);