docshell/test/test_bug529119-1.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.

     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 gotWrongPageOnTryAgainClick = false;
    19 function pollForPage(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 || haveErrorPage) {
    37         window.clearInterval(int);
    38         f(iterationsLeft > 0);
    39       }
    40     }, 100);
    41   }, 1000);
    42 }
    44 function windowLoaded()
    45 {
    46   switch (phase)
    47   {
    48     case 0:
    49       /* 2. We have succeededfully loaded a page, now go to a faulty URL */
    50       window.setTimeout(function() {
    51         w.location.href = faultyURL;
    52       }, 0);
    54       phase = 1;
    56       pollForPage(function(succeeded) {
    57         ok(succeeded, "Waiting for error page succeeded");
    59         /* 3. now, while we are on the error page, try to reload it, actually 
    60            click the "Try Again" button */
    61         SpecialPowers.wrap(w).location.reload();
    63         pollForPage(function(succeeded) {
    64           ok(succeeded, "Waiting for error page succeeded");
    66           /* 4-finish, check we are still on the error page */
    67           is(SpecialPowers.wrap(w).location.href, faultyURL, "Is on an error page");
    68           isnot(SpecialPowers.wrap(w).location.href, workingURL, "Is not on the previous page");
    69           is(gotWrongPageOnTryAgainClick, false, 
    70             "Must not get www.example.com page on reload of an error page");
    71           w.close();
    72           SimpleTest.finish();
    73         }, w);
    74       }, w);
    75       break;
    77     case 1:
    78       /* 4-check, we must not get here! */
    79       gotWrongPageOnTryAgainClick = true;
    80       break;
    81   }             
    82 }
    84 function startTest()
    85 {
    86   /* 1. load a URL that leads to an error page */
    87   w = window.open(workingURL);
    88 }
    90 </script>
    91 </head>
    92 <body onload="startTest();">
    93 </body>
    94 </html>

mercurial