From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../mochitest/browserElement_PromptConfirm.js | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 dom/browser-element/mochitest/browserElement_PromptConfirm.js (limited to 'dom/browser-element/mochitest/browserElement_PromptConfirm.js') diff --git a/dom/browser-element/mochitest/browserElement_PromptConfirm.js b/dom/browser-element/mochitest/browserElement_PromptConfirm.js new file mode 100644 index 000000000..c01836a25 --- /dev/null +++ b/dom/browser-element/mochitest/browserElement_PromptConfirm.js @@ -0,0 +1,87 @@ +/* Any copyright is dedicated to the public domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that prompt and confirm work. In particular, we're concerned that we +// get correct return values out of them. +// +// We use alert() to communicate the return values of prompt/confirm back to +// ourselves. +"use strict"; + +SimpleTest.waitForExplicitFinish(); +browserElementTestHelpers.setEnabledPref(true); +browserElementTestHelpers.addPermission(); + +function runTest() { + var iframe = document.createElement('iframe'); + iframe.setAttribute('mozbrowser', 'true'); + document.body.appendChild(iframe); + + var prompts = [ + {msg: '1', type: 'alert', rv: 42, expected: 'undefined'}, + {msg: '2', type: 'confirm', rv: true, expected: 'true'}, + {msg: '3', type: 'confirm', rv: false, expected: 'false'}, + + // rv == 42 should be coerced to 'true' for confirm. + {msg: '4', type: 'confirm', rv: 42, expected: 'true'}, + {msg: '5', type: 'prompt', rv: 'worked', expected: 'worked'}, + {msg: '6', type: 'prompt', rv: null, expected: 'null'}, + {msg: '7', type: 'prompt', rv: '', expected: ''} + ]; + + iframe.addEventListener("mozbrowsershowmodalprompt", function(e) { + var curPrompt = prompts[0]; + if (!curPrompt.waitingForResponse) { + curPrompt.waitingForResponse = true; + + is(e.detail.message, curPrompt.msg, "prompt message"); + is(e.detail.promptType, curPrompt.type, "prompt type"); + + if (e.detail.promptType == 'prompt') { + ok(e.detail.returnValue === null, "prompt's returnValue should be null"); + is(e.detail.initialValue, "initial", "prompt's initial value."); + } + else { + ok(e.detail.returnValue === undefined, + "Other than for prompt, shouldn't have initial value."); + } + + // Block the child until we call e.detail.unblock(). + e.preventDefault(); + + SimpleTest.executeSoon(function() { + e.detail.returnValue = curPrompt.rv; + e.detail.unblock(); + }); + } + else { + prompts.shift(); + + // |e| now corresponds to an alert() containing the return value we just + // sent for this prompt. + + is(e.detail.message, 'RESULT:' + curPrompt.expected, + "expected rv for msg " + curPrompt.msg); + + if (prompts.length == 0) { + SimpleTest.finish(); + } + } + }); + + iframe.src = + 'data:text/html,