browser_bug436200.js (1521B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const kTestPage = "https://example.org/browser/dom/html/test/bug436200.html"; 7 8 async function run_test(shouldShowPrompt, msg) { 9 let promptShown = false; 10 11 function commonDialogObserver(subject) { 12 let dialog = subject.Dialog; 13 promptShown = true; 14 dialog.ui.button0.click(); 15 } 16 Services.obs.addObserver(commonDialogObserver, "common-dialog-loaded"); 17 18 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestPage); 19 20 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 21 let form = content.document.getElementById("test_form"); 22 form.submit(); 23 }); 24 Services.obs.removeObserver(commonDialogObserver, "common-dialog-loaded"); 25 26 is(promptShown, shouldShowPrompt, msg); 27 BrowserTestUtils.removeTab(tab); 28 } 29 30 add_task(async function test_prompt() { 31 await run_test(true, "Should show prompt"); 32 }); 33 34 add_task(async function test_noprompt() { 35 await SpecialPowers.pushPrefEnv({ 36 set: [["security.warn_submit_secure_to_insecure", false]], 37 }); 38 await run_test(false, "Should not show prompt"); 39 await SpecialPowers.popPrefEnv(); 40 }); 41 42 add_task(async function test_prompt_modal() { 43 await SpecialPowers.pushPrefEnv({ 44 set: [ 45 [ 46 "prompts.modalType.insecureFormSubmit", 47 Services.prompt.MODAL_TYPE_WINDOW, 48 ], 49 ], 50 }); 51 await run_test(true, "Should show prompt"); 52 await SpecialPowers.popPrefEnv(); 53 });