toolkit/components/alerts/test/test_multiple_alerts.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for multiple alerts</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 7 </head>
michael@0 8 <body>
michael@0 9 <pre id="test">
michael@0 10 <script class="testbody" type="text/javascript">
michael@0 11
michael@0 12 const Cc = SpecialPowers.Cc;
michael@0 13 const Ci = SpecialPowers.Ci;
michael@0 14
michael@0 15 const ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
michael@0 16 .getService(Ci.nsIWindowWatcher);
michael@0 17
michael@0 18 function showSimpleAlert(alertService) {
michael@0 19 try {
michael@0 20 alertService.showAlertNotification(null, "title", "body");
michael@0 21 ok(true, "Alert shown.");
michael@0 22 } catch (ex) {
michael@0 23 ok(false, "Failed to show alert.", ex);
michael@0 24 SimpleTest.finish();
michael@0 25 }
michael@0 26 }
michael@0 27
michael@0 28 var firstAlertXPosition = 0;
michael@0 29 var firstAlertYPosition = 0;
michael@0 30
michael@0 31 function showFirstAlert(alertService) {
michael@0 32 // Set a timeout to finish the test in case we are on a platform
michael@0 33 // that doesn't use XUL alert windows. This timeout is cleared
michael@0 34 // when a XUL alert window does get created.
michael@0 35 var timer = setTimeout(function() {
michael@0 36 ok(true, "Platform does not use XUL alerts.");
michael@0 37 ww.unregisterNotification(windowObserver);
michael@0 38 SimpleTest.finish();
michael@0 39 }, 2000);
michael@0 40
michael@0 41 var windowObserver = function(aSubject, aTopic, aData) {
michael@0 42 if (aTopic != "domwindowopened") {
michael@0 43 return;
michael@0 44 }
michael@0 45
michael@0 46 // Alerts are implemented using XUL, clear the timeout
michael@0 47 // that finishes the test.
michael@0 48 clearTimeout(timer);
michael@0 49
michael@0 50 ww.unregisterNotification(windowObserver);
michael@0 51
michael@0 52 var win = SpecialPowers.wrap(aSubject);
michael@0 53 win.addEventListener("pageshow", function() {
michael@0 54 win.removeEventListener("pageshow", arguments.callee, false);
michael@0 55 firstAlertXPosition = win.screenX;
michael@0 56 firstAlertYPosition = win.screenY;
michael@0 57
michael@0 58 // Wait for alert window to close then open a second alert.
michael@0 59 win.addEventListener("pagehide", function() {
michael@0 60 win.removeEventListener("pagehide", arguments.callee, false);
michael@0 61 // Wait for alert to close before creating a new one.
michael@0 62 showSecondAlert(alertService);
michael@0 63 }, false);
michael@0 64
michael@0 65 alertService.closeAlert();
michael@0 66 }, false);
michael@0 67 };
michael@0 68
michael@0 69 ww.registerNotification(windowObserver);
michael@0 70 showSimpleAlert(alertService);
michael@0 71 }
michael@0 72
michael@0 73 function showSecondAlert(alertService) {
michael@0 74 var windowObserver = function(aSubject, aTopic, aData) {
michael@0 75 if (aTopic != "domwindowopened") {
michael@0 76 return;
michael@0 77 }
michael@0 78
michael@0 79 ww.unregisterNotification(windowObserver);
michael@0 80
michael@0 81 var win = SpecialPowers.wrap(aSubject);
michael@0 82 win.addEventListener("pageshow", function() {
michael@0 83 win.removeEventListener("pageshow", arguments.callee, false);
michael@0 84 is(win.screenX, firstAlertXPosition, "Second alert should be opened in the same position.");
michael@0 85 is(win.screenY, firstAlertYPosition, "Second alert should be opened in the same position.");
michael@0 86
michael@0 87 // Wait for alert window to close then finish the test.
michael@0 88 win.addEventListener("pagehide", function() {
michael@0 89 win.removeEventListener("pagehide", arguments.callee, false);
michael@0 90 // Wait for alert to close before finishing the test.
michael@0 91 SimpleTest.finish();
michael@0 92 }, false);
michael@0 93
michael@0 94 alertService.closeAlert();
michael@0 95 }, false);
michael@0 96 };
michael@0 97
michael@0 98 ww.registerNotification(windowObserver);
michael@0 99 showSimpleAlert(alertService);
michael@0 100 }
michael@0 101
michael@0 102 function runTest() {
michael@0 103 if (!("@mozilla.org/alerts-service;1" in Cc)) {
michael@0 104 todo(false, "Alerts service does not exist in this application.");
michael@0 105 return;
michael@0 106 }
michael@0 107
michael@0 108 ok(true, "Alerts service exists in this application.");
michael@0 109
michael@0 110 var alertService;
michael@0 111 try {
michael@0 112 alertService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
michael@0 113 ok(true, "Alerts service is available.");
michael@0 114 } catch (ex) {
michael@0 115 todo(false, "Alerts service is not available.");
michael@0 116 return;
michael@0 117 }
michael@0 118
michael@0 119 SimpleTest.waitForExplicitFinish();
michael@0 120 showFirstAlert(alertService);
michael@0 121 }
michael@0 122
michael@0 123 runTest();
michael@0 124
michael@0 125 </script>
michael@0 126 </pre>
michael@0 127 </body>
michael@0 128 </html>

mercurial