toolkit/components/prompts/test/test_bug625187.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Test for Bug 625187</title>
michael@0 4 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7 <script type="text/javascript" src="prompt_common.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 9 <!--
michael@0 10 - Any copyright is dedicated to the Public Domain.
michael@0 11 - http://creativecommons.org/publicdomain/zero/1.0/
michael@0 12 -
michael@0 13 - Contributor(s):
michael@0 14 - Mihai Sucan <mihai.sucan@gmail.com>
michael@0 15 -->
michael@0 16 </head>
michael@0 17 <body onload="runtest()">
michael@0 18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=625187">Mozilla Bug 625187</a>
michael@0 19
michael@0 20 <p><button onclick="alert('hello world')">Button</button></p>
michael@0 21
michael@0 22 <iframe id="iframe_diff_origin" src="http://example.com/tests/toolkit/components/prompts/test/bug625187_iframe.html"></iframe>
michael@0 23
michael@0 24 <iframe id="iframe_same_origin" src="bug625187_iframe.html"></iframe>
michael@0 25
michael@0 26 <pre id="test"></pre>
michael@0 27
michael@0 28 <script class="testbody" type="text/javascript">
michael@0 29 SimpleTest.waitForExplicitFinish();
michael@0 30
michael@0 31 var testNum = 0;
michael@0 32 var dialogNum = 0;
michael@0 33
michael@0 34 function hasTabModalPrompts() {
michael@0 35 var prefName = "prompts.tab_modal.enabled";
michael@0 36 var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services;
michael@0 37 return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
michael@0 38 Services.prefs.getBoolPref(prefName);
michael@0 39 }
michael@0 40
michael@0 41 function runtest()
michael@0 42 {
michael@0 43 isTabModal = hasTabModalPrompts();
michael@0 44
michael@0 45 // This test depends on tab modal prompts being enabled.
michael@0 46 if (!isTabModal) {
michael@0 47 todo(false, "Test disabled when tab modal prompts are not enabled.");
michael@0 48 SimpleTest.finish();
michael@0 49 return;
michael@0 50 }
michael@0 51
michael@0 52 startCallbackTimer();
michael@0 53
michael@0 54 var button = document.querySelector("button");
michael@0 55 dispatchMouseEvent(button, "click");
michael@0 56
michael@0 57 startCallbackTimer();
michael@0 58
michael@0 59 var iframe = document.getElementById("iframe_diff_origin");
michael@0 60 button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
michael@0 61 dispatchMouseEvent(button, "click");
michael@0 62
michael@0 63 startCallbackTimer();
michael@0 64
michael@0 65 iframe = document.getElementById("iframe_same_origin");
michael@0 66 button = iframe.contentWindow.document.getElementById("btn1");
michael@0 67 dispatchMouseEvent(button, "click");
michael@0 68
michael@0 69 startCallbackTimer();
michael@0 70
michael@0 71 button = iframe.contentWindow.document.getElementById("btn2");
michael@0 72 dispatchMouseEvent(button, "click");
michael@0 73
michael@0 74 SimpleTest.finish();
michael@0 75 }
michael@0 76
michael@0 77 function handleDialog(ui)
michael@0 78 {
michael@0 79 dialogNum++;
michael@0 80 if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
michael@0 81 is(ui.infoTitle.getAttribute("hidden"), "true",
michael@0 82 "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
michael@0 83 else if (dialogNum == 2)
michael@0 84 ok(!ui.infoTitle.hasAttribute("hidden"),
michael@0 85 "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
michael@0 86
michael@0 87 synthesizeMouse(ui.button0, 2, 2, {}, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
michael@0 88 }
michael@0 89
michael@0 90 function dispatchMouseEvent(target, type)
michael@0 91 {
michael@0 92 var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
michael@0 93 var e = document.createEvent("MouseEvent");
michael@0 94 e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
michael@0 95 false, false, false, false, 0, null);
michael@0 96 var utils = SpecialPowers.getDOMWindowUtils(win);
michael@0 97 utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e, true);
michael@0 98 }
michael@0 99 </script>
michael@0 100 </body>
michael@0 101 </html>

mercurial