dom/tests/mochitest/bugs/test_bug260264.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug260264.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,144 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=260264
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 260264</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <script type="application/javascript" src="utils_bug260264.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=260264">Mozilla Bug 260264</a>
    1.18 +<p id="display">
    1.19 +  <a id="link" href="javascript:(function(){})()">link</a>
    1.20 +</p>
    1.21 +<div id="content" style="display: none">
    1.22 +
    1.23 +</div>
    1.24 +<pre id="test">
    1.25 +<script type="application/javascript">
    1.26 +
    1.27 +/** Test for Bug 260264 **/
    1.28 +
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +/**
    1.32 + * These functions can be called without arguments to retrieve the current
    1.33 + * value of the preference/privilege, or called with a single argument to set
    1.34 + * the preference/privilege to a new value.
    1.35 + *
    1.36 + * In other words, they obey the interface that |hold| expects its |accessor|
    1.37 + * parameter to obey.
    1.38 + */
    1.39 +var popupMax = makePrefAccessor("dom.popup_maximum"),
    1.40 +    popupEvents = makePrefAccessor("dom.popup_allowed_events"),
    1.41 +    blockPopups = makePrefAccessor("dom.disable_open_during_load"),
    1.42 +    ownPopupPriv = makePopupPrivAccessor(location.href);
    1.43 +
    1.44 +var a = $("link"),
    1.45 +    checkOpened = function() { ok(window.open("http://example.com"), "not properly opened") },
    1.46 +    checkBlocked = function() { ok(!window.open("http://example.com"), "not properly blocked") };
    1.47 +
    1.48 +/**
    1.49 + * Intentional popups are not limited by dom.popup_maximum.
    1.50 + */
    1.51 +function testIntentional(event) {
    1.52 +  hold(popupMax, 3, function() {
    1.53 +    send(a, event, checkOpened);
    1.54 +    send(a, event, checkOpened);
    1.55 +    send(a, event, checkOpened);
    1.56 +    send(a, event, checkOpened);
    1.57 +  });
    1.58 +  window.open.close();
    1.59 +}
    1.60 +
    1.61 +/**
    1.62 + * Probably-intentional popups are limited only by dom.popup_maximum, and
    1.63 + * closing the popup window immediately allows another to open.
    1.64 + */
    1.65 +function testProbablyIntentional(event) {
    1.66 +  var max = 3;
    1.67 +  hold(popupMax, max, function() {
    1.68 +    for (var count = 0, n = 0; n < max; n++)
    1.69 +      send(a, event, function() { if (window.open("http://example.com")) count++ });
    1.70 +    send(a, event, checkBlocked);
    1.71 +    window.open.close(1);
    1.72 +    send(a, event, checkOpened);
    1.73 +    send(a, event, checkBlocked);
    1.74 +    send(a, event, checkBlocked);
    1.75 +    window.open.close();
    1.76 +    ok(count > 0, "Windows left open by previous tests?");
    1.77 +    while (count --> 0)
    1.78 +      send(a, event, checkOpened);
    1.79 +    send(a, event, checkBlocked);
    1.80 +  });
    1.81 +  window.open.close();
    1.82 +}
    1.83 +
    1.84 +/**
    1.85 + * Probably-unintentional popups are forbidden entirely.
    1.86 + */
    1.87 +function testProbablyUnintentional(event) {
    1.88 +  hold(popupMax, 2, function() {
    1.89 +    send(a, event, checkBlocked);
    1.90 +  });
    1.91 +  window.open.close();
    1.92 +}
    1.93 +
    1.94 +/**
    1.95 + * Please be patient; run_tests opens/closes a LOT of windows.
    1.96 + */
    1.97 +function run_tests() {
    1.98 +  hold(popupEvents, "click mouseup", function() {
    1.99 +    // Note: UNKNOWN_ACTION is the same as DENY_ACTION.
   1.100 +    hold(ownPopupPriv, DENY_ACTION, function() {
   1.101 +      testIntentional("click");
   1.102 +      testProbablyIntentional("mouseup");
   1.103 +      testProbablyUnintentional("mouseover");
   1.104 +    });
   1.105 +    hold(ownPopupPriv, ALLOW_ACTION, function() {
   1.106 +      testIntentional("click");
   1.107 +      testIntentional("mouseup");
   1.108 +      testProbablyIntentional("mouseover");
   1.109 +    });
   1.110 +  });
   1.111 +
   1.112 +  hold(popupEvents, "click", function() {
   1.113 +    // Note: UNKNOWN_ACTION is the same as DENY_ACTION.
   1.114 +    hold(ownPopupPriv, DENY_ACTION, function() {
   1.115 +      testIntentional("click");
   1.116 +      testProbablyUnintentional("mouseup");
   1.117 +      testProbablyUnintentional("mouseover");
   1.118 +    });
   1.119 +    hold(ownPopupPriv, ALLOW_ACTION, function() {
   1.120 +      testIntentional("click");
   1.121 +      testProbablyIntentional("mouseup");
   1.122 +      testProbablyIntentional("mouseover");
   1.123 +    });
   1.124 +  });
   1.125 +
   1.126 +  window.open.close(); // just in case
   1.127 +}
   1.128 +
   1.129 +function check_sanity() {
   1.130 +  hold(ownPopupPriv, UNKNOWN_ACTION, function(unknown) {
   1.131 +    hold(ownPopupPriv, ALLOW_ACTION, function(allow) {
   1.132 +      is(ownPopupPriv(), allow, "properly set to allow");
   1.133 +    });
   1.134 +    is(ownPopupPriv(), unknown, "properly reset to unknown");
   1.135 +  });
   1.136 +}
   1.137 +
   1.138 +setTimeout(function() {
   1.139 +  check_sanity();
   1.140 +  hold(blockPopups, true, run_tests);
   1.141 +  SimpleTest.finish();
   1.142 +}, 200);
   1.143 +
   1.144 +</script>
   1.145 +</pre>
   1.146 +</body>
   1.147 +</html>

mercurial