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

Unified Diff: chrome/test/data/cross_site_iframe_factory.html

Issue 1252943009: First stab at a test for site isolation metrics_memory_details (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@histogram_tester3
Patch Set: Created 5 years, 5 months 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: chrome/test/data/cross_site_iframe_factory.html
diff --git a/chrome/test/data/cross_site_iframe_factory.html b/chrome/test/data/cross_site_iframe_factory.html
new file mode 100644
index 0000000000000000000000000000000000000000..934f4f71b803561ed12e1888893ec51282354c9d
--- /dev/null
+++ b/chrome/test/data/cross_site_iframe_factory.html
@@ -0,0 +1,143 @@
+<html>
+<head>
+<title>cross-site iframe factory</title>
+<style>
+body {font-family: Sans-Serif;
+ text-align: center;}
+h1 {color:black}
+h2 {color:black}
+iframe {border-radius: 7px;
+ border-style: solid;
+ vertical-align: top;
+ margin: 2px;
+ }
+</style>
+</head>
+<body>
+<!-- This only works if the CrossSiteRedirector is running on the embedded test
+ server, and the host_resolver is set up to handle b.com. -->
+<script src="cross_site_iframe_factory_parser.js"></script>
+<script type="text/javascript">
+
+function murmurhash3_32_gc(key, seed) {
+ var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;
+
+ remainder = key.length & 3; // key.length % 4
+ bytes = key.length - remainder;
+ h1 = seed;
+ c1 = 0xcc9e2d51;
+ c2 = 0x1b873593;
+ i = 0;
+
+ while (i < bytes) {
+ k1 =
+ ((key.charCodeAt(i) & 0xff)) |
+ ((key.charCodeAt(++i) & 0xff) << 8) |
+ ((key.charCodeAt(++i) & 0xff) << 16) |
+ ((key.charCodeAt(++i) & 0xff) << 24);
+ ++i;
+
+ k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;
+ k1 = (k1 << 15) | (k1 >>> 17);
+ k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;
+
+ h1 ^= k1;
+ h1 = (h1 << 13) | (h1 >>> 19);
+ h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;
+ h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));
+ }
+
+ k1 = 0;
+
+ switch (remainder) {
+ case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
+ case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
+ case 1: k1 ^= (key.charCodeAt(i) & 0xff);
+
+ k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
+ k1 = (k1 << 15) | (k1 >>> 17);
+ k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
+ h1 ^= k1;
+ }
+
+ h1 ^= key.length;
+
+ h1 ^= h1 >>> 16;
+ h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
+ h1 ^= h1 >>> 13;
+ h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
+ h1 ^= h1 >>> 16;
+
+ return h1 >>> 0;
+}
+
+function pastel_color(input_str, gamma) {
+ // Picked by trial and erro so that [a.com ... h.com] are well distributed
+ // in colorspace.
+ var seeded_value = input_str + "14";
+ var hash = murmurhash3_32_gc(seeded_value, 0);
+ var x1 = ((hash >> 00) & 0x3FF) / 0x3FF;
+ var x2 = ((hash >> 10) & 0x3FF) / 0x3FF;
+ var x3 = ((hash >> 20) & 0x3FF) / 0x3FF;
+
+ // Apply gamma for lighter/darker tones.
+ x1 = Math.pow(x1, gamma);
+ x2 = Math.pow(x2, gamma);
+ x3 = Math.pow(x3, gamma);
+
+ // Average the color with the base. This produces pastel-like tones.
+ var alpha = 0.5;
+ var r = Math.round(255 * (alpha * x1 + (1 - alpha)));
+ var g = Math.round(255 * (alpha * x2 + (1 - alpha)));
+ var b = Math.round(255 * (alpha * x3 + (1 - alpha)));
+
+ return "rgb(" + r + ", " + g + ", " + b + ")";
+}
+
+function backgroundColor(input_str) {
+ return pastel_color(input_str, .5);
+}
+function borderColor(input_str) {
+ return pastel_color(input_str, 2);
+}
+
+if (!window.location.protocol.startsWith('http')) {
+ var me = document.createElement('h1');
+ document.body.appendChild(me);
+}
+
+function canonicalizeSite(site_string) {
+ if (site_string.indexOf('.') == -1)
+ return site_string + ".com";
+ return site_string;
+}
+
+var query_string = unescape(window.location.search.substring(1));
+var command = query_parser.parse(query_string);
+
+var me = document.createElement('h2');
+var document_site = canonicalizeSite(command.site);
+me.innerText = document_site;
+document.body.appendChild(me);
+document.body.style.backgroundColor = backgroundColor(document_site);
+
+for (var i = 0; i < command.frames.length; i++) {
+ var go_cross_site = window.location.protocol.startsWith('http');
+ var host = canonicalizeSite(command.frames[i].site);
+ var url = "";
+ url += window.location.protocol + "//"; // scheme (preserved)
+ url += go_cross_site ? host : window.location.host; // host
+ if (window.location.port)
+ url += ":" + window.location.port; // port (preserved)
+ url += "/" + window.location.pathname; // path (preserved)
+ url += "?" + escape(command.frames[i].args); // query
+
+ var iframe = document.createElement('iframe');
+ iframe.src = url;
+ iframe.style.borderColor = borderColor(host);
+ iframe.scrolling = "no";
+ iframe.width = iframe.height = command.frames[i].args.length*25 + 50;
+ document.body.appendChild(iframe);
+}
+</script>
+</body></html>
« no previous file with comments | « chrome/browser/metrics/metrics_memory_details_browsertest.cc ('k') | chrome/test/data/cross_site_iframe_factory_parser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698