Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html

Issue 718633002: Deflake http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix our use of w3 test harness to call done() Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html
diff --git a/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html b/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html
index 749cd821b10e58e9a85d3c8cfc02b4761c3f09b7..b5d4411060da27b37c2830544d67aa9b9d270af7 100644
--- a/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html
+++ b/LayoutTests/http/tests/security/subresourceIntegrity/subresource-integrity-style-blocked.html
@@ -4,26 +4,79 @@
<title>Subresource integrity blocked style resources</title>
<script src="../../resources/testharness.js"></script>
- <link rel="stylesheet" href="style-1-of-3.css" integrity="ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE="></link>
- <link rel="stylesheet" href="style-2-of-3.css" integrity="ni:///sha384;XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA1v5GPr"></link>
- <link rel="stylesheet" href="style-3-of-3.css" integrity="ni:///sha512;tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81ytlg0MPaIrPAjcHqba5csorDWtKg=="></link>
- </head>
- <body>
<script>
- if (window.testRunner)
- testRunner.dumpAsText();
+ var steps = 0;
+ var loaded = 0;
+ var failed = 0;
+
+ function markLoaded() {
+ ++loaded;
+ runNextStep();
+ }
+
+ function markFailed() {
+ ++failed;
+ runNextStep();
+ }
+
+ function insertStylesheetAsLink(cssHref, hash)
+ {
+ var link = document.createElement("link");
+ link.rel = "stylesheet";
+ link.href = cssHref;
+ link.integrity = hash;
+ link.addEventListener('load', markLoaded);
+ link.addEventListener('error', markFailed);
+ document.head.appendChild(link);
+ }
+
+ function runTest()
+ {
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ runNextStep();
+ }
+
+ function runNextStep()
+ {
+ switch (++steps) {
+ case 1:
+ insertStylesheetAsLink("style-1-of-3.css", "ni:///sha256;BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=");
+ break;
+ case 2:
+ insertStylesheetAsLink("style-2-of-3.css", "ni:///sha384;XVVXBGoYw6AJOh9J/Z8pBDMVVPfkBpngexkA7JqZu8d5GENND6TEIup/tA1v5GPr");
+ break;
+ case 3:
+ insertStylesheetAsLink("style-3-of-3.css", "ni:///sha512;tbUPioKbVBplr0b1ucnWB57SJWt4x9dOE0Vy2mzCXvH3FepqDZ+07yMK81ytlg0MPaIrPAjcHqba5csorDWtKg==");
+ break;
+ case 4:
+ finishTest();
+ break;
+ }
+ }
+
+ function finishTest()
+ {
+ var color = window.getComputedStyle(document.querySelector('#p1')).color;
+ assert_not_equals(color, "rgb(0, 128, 0)", "The p#1 element's text should not be green.");
+ color = window.getComputedStyle(document.querySelector('#p2')).color;
+ assert_not_equals(color, "rgb(0, 128, 0)", "The p#2 element's text should not be green.");
+ color = window.getComputedStyle(document.querySelector('#p3')).color;
+ assert_not_equals(color, "rgb(0, 128, 0)", "The p#3 element's text should not be green.");
+ assert_equals(failed, 3, "All stylesheet loads should have failed.");
+ assert_equals(loaded, 0, "All stylesheet loads should have failed.");
+ done();
+ if (window.testRunner)
+ testRunner.notifyDone();
+ }
</script>
+ </head>
+ <body onload="runTest()">
<p id="p1">Test 1</p>
<p id="p2">Test 2</p>
<p id="p3">Test 3</p>
-
- <script>
- var color = window.getComputedStyle(document.querySelector('#p1')).color;
- assert_not_equals(color, "rgb(0, 128, 0)", "The p#1 element's text should not be green.");
- color = window.getComputedStyle(document.querySelector('#p2')).color;
- assert_not_equals(color, "rgb(0, 128, 0)", "The p#2 element's text should not be green.");
- color = window.getComputedStyle(document.querySelector('#p3')).color;
- assert_not_equals(color, "rgb(0, 128, 0)", "The p#3 element's text should not be green.");
- </script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698