1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_Manifestchange.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that the onmozbrowsermanifestchange event works. 1.8 +"use strict"; 1.9 + 1.10 +SimpleTest.waitForExplicitFinish(); 1.11 +browserElementTestHelpers.setEnabledPref(true); 1.12 +browserElementTestHelpers.addPermission(); 1.13 + 1.14 +function createHtml(manifest) { 1.15 + return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace"><head>' + manifest + '<body></body></html>'; 1.16 +} 1.17 + 1.18 +function createManifest(href) { 1.19 + return '<link rel="manifest" href="' + href + '">'; 1.20 +} 1.21 + 1.22 +function runTest() { 1.23 + var iframe1 = document.createElement('iframe'); 1.24 + SpecialPowers.wrap(iframe1).mozbrowser = true; 1.25 + document.body.appendChild(iframe1); 1.26 + 1.27 + // iframe2 is a red herring; we modify its manifest link elements but don't 1.28 + // listen for manifestchanges; we want to make sure that its manifestchange 1.29 + // events aren't picked up by the listener on iframe1. 1.30 + var iframe2 = document.createElement('iframe'); 1.31 + SpecialPowers.wrap(iframe2).mozbrowser = true; 1.32 + document.body.appendChild(iframe2); 1.33 + 1.34 + // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't 1.35 + // get any manifestchange events on it. 1.36 + var iframe3 = document.createElement('iframe'); 1.37 + document.body.appendChild(iframe3); 1.38 + 1.39 + var numManifestChanges = 0; 1.40 + 1.41 + iframe1.addEventListener('mozbrowsermanifestchange', function(e) { 1.42 + 1.43 + numManifestChanges++; 1.44 + 1.45 + if (numManifestChanges == 1) { 1.46 + is(e.detail.href, 'manifest.1', 'manifest.1 matches'); 1.47 + 1.48 + // We should recieve manifestchange events when the user creates new 1.49 + // manifests 1.50 + SpecialPowers.getBrowserFrameMessageManager(iframe1) 1.51 + .loadFrameScript("data:,content.document.title='New title';", 1.52 + /* allowDelayedLoad = */ false); 1.53 + 1.54 + SpecialPowers.getBrowserFrameMessageManager(iframe1) 1.55 + .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", 1.56 + /* allowDelayedLoad = */ false); 1.57 + 1.58 + SpecialPowers.getBrowserFrameMessageManager(iframe2) 1.59 + .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", 1.60 + /* allowDelayedLoad = */ false); 1.61 + } 1.62 + else if (numManifestChanges == 2) { 1.63 + is(e.detail.href, 'manifest.2', 'manifest.2 matches'); 1.64 + 1.65 + // Full new pages should trigger manifestchange events 1.66 + iframe1.src = createHtml(createManifest('manifest.3')); 1.67 + } 1.68 + else if (numManifestChanges == 3) { 1.69 + is(e.detail.href, 'manifest.3', 'manifest.3 matches'); 1.70 + 1.71 + // Test setting a page with multiple manifest link elements 1.72 + iframe1.src = createHtml(createManifest('manifest.4a') + createManifest('manifest.4b')); 1.73 + } 1.74 + else if (numManifestChanges == 4) { 1.75 + is(e.detail.href, 'manifest.4a', 'manifest.4a matches'); 1.76 + // 2 events will be triggered by previous test, wait for next 1.77 + } 1.78 + else if (numManifestChanges == 5) { 1.79 + is(e.detail.href, 'manifest.4b', 'manifest.4b matches'); 1.80 + SimpleTest.finish(); 1.81 + } else { 1.82 + ok(false, 'Too many manifestchange events.'); 1.83 + } 1.84 + }); 1.85 + 1.86 + iframe3.addEventListener('mozbrowsermanifestchange', function(e) { 1.87 + ok(false, 'Should not get a manifestchange event for iframe3.'); 1.88 + }); 1.89 + 1.90 + 1.91 + iframe1.src = createHtml(createManifest('manifest.1')); 1.92 + // We should not recieve manifest change events for either of the below iframes 1.93 + iframe2.src = createHtml(createManifest('manifest.1')); 1.94 + iframe3.src = createHtml(createManifest('manifest.1')); 1.95 + 1.96 +} 1.97 + 1.98 +addEventListener('testready', runTest); 1.99 +