michael@0: /* Any copyright is dedicated to the public domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that prompt and confirm work. In particular, we're concerned that we michael@0: // get correct return values out of them. michael@0: // michael@0: // We use alert() to communicate the return values of prompt/confirm back to michael@0: // ourselves. michael@0: "use strict"; michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: browserElementTestHelpers.setEnabledPref(true); michael@0: browserElementTestHelpers.addPermission(); michael@0: michael@0: function runTest() { michael@0: var iframe = document.createElement('iframe'); michael@0: SpecialPowers.wrap(iframe).mozbrowser = true; michael@0: document.body.appendChild(iframe); michael@0: michael@0: var prompts = [ michael@0: {msg: 1, type: 'alert', rv: 42, expected: 'undefined'}, michael@0: {msg: 2, type: 'confirm', rv: true, expected: 'true'}, michael@0: {msg: 3, type: 'confirm', rv: false, expected: 'false'}, michael@0: michael@0: // rv == 42 should be coerced to 'true' for confirm. michael@0: {msg: 4, type: 'confirm', rv: 42, expected: 'true'}, michael@0: {msg: 5, type: 'prompt', rv: 'worked', expected: 'worked'}, michael@0: {msg: 6, type: 'prompt', rv: null, expected: 'null'}, michael@0: {msg: 7, type: 'prompt', rv: '', expected: ''} michael@0: ]; michael@0: michael@0: iframe.addEventListener("mozbrowsershowmodalprompt", function(e) { michael@0: var curPrompt = prompts[0]; michael@0: if (!curPrompt.waitingForResponse) { michael@0: curPrompt.waitingForResponse = true; michael@0: michael@0: is(e.detail.message, curPrompt.msg, "prompt message"); michael@0: is(e.detail.promptType, curPrompt.type, "prompt type"); michael@0: michael@0: if (e.detail.promptType == 'prompt') { michael@0: ok(e.detail.returnValue === null, "prompt's returnValue should be null"); michael@0: is(e.detail.initialValue, "initial", "prompt's initial value."); michael@0: } michael@0: else { michael@0: ok(e.detail.returnValue === undefined, michael@0: "Other than for prompt, shouldn't have initial value."); michael@0: } michael@0: michael@0: // Block the child until we call e.detail.unblock(). michael@0: e.preventDefault(); michael@0: michael@0: SimpleTest.executeSoon(function() { michael@0: e.detail.returnValue = curPrompt.rv; michael@0: e.detail.unblock(); michael@0: }); michael@0: } michael@0: else { michael@0: prompts.shift(); michael@0: michael@0: // |e| now corresponds to an alert() containing the return value we just michael@0: // sent for this prompt. michael@0: michael@0: is(e.detail.message, 'RESULT:' + curPrompt.expected, michael@0: "expected rv for msg " + curPrompt.msg); michael@0: michael@0: if (prompts.length == 0) { michael@0: SimpleTest.finish(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: iframe.src = michael@0: 'data:text/html,