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
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 onmozbrowsermanifestchange 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(manifest) { |
michael@0 | 12 | return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace"><head>' + manifest + '<body></body></html>'; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function createManifest(href) { |
michael@0 | 16 | return '<link rel="manifest" href="' + href + '">'; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function runTest() { |
michael@0 | 20 | var iframe1 = document.createElement('iframe'); |
michael@0 | 21 | SpecialPowers.wrap(iframe1).mozbrowser = true; |
michael@0 | 22 | document.body.appendChild(iframe1); |
michael@0 | 23 | |
michael@0 | 24 | // iframe2 is a red herring; we modify its manifest link elements but don't |
michael@0 | 25 | // listen for manifestchanges; we want to make sure that its manifestchange |
michael@0 | 26 | // events aren't picked up by the listener on iframe1. |
michael@0 | 27 | var iframe2 = document.createElement('iframe'); |
michael@0 | 28 | SpecialPowers.wrap(iframe2).mozbrowser = true; |
michael@0 | 29 | document.body.appendChild(iframe2); |
michael@0 | 30 | |
michael@0 | 31 | // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't |
michael@0 | 32 | // get any manifestchange events on it. |
michael@0 | 33 | var iframe3 = document.createElement('iframe'); |
michael@0 | 34 | document.body.appendChild(iframe3); |
michael@0 | 35 | |
michael@0 | 36 | var numManifestChanges = 0; |
michael@0 | 37 | |
michael@0 | 38 | iframe1.addEventListener('mozbrowsermanifestchange', function(e) { |
michael@0 | 39 | |
michael@0 | 40 | numManifestChanges++; |
michael@0 | 41 | |
michael@0 | 42 | if (numManifestChanges == 1) { |
michael@0 | 43 | is(e.detail.href, 'manifest.1', 'manifest.1 matches'); |
michael@0 | 44 | |
michael@0 | 45 | // We should recieve manifestchange events when the user creates new |
michael@0 | 46 | // manifests |
michael@0 | 47 | SpecialPowers.getBrowserFrameMessageManager(iframe1) |
michael@0 | 48 | .loadFrameScript("data:,content.document.title='New title';", |
michael@0 | 49 | /* allowDelayedLoad = */ false); |
michael@0 | 50 | |
michael@0 | 51 | SpecialPowers.getBrowserFrameMessageManager(iframe1) |
michael@0 | 52 | .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", |
michael@0 | 53 | /* allowDelayedLoad = */ false); |
michael@0 | 54 | |
michael@0 | 55 | SpecialPowers.getBrowserFrameMessageManager(iframe2) |
michael@0 | 56 | .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", |
michael@0 | 57 | /* allowDelayedLoad = */ false); |
michael@0 | 58 | } |
michael@0 | 59 | else if (numManifestChanges == 2) { |
michael@0 | 60 | is(e.detail.href, 'manifest.2', 'manifest.2 matches'); |
michael@0 | 61 | |
michael@0 | 62 | // Full new pages should trigger manifestchange events |
michael@0 | 63 | iframe1.src = createHtml(createManifest('manifest.3')); |
michael@0 | 64 | } |
michael@0 | 65 | else if (numManifestChanges == 3) { |
michael@0 | 66 | is(e.detail.href, 'manifest.3', 'manifest.3 matches'); |
michael@0 | 67 | |
michael@0 | 68 | // Test setting a page with multiple manifest link elements |
michael@0 | 69 | iframe1.src = createHtml(createManifest('manifest.4a') + createManifest('manifest.4b')); |
michael@0 | 70 | } |
michael@0 | 71 | else if (numManifestChanges == 4) { |
michael@0 | 72 | is(e.detail.href, 'manifest.4a', 'manifest.4a matches'); |
michael@0 | 73 | // 2 events will be triggered by previous test, wait for next |
michael@0 | 74 | } |
michael@0 | 75 | else if (numManifestChanges == 5) { |
michael@0 | 76 | is(e.detail.href, 'manifest.4b', 'manifest.4b matches'); |
michael@0 | 77 | SimpleTest.finish(); |
michael@0 | 78 | } else { |
michael@0 | 79 | ok(false, 'Too many manifestchange events.'); |
michael@0 | 80 | } |
michael@0 | 81 | }); |
michael@0 | 82 | |
michael@0 | 83 | iframe3.addEventListener('mozbrowsermanifestchange', function(e) { |
michael@0 | 84 | ok(false, 'Should not get a manifestchange event for iframe3.'); |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | |
michael@0 | 88 | iframe1.src = createHtml(createManifest('manifest.1')); |
michael@0 | 89 | // We should not recieve manifest change events for either of the below iframes |
michael@0 | 90 | iframe2.src = createHtml(createManifest('manifest.1')); |
michael@0 | 91 | iframe3.src = createHtml(createManifest('manifest.1')); |
michael@0 | 92 | |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | addEventListener('testready', runTest); |
michael@0 | 96 |