docshell/test/test_bug529119-2.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial