Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test bug 529119</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 <script class="testbody" type="text/javascript">
10 SimpleTest.waitForExplicitFinish();
12 var workingURL = "http://mochi.test:8888/tests/docshell/test/bug529119-window.html";
13 var faultyURL = "http://some-nonexistent-domain-27489274c892748217cn2384.com/";
15 var w = null;
16 var phase = 0;
17 var isWindowLoaded = false;
19 function pollForPage(expectErrorPage, f, w)
20 {
21 // Start with polling after a delay, we might mistakenly take the current page
22 // as an expected one.
23 window.setTimeout(function() {
24 var iterationsLeft = 200;
25 var int = window.setInterval(function() {
26 iterationsLeft--;
28 var haveErrorPage = false;
29 try {
30 var title = w.document.title;
31 }
32 catch (ex) {
33 haveErrorPage = true;
34 }
36 if (iterationsLeft == 0 || expectErrorPage == haveErrorPage) {
37 window.clearInterval(int);
38 f(iterationsLeft > 0);
39 }
40 }, 100);
41 }, 1000);
42 }
44 function windowLoaded()
45 {
46 // The code under here should only be run once
47 // The test popup window workingURL was already opened
48 if (isWindowLoaded)
49 return;
50 isWindowLoaded = true;
52 /* 2. We have successfully loaded a page, now go to a faulty URL */
53 // XXX The test fails when we change the location synchronously
54 window.setTimeout(function() {
55 w.location.href = faultyURL;
56 }, 0);
58 pollForPage(true, function(succeeded) {
59 ok(succeeded, "Waiting for error page succeeded");
60 /* 3. now, while we are on the error page, navigate back */
61 try {
62 SpecialPowers.wrap(w).back();
63 }
64 catch(ex) {
65 ok(false, "w.back() threw " + ex);
66 }
68 pollForPage(false, function(succeeded) {
69 ok(succeeded, "Waiting for original page succeeded");
70 /* 4-finish, check we are back at the original page */
71 isnot(SpecialPowers.wrap(w).location.href, faultyURL, "Is on an error page");
72 is(SpecialPowers.wrap(w).location.href, workingURL, "Is not on the previous page");
73 w.close();
74 SimpleTest.finish();
75 }, w);
76 }, w);
77 }
79 function startTest()
80 {
81 /* 1. load a URL that leads to an error page */
82 w = window.open(workingURL);
83 }
85 </script>
86 </head>
87 <body onload="startTest();">
88 </body>
89 </html>