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 onmozbrowsermanifestchange 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(manifest) { michael@0: return 'data:text/html,' + manifest + ''; michael@0: } michael@0: michael@0: function createManifest(href) { 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 manifest link elements but don't michael@0: // listen for manifestchanges; we want to make sure that its manifestchange michael@0: // events aren't 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 manifestchange events on it. michael@0: var iframe3 = document.createElement('iframe'); michael@0: document.body.appendChild(iframe3); michael@0: michael@0: var numManifestChanges = 0; michael@0: michael@0: iframe1.addEventListener('mozbrowsermanifestchange', function(e) { michael@0: michael@0: numManifestChanges++; michael@0: michael@0: if (numManifestChanges == 1) { michael@0: is(e.detail.href, 'manifest.1', 'manifest.1 matches'); michael@0: michael@0: // We should recieve manifestchange events when the user creates new michael@0: // manifests 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 (numManifestChanges == 2) { michael@0: is(e.detail.href, 'manifest.2', 'manifest.2 matches'); michael@0: michael@0: // Full new pages should trigger manifestchange events michael@0: iframe1.src = createHtml(createManifest('manifest.3')); michael@0: } michael@0: else if (numManifestChanges == 3) { michael@0: is(e.detail.href, 'manifest.3', 'manifest.3 matches'); michael@0: michael@0: // Test setting a page with multiple manifest link elements michael@0: iframe1.src = createHtml(createManifest('manifest.4a') + createManifest('manifest.4b')); michael@0: } michael@0: else if (numManifestChanges == 4) { michael@0: is(e.detail.href, 'manifest.4a', 'manifest.4a matches'); michael@0: // 2 events will be triggered by previous test, wait for next michael@0: } michael@0: else if (numManifestChanges == 5) { michael@0: is(e.detail.href, 'manifest.4b', 'manifest.4b matches'); michael@0: SimpleTest.finish(); michael@0: } else { michael@0: ok(false, 'Too many manifestchange events.'); michael@0: } michael@0: }); michael@0: michael@0: iframe3.addEventListener('mozbrowsermanifestchange', function(e) { michael@0: ok(false, 'Should not get a manifestchange event for iframe3.'); michael@0: }); michael@0: michael@0: michael@0: iframe1.src = createHtml(createManifest('manifest.1')); michael@0: // We should not recieve manifest change events for either of the below iframes michael@0: iframe2.src = createHtml(createManifest('manifest.1')); michael@0: iframe3.src = createHtml(createManifest('manifest.1')); michael@0: michael@0: } michael@0: michael@0: addEventListener('testready', runTest); michael@0: