docshell/test/test_bug529119-1.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bug529119-1.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +<title>Test bug 529119</title>
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
     1.9 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +
    1.11 +<script class="testbody" type="text/javascript">
    1.12 +
    1.13 +SimpleTest.waitForExplicitFinish();
    1.14 +
    1.15 +var workingURL = "http://mochi.test:8888/tests/docshell/test/bug529119-window.html";
    1.16 +var faultyURL = "http://some-nonexistent-domain-27489274c892748217cn2384.com/";
    1.17 +
    1.18 +var w = null;
    1.19 +var phase = 0;
    1.20 +var gotWrongPageOnTryAgainClick = false;
    1.21 +
    1.22 +function pollForPage(f, w)
    1.23 +{
    1.24 +  // Start with polling after a delay, we might mistakenly take the current page
    1.25 +  // as an expected one.
    1.26 +  window.setTimeout(function() {
    1.27 +    var iterationsLeft = 200;
    1.28 +    var int = window.setInterval(function() {
    1.29 +      iterationsLeft--;
    1.30 +
    1.31 +      var haveErrorPage = false;
    1.32 +      try {
    1.33 +        var title = w.document.title;
    1.34 +      }
    1.35 +      catch (ex) {
    1.36 +        haveErrorPage = true;
    1.37 +      }
    1.38 +  
    1.39 +      if (iterationsLeft == 0 || haveErrorPage) {
    1.40 +        window.clearInterval(int);
    1.41 +        f(iterationsLeft > 0);
    1.42 +      }
    1.43 +    }, 100);
    1.44 +  }, 1000);
    1.45 +}
    1.46 +
    1.47 +function windowLoaded()
    1.48 +{
    1.49 +  switch (phase)
    1.50 +  {
    1.51 +    case 0:
    1.52 +      /* 2. We have succeededfully loaded a page, now go to a faulty URL */
    1.53 +      window.setTimeout(function() {
    1.54 +        w.location.href = faultyURL;
    1.55 +      }, 0);
    1.56 +    
    1.57 +      phase = 1;
    1.58 +
    1.59 +      pollForPage(function(succeeded) {
    1.60 +        ok(succeeded, "Waiting for error page succeeded");
    1.61 +        
    1.62 +        /* 3. now, while we are on the error page, try to reload it, actually 
    1.63 +           click the "Try Again" button */
    1.64 +        SpecialPowers.wrap(w).location.reload();
    1.65 +
    1.66 +        pollForPage(function(succeeded) {
    1.67 +          ok(succeeded, "Waiting for error page succeeded");
    1.68 +          
    1.69 +          /* 4-finish, check we are still on the error page */
    1.70 +          is(SpecialPowers.wrap(w).location.href, faultyURL, "Is on an error page");
    1.71 +          isnot(SpecialPowers.wrap(w).location.href, workingURL, "Is not on the previous page");
    1.72 +          is(gotWrongPageOnTryAgainClick, false, 
    1.73 +            "Must not get www.example.com page on reload of an error page");
    1.74 +          w.close();
    1.75 +          SimpleTest.finish();
    1.76 +        }, w);
    1.77 +      }, w);
    1.78 +      break;
    1.79 +      
    1.80 +    case 1:
    1.81 +      /* 4-check, we must not get here! */
    1.82 +      gotWrongPageOnTryAgainClick = true;
    1.83 +      break;
    1.84 +  }             
    1.85 +}
    1.86 +
    1.87 +function startTest()
    1.88 +{
    1.89 +  /* 1. load a URL that leads to an error page */
    1.90 +  w = window.open(workingURL);
    1.91 +}
    1.92 +
    1.93 +</script>
    1.94 +</head>
    1.95 +<body onload="startTest();">
    1.96 +</body>
    1.97 +</html>

mercurial