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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters.html

Issue 1413193010: Add counters for various ways of loading scripts with bad mimetypes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters.html b/third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters.html
new file mode 100644
index 0000000000000000000000000000000000000000..0bff8141012b5375d923efa55b7a69a8dd78b115
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters.html
@@ -0,0 +1,93 @@
+<body>
+<script src="../../../resources/testharness.js"></script>
+<script>
+testRunner.dumpAsText();
+function runScript(name, callback) {
+ var script = document.createElement("script");
+ script.src = name;
+ script.onload = callback;
+ document.head.appendChild(script);
+}
+var increment = 0;
+var SameOriginTextScript = 1066,
+ SameOriginApplicationScript = 1067,
+ SameOriginOtherScript = 1068,
+ CrossOriginTextScript = 1069,
+ CrossOriginApplicationScript = 1070,
+ CrossOriginOtherScript = 1071;
+var counters = [SameOriginTextScript,
+ SameOriginApplicationScript,
+ SameOriginOtherScript,
+ CrossOriginTextScript,
+ CrossOriginApplicationScript,
+ CrossOriginOtherScript];
+function getUseCounters() {
+ return counters.map(counter => window.internals.isUseCounted(document, counter));
+}
+function testCase(test, callback) {
+ var previousCounters = getUseCounters();
+ var previousIncrement = increment;
+ var url = (test.crossOrigin ? "http://localhost:8000" : "") +
+ "/mime/resources/javascript-mimetype.php?mimetype=" + test.mimetype;
+ runScript(url, function() {
+ assert_false(test.expectFailure === true);
+ assert_equals(previousIncrement + 1, increment, "should have run the script");
+ var newCounters = getUseCounters();
+ for (var counter in counters) {
+ if (counters[counter] === test.useCounter) {
+ assert_equals(previousCounters[counter], !!test.secondTime);
+ assert_equals(newCounters[counter], true);
+ } else {
+ assert_equals(previousCounters[counter], newCounters[counter]);
+ }
+ }
+ alert("Correct");
+ callback();
+ });
+ if (test.expectFailure) callback();
+}
+function nextCase(cases, i) {
+ if (i >= cases.length)
+ return function() {};
+ else return function() {
+ testCase(cases[i], nextCase(cases, i + 1));
+ }
+}
+function runTestCases(cases) {
+ nextCase(cases, 0)();
+}
+
+var initialCounters = getUseCounters();
+for (var initialCounter of initialCounters) {
+ assert_false(initialCounter);
+}
+runTestCases([
+ // JS mimetypes don't increment any usecounters
+ { mimetype: 'text/livescript', crossOrigin: false, useCounter: -1 },
+ { mimetype: 'text/jscript', crossOrigin: true, useCounter: -1 },
+ { mimetype: 'application/ecmascript', crossOrigin: false, useCounter: -1 },
+ { mimetype: 'text/ecmascript', crossOrigin: true, useCounter: -1 },
+
+ // Counters are not incremented on invalid use of images
+ { mimetype: 'image/foo', crossOrigin: false, useCounter: -1, expectFailure: true },
+ { mimetype: 'image/bar', crossOrigin: true, useCounter: -1, expectFailure: true },
+
+ // Text mimetypes are registered separately
+ { mimetype: 'text/html', crossOrigin: false, useCounter: SameOriginTextScript },
+ { mimetype: 'text/csv', crossOrigin: false, useCounter: SameOriginTextScript, secondTime: true },
+
+ { mimetype: 'text/html', crossOrigin: true, useCounter: CrossOriginTextScript },
+ { mimetype: 'text/csv', crossOrigin: true, useCounter: CrossOriginTextScript , secondTime: true },
+
+ { mimetype: 'foo/html', crossOrigin: false, useCounter: SameOriginOtherScript },
+ { mimetype: 'foo/csv', crossOrigin: false, useCounter: SameOriginOtherScript, secondTime: true },
+
+ { mimetype: 'foo/html', crossOrigin: true, useCounter: CrossOriginOtherScript },
+ { mimetype: 'foo/csv', crossOrigin: true, useCounter: CrossOriginOtherScript, secondTime: true },
+
+ { mimetype: 'application/csv', crossOrigin: false, useCounter: SameOriginApplicationScript },
+
+ { mimetype: 'application/csv', crossOrigin: true, useCounter: CrossOriginApplicationScript },
+]);
+</script>
+</body>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/mime/javascript-mimetype-usecounters-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698