tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_change_crossorigin.html (2423B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=696451
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 696451</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 696451 */
     14 
     15  SimpleTest.waitForExplicitFinish();
     16 
     17  var img = new Image,
     18      canvas = document.createElement("canvas"),
     19      ctx = canvas.getContext("2d"),
     20      src = "http://example.com/tests/dom/html/test/image-allow-credentials.png",
     21      imgDone = false,
     22      imgNotAllowedToLoadDone = false;
     23 
     24  img.src = src;
     25  img.crossOrigin = "Anonymous";
     26 
     27  img.addEventListener("load", function() {
     28    canvas.width = img.width;
     29    canvas.height = img.height;
     30    ctx.drawImage( img, 0, 0 );
     31    try {
     32      canvas.toDataURL("image/png");
     33      ok(true, "Image was refetched with setting crossOrigin.");
     34    } catch (e) {
     35      ok(false, "Image was not refetched after setting crossOrigin.");
     36    }
     37 
     38    imgDone = true;
     39    if (imgDone && imgNotAllowedToLoadDone) {
     40      SimpleTest.finish();
     41    }
     42  });
     43 
     44  img.addEventListener("error", function (event) {
     45    ok(false, "Should be able to load cross origin image with proper headers.");
     46 
     47    imgDone = true;
     48    if (imgDone && imgNotAllowedToLoadDone) {
     49      SimpleTest.finish();
     50    }
     51  });
     52 
     53  var imgNotAllowedToLoad = new Image;
     54 
     55  imgNotAllowedToLoad.src = "http://example.com/tests/dom/html/test/image.png";
     56 
     57  imgNotAllowedToLoad.crossOrigin = "Anonymous";
     58 
     59  imgNotAllowedToLoad.addEventListener("load", function() {
     60      ok(false, "Image should not be allowed to load without " +
     61                "allow-cross-origin-access headers.");
     62 
     63      imgNotAllowedToLoadDone = true;
     64      if (imgDone && imgNotAllowedToLoadDone) {
     65        SimpleTest.finish();
     66      }
     67  });
     68 
     69  imgNotAllowedToLoad.addEventListener("error", function() {
     70      ok(true, "Image should not be allowed to load without " +
     71               "allow-cross-origin-access headers.");
     72      imgNotAllowedToLoadDone = true;
     73      if (imgDone && imgNotAllowedToLoadDone) {
     74        SimpleTest.finish();
     75      }
     76  });
     77 
     78  </script>
     79 </head>
     80 <body>
     81 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=696451">Mozilla Bug 696451</a>
     82 <p id="display"></p>
     83 <div id="content" style="display: none">
     84 
     85 </div>
     86 <pre id="test">
     87 </pre>
     88 </body>
     89 </html>