content/canvas/test/crossorigin/test_webgl_crossorigin_textures.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/crossorigin/test_webgl_crossorigin_textures.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<title>WebGL cross-origin textures test</title>
     1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
     1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css">
     1.8 +<body>
     1.9 +<canvas id="canvas" style="border: none;" width="100" height="100">
    1.10 +  <p class="fallback"> FAIL (fallback content) </p>
    1.11 +</canvas>
    1.12 +<script>
    1.13 +
    1.14 +  SimpleTest.waitForExplicitFinish();
    1.15 +
    1.16 +  const OK = "";
    1.17 +
    1.18 +  var gl;
    1.19 +  var number_of_tests_live = 0;
    1.20 +  var all_tests_started = false;
    1.21 +
    1.22 +  function verifyError(actual_error, expected_error, message) {
    1.23 +    ok(actual_error == expected_error,
    1.24 +       message + ": expected " + expected_error + ", got " + actual_error);
    1.25 +  }
    1.26 +
    1.27 +  function testTexture(url, crossOriginAttribute, expected_error) {
    1.28 +    number_of_tests_live++;
    1.29 +    var image = new Image();
    1.30 +    if (crossOriginAttribute == "just-crossOrigin-without-value") {
    1.31 +      var div = document.createElement('div');
    1.32 +      div.innerHTML="<img crossOrigin>";
    1.33 +      image = div.children[0];
    1.34 +    }
    1.35 +    else if (crossOriginAttribute != "missing-value-default")
    1.36 +      image.crossOrigin = crossOriginAttribute;
    1.37 +    
    1.38 +
    1.39 +    function testDone() {
    1.40 +      number_of_tests_live--;
    1.41 +        
    1.42 +      if (number_of_tests_live == 0 && all_tests_started)
    1.43 +        SimpleTest.finish();
    1.44 +    }
    1.45 +
    1.46 +    image.onload = function() {
    1.47 +      var tex = gl.createTexture();
    1.48 +      gl.bindTexture(gl.TEXTURE_2D, tex);
    1.49 +      var actual_error = OK;
    1.50 +      try {
    1.51 +        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
    1.52 +      } catch(e) {
    1.53 +        actual_error = e.name;
    1.54 +      }
    1.55 +      verifyError(actual_error, expected_error, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin);
    1.56 +
    1.57 +      testDone();
    1.58 +    };
    1.59 +
    1.60 +    image.onerror = function(event) {
    1.61 +      ok(expected_error != OK, "Got an error but expected OK!");
    1.62 +
    1.63 +      testDone();
    1.64 +    }
    1.65 +
    1.66 +    image.src = url;
    1.67 +  }
    1.68 +
    1.69 +  addLoadEvent(function () {
    1.70 +    var canvas = document.getElementById("canvas");
    1.71 +    gl = canvas.getContext("experimental-webgl");
    1.72 +    if (!gl) {
    1.73 +      todo(false, "Canvas WebGL not supported");
    1.74 +      SimpleTest.finish();
    1.75 +      return;
    1.76 +    }
    1.77 +
    1.78 +
    1.79 +    testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png",
    1.80 +                "missing-value-default",
    1.81 +                OK);
    1.82 +    testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png",
    1.83 +                "",
    1.84 +                OK);
    1.85 +    testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png",
    1.86 +                "just-crossOrigin-without-value",
    1.87 +                OK);
    1.88 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
    1.89 +                "missing-value-default",
    1.90 +                "SecurityError");
    1.91 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
    1.92 +                "",
    1.93 +                "SecurityError");
    1.94 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
    1.95 +                "just-crossOrigin-without-value",
    1.96 +                "SecurityError");
    1.97 +
    1.98 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
    1.99 +                "missing-value-default",
   1.100 +                "SecurityError");
   1.101 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
   1.102 +                "",
   1.103 +                OK);
   1.104 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
   1.105 +                "just-crossOrigin-without-value",
   1.106 +                OK);
   1.107 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
   1.108 +                "anonymous",
   1.109 +                OK);
   1.110 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
   1.111 +                "use-credentials",
   1.112 +                "SecurityError");
   1.113 +
   1.114 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.115 +                "missing-value-default",
   1.116 +                "SecurityError");
   1.117 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.118 +                "",
   1.119 +                OK);
   1.120 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.121 +                "just-crossOrigin-without-value",
   1.122 +                OK);
   1.123 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.124 +                "anonymous",
   1.125 +                OK);
   1.126 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.127 +                "use-credentials",
   1.128 +                OK);
   1.129 +
   1.130 +    // Test that bad values for crossorigin="..." are interpreted as invalid-value-default which is "anonymous".
   1.131 +    testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png",
   1.132 +                "foobar",
   1.133 +                OK);
   1.134 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
   1.135 +                "foobar",
   1.136 +                "SecurityError");
   1.137 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
   1.138 +                "foobar",
   1.139 +                OK);
   1.140 +    testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
   1.141 +                "foobar",
   1.142 +                OK);
   1.143 +
   1.144 +    all_tests_started = true;
   1.145 +  });
   1.146 +</script>

mercurial