michael@0: /* Any copyright is dedicated to the public domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that the onmozbrowsericonchange event works. michael@0: "use strict"; michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: browserElementTestHelpers.setEnabledPref(true); michael@0: browserElementTestHelpers.addPermission(); michael@0: michael@0: function createHtml(link) { michael@0: return 'data:text/html,
' + link + ''; michael@0: } michael@0: michael@0: function createLink(name, sizes) { michael@0: var s = sizes ? 'sizes="' + sizes + '"' : ''; michael@0: return ''; michael@0: } michael@0: michael@0: function runTest() { michael@0: var iframe1 = document.createElement('iframe'); michael@0: SpecialPowers.wrap(iframe1).mozbrowser = true; michael@0: document.body.appendChild(iframe1); michael@0: michael@0: // iframe2 is a red herring; we modify its favicon but don't listen for michael@0: // iconchanges; we want to make sure that its iconchange events aren't michael@0: // picked up by the listener on iframe1. michael@0: var iframe2 = document.createElement('iframe'); michael@0: SpecialPowers.wrap(iframe2).mozbrowser = true; michael@0: document.body.appendChild(iframe2); michael@0: michael@0: // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't michael@0: // get any iconchange events on it. michael@0: var iframe3 = document.createElement('iframe'); michael@0: document.body.appendChild(iframe3); michael@0: michael@0: var numIconChanges = 0; michael@0: michael@0: iframe1.addEventListener('mozbrowsericonchange', function(e) { michael@0: michael@0: numIconChanges++; michael@0: michael@0: if (numIconChanges == 1) { michael@0: is(e.detail.href, 'http://example.com/myicon.png'); michael@0: michael@0: // We should recieve iconchange events when the user creates new links michael@0: // to a favicon, but only when we listen for them michael@0: SpecialPowers.getBrowserFrameMessageManager(iframe1) michael@0: .loadFrameScript("data:,content.document.title='New title';", michael@0: /* allowDelayedLoad = */ false); michael@0: michael@0: SpecialPowers.getBrowserFrameMessageManager(iframe1) michael@0: .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '')", michael@0: /* allowDelayedLoad = */ false); michael@0: michael@0: SpecialPowers.getBrowserFrameMessageManager(iframe2) michael@0: .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '')", michael@0: /* allowDelayedLoad = */ false); michael@0: } michael@0: else if (numIconChanges == 2) { michael@0: is(e.detail.href, 'http://example.com/newicon.png'); michael@0: michael@0: // Full new pages should trigger iconchange events michael@0: iframe1.src = createHtml(createLink('3rdicon')); michael@0: } michael@0: else if (numIconChanges == 3) { michael@0: is(e.detail.href, 'http://example.com/3rdicon.png'); michael@0: michael@0: // the rel attribute can have various space seperated values, make michael@0: // sure we only pick up correct values for 'icon' michael@0: SpecialPowers.getBrowserFrameMessageManager(iframe1) michael@0: .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '')", michael@0: /* allowDelayedLoad = */ false); michael@0: // Test setting a page with multiple links elements michael@0: iframe1.src = createHtml(createLink('another') + createLink('icon')); michael@0: } michael@0: else if (numIconChanges == 4) { michael@0: is(e.detail.href, 'http://example.com/another.png'); michael@0: // 2 events will be triggered by previous test, wait for next michael@0: } michael@0: else if (numIconChanges == 5) { michael@0: is(e.detail.href, 'http://example.com/icon.png'); michael@0: michael@0: // Make sure icon check is case insensitive michael@0: SpecialPowers.getBrowserFrameMessageManager(iframe1) michael@0: .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '')", michael@0: /* allowDelayedLoad = */ false); michael@0: } michael@0: else if (numIconChanges == 6) { michael@0: is(e.detail.href, 'http://example.com/ucaseicon.png'); michael@0: iframe1.src = createHtml(createLink('testsize', '50x50')); michael@0: } michael@0: else if (numIconChanges == 7) { michael@0: is(e.detail.href, 'http://example.com/testsize.png'); michael@0: is(e.detail.sizes, '50x50'); michael@0: SimpleTest.finish(); michael@0: } else { michael@0: ok(false, 'Too many iconchange events.'); michael@0: } michael@0: }); michael@0: michael@0: iframe3.addEventListener('mozbrowsericonchange', function(e) { michael@0: ok(false, 'Should not get a iconchange event for iframe3.'); michael@0: }); michael@0: michael@0: michael@0: iframe1.src = createHtml(createLink('myicon')); michael@0: // We should not recieve icon change events for either of the below iframes michael@0: iframe2.src = createHtml(createLink('myicon')); michael@0: iframe3.src = createHtml(createLink('myicon')); michael@0: michael@0: } michael@0: michael@0: addEventListener('testready', runTest);