CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / docshell / test / test_bug529119-2.html
blob6e106a94c6fa4414f041c7fcffec197d267334be
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test bug 529119</title>
5 <script type="text/javascript" src="/MochiKit/packed.js"></script>
6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
9 <script class="testbody" type="text/javascript">
11 SimpleTest.waitForExplicitFinish();
13 var workingURL = "http://mochi.test:8888/tests/docshell/test/bug529119-window.html";
14 var faultyURL = "http://some-nonexistent-domain-27489274c892748217cn2384.com/";
16 var w = null;
17 var phase = 0;
19 function pollForPage(expectErrorPage, f, w)
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;
32 catch (ex) {
33 haveErrorPage = true;
36 if (iterationsLeft == 0 || expectErrorPage == haveErrorPage) {
37 window.clearInterval(int);
38 f(iterationsLeft > 0);
40 }, 100);
41 }, 1000);
44 function windowLoaded()
46 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
48 /* 2. We have successfully loaded a page, now go to a faulty URL */
49 // XXX The test fails when we change the location synchronously
50 window.setTimeout(function() {
51 w.location.href = faultyURL;
52 }, 0);
54 pollForPage(true, function(succeeded) {
55 ok(succeeded, "Waiting for error page succeeded");
57 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
58 /* 3. now, while we are on the error page, navigate back */
59 try {
60 w.back();
62 catch(ex) {
63 ok(false, "w.back() threw " + ex);
66 pollForPage(false, function(succeeded) {
67 ok(succeeded, "Waiting for original page succeeded");
69 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
70 /* 4-finish, check we are back at the original page */
71 isnot(w.location.href, faultyURL, "Is on an error page");
72 is(w.location.href, workingURL, "Is not on the previous page");
73 w.close();
74 SimpleTest.finish();
75 }, w);
76 }, w);
79 function startTest()
81 /* 1. load a URL that leads to an error page */
82 w = window.open(workingURL);
85 </script>
86 </head>
87 <body onload="startTest();">
88 </body>
89 </html>