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