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