docshell/test/test_bug529119-2.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bug529119-2.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     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 isWindowLoaded = false;
    1.21 +
    1.22 +function pollForPage(expectErrorPage, 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 || expectErrorPage == 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 +  // The code under here should only be run once
    1.50 +  // The test popup window workingURL was already opened
    1.51 +  if (isWindowLoaded)
    1.52 +    return;
    1.53 +  isWindowLoaded = true;
    1.54 +
    1.55 +  /* 2. We have successfully loaded a page, now go to a faulty URL */
    1.56 +  // XXX The test fails when we change the location synchronously 
    1.57 +  window.setTimeout(function() {
    1.58 +    w.location.href = faultyURL;
    1.59 +  }, 0);
    1.60 +
    1.61 +  pollForPage(true, function(succeeded) {
    1.62 +    ok(succeeded, "Waiting for error page succeeded");
    1.63 +    /* 3. now, while we are on the error page, navigate back */
    1.64 +    try {
    1.65 +      SpecialPowers.wrap(w).back();
    1.66 +    }
    1.67 +    catch(ex) {
    1.68 +      ok(false, "w.back() threw " + ex);
    1.69 +    }
    1.70 +
    1.71 +    pollForPage(false, function(succeeded) {
    1.72 +      ok(succeeded, "Waiting for original page succeeded");
    1.73 +      /* 4-finish, check we are back at the original page */
    1.74 +      isnot(SpecialPowers.wrap(w).location.href, faultyURL, "Is on an error page");
    1.75 +      is(SpecialPowers.wrap(w).location.href, workingURL, "Is not on the previous page");
    1.76 +      w.close();
    1.77 +      SimpleTest.finish();
    1.78 +    }, w);
    1.79 +  }, w);
    1.80 +}
    1.81 +
    1.82 +function startTest()
    1.83 +{
    1.84 +  /* 1. load a URL that leads to an error page */
    1.85 +  w = window.open(workingURL);
    1.86 +}
    1.87 +
    1.88 +</script>
    1.89 +</head>
    1.90 +<body onload="startTest();">
    1.91 +</body>
    1.92 +</html>

mercurial