Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 onmozbrowsermetachange 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(meta) { |
michael@0 | 12 | return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace"><head>' + meta + '<body></body></html>'; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function createHtmlWithLang(meta, lang) { |
michael@0 | 16 | return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace" lang="' + lang + '"><head>' + meta + '<body></body></html>'; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function createMeta(name, content) { |
michael@0 | 20 | return '<meta name="' + name + '" content="' + content + '">'; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function createMetaWithLang(name, content, lang) { |
michael@0 | 24 | return '<meta name="' + name + '" content="' + content + '" lang="' + lang + '">'; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function runTest() { |
michael@0 | 28 | var iframe1 = document.createElement('iframe'); |
michael@0 | 29 | SpecialPowers.wrap(iframe1).mozbrowser = true; |
michael@0 | 30 | document.body.appendChild(iframe1); |
michael@0 | 31 | |
michael@0 | 32 | // iframe2 is a red herring; we modify its meta elements but don't listen for |
michael@0 | 33 | // metachanges; we want to make sure that its metachange events aren't |
michael@0 | 34 | // picked up by the listener on iframe1. |
michael@0 | 35 | var iframe2 = document.createElement('iframe'); |
michael@0 | 36 | SpecialPowers.wrap(iframe2).mozbrowser = true; |
michael@0 | 37 | document.body.appendChild(iframe2); |
michael@0 | 38 | |
michael@0 | 39 | // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't |
michael@0 | 40 | // get any metachange events on it. |
michael@0 | 41 | var iframe3 = document.createElement('iframe'); |
michael@0 | 42 | document.body.appendChild(iframe3); |
michael@0 | 43 | |
michael@0 | 44 | var numMetaChanges = 0; |
michael@0 | 45 | |
michael@0 | 46 | iframe1.addEventListener('mozbrowsermetachange', function(e) { |
michael@0 | 47 | |
michael@0 | 48 | numMetaChanges++; |
michael@0 | 49 | |
michael@0 | 50 | if (numMetaChanges == 1) { |
michael@0 | 51 | is(e.detail.name, 'application-name'); |
michael@0 | 52 | is(e.detail.content, 'foobar'); |
michael@0 | 53 | |
michael@0 | 54 | // We should recieve metachange events when the user creates new metas |
michael@0 | 55 | SpecialPowers.getBrowserFrameMessageManager(iframe1) |
michael@0 | 56 | .loadFrameScript("data:,content.document.title='New title';", |
michael@0 | 57 | /* allowDelayedLoad = */ false); |
michael@0 | 58 | |
michael@0 | 59 | SpecialPowers.getBrowserFrameMessageManager(iframe1) |
michael@0 | 60 | .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<meta name=application-name content=new_foobar>')", |
michael@0 | 61 | /* allowDelayedLoad = */ false); |
michael@0 | 62 | |
michael@0 | 63 | SpecialPowers.getBrowserFrameMessageManager(iframe2) |
michael@0 | 64 | .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<meta name=application-name content=new_foobar>')", |
michael@0 | 65 | /* allowDelayedLoad = */ false); |
michael@0 | 66 | } |
michael@0 | 67 | else if (numMetaChanges == 2) { |
michael@0 | 68 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 69 | is(e.detail.content, 'new_foobar', 'content matches'); |
michael@0 | 70 | ok(!("lang" in e.detail), 'lang not present'); |
michael@0 | 71 | |
michael@0 | 72 | // Full new pages should trigger metachange events |
michael@0 | 73 | iframe1.src = createHtml(createMeta('application-name', '3rd_foobar')); |
michael@0 | 74 | } |
michael@0 | 75 | else if (numMetaChanges == 3) { |
michael@0 | 76 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 77 | is(e.detail.content, '3rd_foobar', 'content matches'); |
michael@0 | 78 | ok(!("lang" in e.detail), 'lang not present'); |
michael@0 | 79 | |
michael@0 | 80 | // Test setting a page with multiple meta elements |
michael@0 | 81 | iframe1.src = createHtml(createMeta('application-name', 'foobar_1') + createMeta('application-name', 'foobar_2')); |
michael@0 | 82 | } |
michael@0 | 83 | else if (numMetaChanges == 4) { |
michael@0 | 84 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 85 | is(e.detail.content, 'foobar_1', 'content matches'); |
michael@0 | 86 | ok(!("lang" in e.detail), 'lang not present'); |
michael@0 | 87 | // 2 events will be triggered by previous test, wait for next |
michael@0 | 88 | } |
michael@0 | 89 | else if (numMetaChanges == 5) { |
michael@0 | 90 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 91 | is(e.detail.content, 'foobar_2', 'content matches'); |
michael@0 | 92 | ok(!("lang" in e.detail), 'lang not present'); |
michael@0 | 93 | |
michael@0 | 94 | // Test the language |
michael@0 | 95 | iframe1.src = createHtml(createMetaWithLang('application-name', 'foobar_lang_1', 'en')); |
michael@0 | 96 | } |
michael@0 | 97 | else if (numMetaChanges == 6) { |
michael@0 | 98 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 99 | is(e.detail.content, 'foobar_lang_1', 'content matches'); |
michael@0 | 100 | is(e.detail.lang, 'en', 'language matches'); |
michael@0 | 101 | |
michael@0 | 102 | // Test the language in the ancestor element |
michael@0 | 103 | iframe1.src = createHtmlWithLang(createMeta('application-name', 'foobar_lang_2'), 'es'); |
michael@0 | 104 | } |
michael@0 | 105 | else if (numMetaChanges == 7) { |
michael@0 | 106 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 107 | is(e.detail.content, 'foobar_lang_2', 'content matches'); |
michael@0 | 108 | is(e.detail.lang, 'es', 'language matches'); |
michael@0 | 109 | |
michael@0 | 110 | // Test the language in the ancestor element |
michael@0 | 111 | iframe1.src = createHtmlWithLang(createMetaWithLang('application-name', 'foobar_lang_3', 'it'), 'fi'); |
michael@0 | 112 | } |
michael@0 | 113 | else if (numMetaChanges == 8) { |
michael@0 | 114 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 115 | is(e.detail.content, 'foobar_lang_3', 'content matches'); |
michael@0 | 116 | is(e.detail.lang, 'it', 'language matches'); |
michael@0 | 117 | |
michael@0 | 118 | // Test the content-language |
michael@0 | 119 | iframe1.src = "http://test/tests/dom/browser-element/mochitest/file_browserElement_Metachange.sjs?ru"; |
michael@0 | 120 | } |
michael@0 | 121 | else if (numMetaChanges == 9) { |
michael@0 | 122 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 123 | is(e.detail.content, 'sjs', 'content matches'); |
michael@0 | 124 | is(e.detail.lang, 'ru', 'language matches'); |
michael@0 | 125 | |
michael@0 | 126 | // Test the content-language |
michael@0 | 127 | iframe1.src = "http://test/tests/dom/browser-element/mochitest/file_browserElement_Metachange.sjs?ru|dk"; |
michael@0 | 128 | } |
michael@0 | 129 | else if (numMetaChanges == 10) { |
michael@0 | 130 | is(e.detail.name, 'application-name', 'name matches'); |
michael@0 | 131 | is(e.detail.content, 'sjs', 'content matches'); |
michael@0 | 132 | is(e.detail.lang, 'dk', 'language matches'); |
michael@0 | 133 | |
michael@0 | 134 | // Test the language |
michael@0 | 135 | SimpleTest.finish(); |
michael@0 | 136 | } else { |
michael@0 | 137 | ok(false, 'Too many metachange events.'); |
michael@0 | 138 | } |
michael@0 | 139 | }); |
michael@0 | 140 | |
michael@0 | 141 | iframe3.addEventListener('mozbrowsermetachange', function(e) { |
michael@0 | 142 | ok(false, 'Should not get a metachange event for iframe3.'); |
michael@0 | 143 | }); |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | iframe1.src = createHtml(createMeta('application-name', 'foobar')); |
michael@0 | 147 | // We should not recieve meta change events for either of the below iframes |
michael@0 | 148 | iframe2.src = createHtml(createMeta('application-name', 'foobar')); |
michael@0 | 149 | iframe3.src = createHtml(createMeta('application-name', 'foobar')); |
michael@0 | 150 | |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | addEventListener('testready', runTest); |