browser_bug734076.js (5624B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function () { 5 // allow top level data: URI navigations, otherwise loading data: URIs 6 // in toplevel windows fail. 7 await SpecialPowers.pushPrefEnv({ 8 set: [["security.data_uri.block_toplevel_data_uri_navigations", false]], 9 }); 10 11 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, null, false); 12 13 tab.linkedBrowser.stop(); // stop the about:blank load 14 15 let writeDomainURL = encodeURI( 16 "data:text/html,<script>document.write(document.domain);</script>" 17 ); 18 19 let tests = [ 20 { 21 name: "view image with background image", 22 url: "http://mochi.test:8888/", 23 element: "body", 24 opensNewTab: true, 25 go() { 26 return SpecialPowers.spawn( 27 gBrowser.selectedBrowser, 28 [{ writeDomainURL }], 29 async function (arg) { 30 let contentBody = content.document.body; 31 contentBody.style.backgroundImage = 32 "url('" + arg.writeDomainURL + "')"; 33 34 return "context-viewimage"; 35 } 36 ); 37 }, 38 verify(browser) { 39 return SpecialPowers.spawn(browser, [], async function () { 40 Assert.equal( 41 content.document.body.textContent, 42 "", 43 "no domain was inherited for view image with background image" 44 ); 45 }); 46 }, 47 }, 48 { 49 name: "view image", 50 url: "http://mochi.test:8888/", 51 element: "img", 52 opensNewTab: true, 53 go() { 54 return SpecialPowers.spawn( 55 gBrowser.selectedBrowser, 56 [{ writeDomainURL }], 57 async function (arg) { 58 let doc = content.document; 59 let img = doc.createElement("img"); 60 img.height = 100; 61 img.width = 100; 62 img.setAttribute("src", arg.writeDomainURL); 63 doc.body.insertBefore(img, doc.body.firstElementChild); 64 65 return "context-viewimage"; 66 } 67 ); 68 }, 69 verify(browser) { 70 return SpecialPowers.spawn(browser, [], async function () { 71 Assert.equal( 72 content.document.body.textContent, 73 "", 74 "no domain was inherited for view image" 75 ); 76 }); 77 }, 78 }, 79 { 80 name: "show only this frame", 81 url: "http://mochi.test:8888/", 82 element: "html", 83 frameIndex: 0, 84 go() { 85 return SpecialPowers.spawn( 86 gBrowser.selectedBrowser, 87 [{ writeDomainURL }], 88 async function (arg) { 89 let doc = content.document; 90 let iframe = doc.createElement("iframe"); 91 iframe.setAttribute("src", arg.writeDomainURL); 92 doc.body.insertBefore(iframe, doc.body.firstElementChild); 93 94 // Wait for the iframe to load. 95 return new Promise(resolve => { 96 iframe.addEventListener( 97 "load", 98 function () { 99 resolve("context-showonlythisframe"); 100 }, 101 { capture: true, once: true } 102 ); 103 }); 104 } 105 ); 106 }, 107 verify(browser) { 108 return SpecialPowers.spawn(browser, [], async function () { 109 Assert.equal( 110 content.document.body.textContent, 111 "", 112 "no domain was inherited for 'show only this frame'" 113 ); 114 }); 115 }, 116 }, 117 ]; 118 119 let contentAreaContextMenu = document.getElementById( 120 "contentAreaContextMenu" 121 ); 122 123 for (let test of tests) { 124 let loadedPromise = BrowserTestUtils.browserLoaded( 125 gBrowser.selectedBrowser 126 ); 127 BrowserTestUtils.startLoadingURIString(gBrowser, test.url); 128 await loadedPromise; 129 130 info("Run subtest " + test.name); 131 let commandToRun = await test.go(); 132 133 let popupShownPromise = BrowserTestUtils.waitForEvent( 134 contentAreaContextMenu, 135 "popupshown" 136 ); 137 138 let browsingContext = gBrowser.selectedBrowser.browsingContext; 139 if (test.frameIndex != null) { 140 browsingContext = browsingContext.children[test.frameIndex]; 141 } 142 143 await new Promise(r => { 144 SimpleTest.executeSoon(r); 145 }); 146 147 // Sometimes, the iframe test fails as the child iframe hasn't finishing layout 148 // yet. Try again in this case. 149 while (true) { 150 try { 151 await BrowserTestUtils.synthesizeMouse( 152 test.element, 153 3, 154 3, 155 { type: "contextmenu", button: 2 }, 156 browsingContext 157 ); 158 } catch (ex) { 159 continue; 160 } 161 break; 162 } 163 164 await popupShownPromise; 165 info("onImage: " + gContextMenu.onImage); 166 167 let loadedAfterCommandPromise = test.opensNewTab 168 ? BrowserTestUtils.waitForNewTab(gBrowser, null, true) 169 : BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 170 let popupHiddenPromise = BrowserTestUtils.waitForEvent( 171 contentAreaContextMenu, 172 "popuphidden" 173 ); 174 if (commandToRun == "context-showonlythisframe") { 175 let subMenu = document.getElementById("frame"); 176 let subMenuShown = BrowserTestUtils.waitForEvent(subMenu, "popupshown"); 177 subMenu.openMenu(true); 178 await subMenuShown; 179 } 180 contentAreaContextMenu.activateItem(document.getElementById(commandToRun)); 181 let result = await loadedAfterCommandPromise; 182 183 await test.verify( 184 test.opensNewTab ? result.linkedBrowser : gBrowser.selectedBrowser 185 ); 186 187 await popupHiddenPromise; 188 189 if (test.opensNewTab) { 190 gBrowser.removeCurrentTab(); 191 } 192 } 193 194 gBrowser.removeCurrentTab(); 195 });