Bug 664299 - Test loading cross-domain images validated with CORS in WebGL. r=bz
authorBenoit Jacob <bjacob@mozilla.com>
Thu, 14 Jul 2011 14:47:39 -0400
changeset 72834 255eaf3959f59efd1d4ee76064e6eb00ae235d94
parent 72833 1d535d70b54d216cf2d3bd7f7b7b1ba0224bbdec
child 72835 d50618fed642458e81415f8a2f9811773f7d00fe
push id20776
push usereakhgari@mozilla.com
push dateFri, 15 Jul 2011 12:13:35 +0000
treeherdermozilla-central@9349ae9094f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs664299
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 664299 - Test loading cross-domain images validated with CORS in WebGL. r=bz
content/canvas/test/webgl/Makefile.in
content/canvas/test/webgl/crossorigin/image-allow-credentials.png
content/canvas/test/webgl/crossorigin/image-allow-credentials.png^headers^
content/canvas/test/webgl/crossorigin/image-allow-star.png
content/canvas/test/webgl/crossorigin/image-allow-star.png^headers^
content/canvas/test/webgl/crossorigin/image.png
content/canvas/test/webgl/crossorigin/test_webgl_crossorigin_textures.html
--- a/content/canvas/test/webgl/Makefile.in
+++ b/content/canvas/test/webgl/Makefile.in
@@ -51,9 +51,10 @@ include $(topsrcdir)/config/rules.mk
   failing_tests_mac.txt \
   $(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 	$(TAR) -cf - -C $(srcdir) \
 	  resources \
 	  conformance \
+          crossorigin \
 	  | $(TAR) -xf - -C $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
index 0000000000000000000000000000000000000000..df24ac6d3404325e473981930ade85065cf7fb9a
GIT binary patch
literal 844
zc$@)D1GD^zP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004b3#c}2nYxW
zd<bN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UMnLSTYXW|E5l
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/webgl/crossorigin/image-allow-credentials.png^headers^
@@ -0,0 +1,2 @@
+Access-Control-Allow-Origin: http://mochi.test:8888
+Access-Control-Allow-Credentials: true
new file mode 100644
index 0000000000000000000000000000000000000000..df24ac6d3404325e473981930ade85065cf7fb9a
GIT binary patch
literal 844
zc$@)D1GD^zP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004b3#c}2nYxW
zd<bNS00009a7bBm000j<000lL0ajJ30{{R5?ny*JR5*=wlU-<Abr{Bf|C4iak|t@k
znyz1_UD|b9CpwyStJbl)wOETfHyJ}l1+P@RQUvu%@X{{?1uq7I;FT95IyVX`Q#a>W
zH*l4W#u<{PNz9VwG#}^W<0L1?t5qG#bM^8*@B6!Y9%v)~sZWR7dH<ET*YfDQ-@UD+
zw7tRIec8-L-Mt*iY#7<fwOXnA4VT_5w*{yN-Ve=&dp<aHa{PEAtBZKDNbK(-ZdJzT
zQE|zVCdrO>&b>bO@tq&Xo#Dw37Y`VD<Kh#CN5=CNOJw5(mJ@jtVdL&l@%vOP8+RtJ
z&-?ctbLE%5`f(HR;<r~jN?H9E>*5zZgOd|P&R*cpRtL#MfnqdAF}{lF@u3x}h-M2d
zU7YIQ_0*!aayBIc)N=ZX)vMQouRK=b_uDDdE|ux^&sgX-sRT#)>9+`tv>+u9Av<NN
zH&!Lt?|m7#A_FWft?lnDrFrzFXYnVh40Oei?E%6Er;(c#UOh3uYp1VZ$RV^?8d?IO
zDEj~*0VGy(s>c)Hp(D?+Cny*kpJ8n71zf|E=pEaMtqb<=?8Ppd$Yvc+rx&+J-U2uz
z01;V>&4(3AT8;+~%~LWAvbi!#=YJ*{T_H3YWP0WZTfGgoZNHzEaIlfcn1GN0gvI&w
zN*BH@U5I9l(LEzH^a4Bj2BEHF*LCd5I_~5-jNVg74nf&4Qh?<EFpbN})LQ@3xyYIR
zPFdqVpMu9JgK1#b%Gh-smzibpQk|8wO3N~-=l=MzS&e?b86;Qt!jxiGerS~A%I*=R
z@yu+m{`kRAU~H&cxUnde8-y2rWyAE+vdmhoa`|B>T>oDZ72o0K<(7D_Y2>a+IG1f<
z1;P(F$7ZLt?Xv8?z$c&I5RxR>Mm_V9#b0j#*4<qY;N0P0I3(fi5l8`OIrdGA%|vgd
z<`k!+naSNcZ4rM9(A$>jU)YfP$i(Ean>QmzT`s3}TZ?`T+8Lm6&oZ?KZQix+Hva+S
WQ#UA?9#7r?0000<MNUMnLSTYXW|E5l
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/webgl/crossorigin/image-allow-star.png^headers^
@@ -0,0 +1,1 @@
+Access-Control-Allow-Origin: *
new file mode 100644
index 0000000000000000000000000000000000000000..df24ac6d3404325e473981930ade85065cf7fb9a
GIT binary patch
literal 844
zc$@)D1GD^zP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004b3#c}2nYxW
zd<bNS00009a7bBm000j<000lL0ajJ30{{R5?ny*JR5*=wlU-<Abr{Bf|C4iak|t@k
znyz1_UD|b9CpwyStJbl)wOETfHyJ}l1+P@RQUvu%@X{{?1uq7I;FT95IyVX`Q#a>W
zH*l4W#u<{PNz9VwG#}^W<0L1?t5qG#bM^8*@B6!Y9%v)~sZWR7dH<ET*YfDQ-@UD+
zw7tRIec8-L-Mt*iY#7<fwOXnA4VT_5w*{yN-Ve=&dp<aHa{PEAtBZKDNbK(-ZdJzT
zQE|zVCdrO>&b>bO@tq&Xo#Dw37Y`VD<Kh#CN5=CNOJw5(mJ@jtVdL&l@%vOP8+RtJ
z&-?ctbLE%5`f(HR;<r~jN?H9E>*5zZgOd|P&R*cpRtL#MfnqdAF}{lF@u3x}h-M2d
zU7YIQ_0*!aayBIc)N=ZX)vMQouRK=b_uDDdE|ux^&sgX-sRT#)>9+`tv>+u9Av<NN
zH&!Lt?|m7#A_FWft?lnDrFrzFXYnVh40Oei?E%6Er;(c#UOh3uYp1VZ$RV^?8d?IO
zDEj~*0VGy(s>c)Hp(D?+Cny*kpJ8n71zf|E=pEaMtqb<=?8Ppd$Yvc+rx&+J-U2uz
z01;V>&4(3AT8;+~%~LWAvbi!#=YJ*{T_H3YWP0WZTfGgoZNHzEaIlfcn1GN0gvI&w
zN*BH@U5I9l(LEzH^a4Bj2BEHF*LCd5I_~5-jNVg74nf&4Qh?<EFpbN})LQ@3xyYIR
zPFdqVpMu9JgK1#b%Gh-smzibpQk|8wO3N~-=l=MzS&e?b86;Qt!jxiGerS~A%I*=R
z@yu+m{`kRAU~H&cxUnde8-y2rWyAE+vdmhoa`|B>T>oDZ72o0K<(7D_Y2>a+IG1f<
z1;P(F$7ZLt?Xv8?z$c&I5RxR>Mm_V9#b0j#*4<qY;N0P0I3(fi5l8`OIrdGA%|vgd
z<`k!+naSNcZ4rM9(A$>jU)YfP$i(Ean>QmzT`s3}TZ?`T+8Lm6&oZ?KZQix+Hva+S
WQ#UA?9#7r?0000<MNUMnLSTYXW|E5l
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/webgl/crossorigin/test_webgl_crossorigin_textures.html
@@ -0,0 +1,137 @@
+<!DOCTYPE HTML>
+<title>WebGL cross-origin textures test</title>
+<script src="/MochiKit/MochiKit.js"></script>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<body>
+<canvas id="canvas" style="border: none;" width="100" height="100">
+  <p class="fallback"> FAIL (fallback content) </p>
+</canvas>
+<script>
+
+  SimpleTest.waitForExplicitFinish();
+
+  const SECURITY_ERR = 0x805303e8;
+  const OK = 0;
+
+  var gl;
+  var number_of_tests_live = 0;
+  var all_tests_started = false;
+
+  function nameForErrorCode(code) {
+    switch(code) {
+      case OK: return "no error";
+      case SECURITY_ERR: return "security error";
+    }
+    return "unexpected error (" + code + ")";
+  }
+
+  function verifyError(actual_error, expected_error, message) {
+    ok(actual_error == expected_error,
+       message + ": expected " + nameForErrorCode(expected_error)
+               + ", got " + nameForErrorCode(actual_error));
+  }
+
+  function testTexture(url, crossOriginAttribute, expected_result) {
+    number_of_tests_live++;
+    var image = new Image();
+    if (crossOriginAttribute != "leave-default-crossOrigin-attribute")
+      image.crossOrigin = crossOriginAttribute;
+
+    function testDone() {
+      number_of_tests_live--;
+        
+      if (number_of_tests_live == 0 && all_tests_started)
+        SimpleTest.finish();
+    }
+
+    image.onload = function() {
+      var tex = gl.createTexture();
+      gl.bindTexture(gl.TEXTURE_2D, tex);
+      var actual_result = OK;
+      try {
+        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
+      } catch(e) {
+        actual_result = e.result;
+      }
+      verifyError(actual_result, expected_result, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin);
+
+      testDone();
+    };
+
+    image.onerror = function(event) {
+      ok(expected_result != OK, "Got an error but expected OK!");
+
+      testDone();
+    }
+
+    image.src = url;
+  }
+
+  MochiKit.DOM.addLoadEvent(function () {
+    var canvas = document.getElementById("canvas");
+    try {
+      gl = canvas.getContext("experimental-webgl");
+    } catch (e) {
+      SimpleTest.finish();
+      return;
+    }
+
+    testTexture("http://mochi.test:8888/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "leave-default-crossOrigin-attribute",
+                OK);
+
+    testTexture("http://mochi.test:8888/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "",
+                OK);
+
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "leave-default-crossOrigin-attribute",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "",
+                SECURITY_ERR);
+
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-star.png",
+                "leave-default-crossOrigin-attribute",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-star.png",
+                "",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-star.png",
+                "anonymous",
+                OK);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-star.png",
+                "use-credentials",
+                SECURITY_ERR);
+
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-credentials.png",
+                "leave-default-crossOrigin-attribute",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-credentials.png",
+                "",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-credentials.png",
+                "anonymous",
+                OK);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-credentials.png",
+                "use-credentials",
+                OK);
+
+    // Test that bad values for crossorigin="..." are interpreted as default.
+    testTexture("http://mochi.test:8888/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "foobar",
+                OK);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image.png",
+                "foobar",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-star.png",
+                "foobar",
+                SECURITY_ERR);
+    testTexture("http://example.com/tests/content/canvas/test/webgl/crossorigin/image-allow-credentials.png",
+                "foobar",
+                SECURITY_ERR);
+
+    all_tests_started = true;
+  });
+</script>