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

Side by Side Diff: content/test/data/cross_site_iframe_factory.html

Issue 2855973005: Update tests for snapshot allowfullscreen behavior (Closed)
Patch Set: Update docs Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 <html> 1 <html>
2 <!-- This page can create whatever iframe structure you want, across whatever 2 <!-- This page can create whatever iframe structure you want, across whatever
3 sites you want. This is useful for testing site isolation. 3 sites you want. This is useful for testing site isolation.
4 4
5 Example usage in a browsertest, explained: 5 Example usage in a browsertest, explained:
6 6
7 GURL url = embedded_test_server()-> 7 GURL url = embedded_test_server()->
8 GetURL("a.com", "/cross_site_iframe_factory.html?a(b(c,d))"); 8 GetURL("a.com", "/cross_site_iframe_factory.html?a(b(c,d))");
9 9
10 When you navigate to the above URL, the outer document (on a.com) will create a 10 When you navigate to the above URL, the outer document (on a.com) will create a
11 single iframe: 11 single iframe:
12 12
13 <iframe src="http://b.com:1234/cross_site_iframe_factory.html?b(c(),d())"> 13 <iframe src="http://b.com:1234/cross_site_iframe_factory.html?b(c(),d())">
14 14
15 Inside of which, then, are created the two leaf iframes: 15 Inside of which, then, are created the two leaf iframes:
16 16
17 <iframe src="http://c.com:1234/cross_site_iframe_factory.html?c()"> 17 <iframe src="http://c.com:1234/cross_site_iframe_factory.html?c()">
18 <iframe src="http://d.com:1234/cross_site_iframe_factory.html?d()"> 18 <iframe src="http://d.com:1234/cross_site_iframe_factory.html?d()">
19 19
20 Add iframe options by enclosing them in '{' and '}' characters after the
21 hostname (multiple options can be separated with commas):
22
23 cross_site_iframe_factory.html?a(b{allowfullscreen}(),c{sandbox-allow-scripts} (d))
24
25 Will create two iframes:
26
27 <iframe src="http://a.com:1234/cross_site_iframe_factory.html?b()" allowfullsc reen>
28 <iframe src="http://c.com:1234/cross_site_iframe_factory.html?c{sandbox-allow- scripts}(d())" sandbox="allow-scripts">
29
30 These options are supported:
31
32 allowfullscreen
33 allowpaymentrequest
34 allow-{featurename} - Adds {featurename} to the "allow" attribute
35 sandbox-{flagname} - Adds {flagname} to the "sandbox" attribute
36
20 To make this page work, your browsertest needs a MockHostResolver, like: 37 To make this page work, your browsertest needs a MockHostResolver, like:
21 38
22 void SetUpOnMainThread() override { 39 void SetUpOnMainThread() override {
23 host_resolver()->AddRule("*", "127.0.0.1"); 40 host_resolver()->AddRule("*", "127.0.0.1");
24 ASSERT_TRUE(embedded_test_server()->Start()); 41 ASSERT_TRUE(embedded_test_server()->Start());
25 } 42 }
26 43
27 You can play around with the arguments by loading this page via file://, but 44 You can play around with the arguments by loading this page via file://, but
28 you probably won't get the same process behavior as if you loaded via http. --> 45 you probably won't get the same process behavior as if you loaded via http. -->
29 <head> 46 <head>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 * This cuts down on noise in the query string, letting you use single-letter 102 * This cuts down on noise in the query string, letting you use single-letter
86 * names. 103 * names.
87 */ 104 */
88 function canonicalizeSite(siteString) { 105 function canonicalizeSite(siteString) {
89 if (siteString.indexOf('.') == -1) 106 if (siteString.indexOf('.') == -1)
90 return siteString + '.com'; 107 return siteString + '.com';
91 return siteString; 108 return siteString;
92 } 109 }
93 110
94 /** 111 /**
112 * Parses the list of iframe options and applies them to the provided element.
113 */
114 function applyIFrameOptions(element, options) {
115 var sandboxArguments = [];
116 var allowFeatures = [];
117 for (var option of options) {
118 if (option == "allowfullscreen") {
119 element.allowFullscreen = true;
120 }
121 if (option == "allowpaymentrequest") {
122 element.allowPaymentRequest = true;
123 }
124 if (option.startsWith("sandbox-")) {
125 sandboxArguments.push(option.slice(8));
126 }
127 if (option.startsWith("allow-")) {
128 allowFeatures.push(option.slice(6))
129 }
130 }
131 if (sandboxArguments.length) {
132 element.sandbox = sandboxArguments.join(" ");
133 }
134 if (allowFeatures.length) {
135 element.allow = allowFeatures.join(" ");
136 }
137 }
138
139 /**
95 * Simple recursive layout heuristic, since frames can't size themselves. 140 * Simple recursive layout heuristic, since frames can't size themselves.
96 * This scribbles .layoutX and .layoutY properties into |tree|. 141 * This scribbles .layoutX and .layoutY properties into |tree|.
97 */ 142 */
98 function layout(tree) { 143 function layout(tree) {
99 // Step 1: layout children. 144 // Step 1: layout children.
100 var numFrames = tree.children.length; 145 var numFrames = tree.children.length;
101 for (var i = 0; i < numFrames; i++) { 146 for (var i = 0; i < numFrames; i++) {
102 layout(tree.children[i]); 147 layout(tree.children[i]);
103 } 148 }
104 149
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 181
137 // Apply style to the current document. 182 // Apply style to the current document.
138 document.getElementById('siteNameHeading').appendChild( 183 document.getElementById('siteNameHeading').appendChild(
139 document.createTextNode(currentSite)); 184 document.createTextNode(currentSite));
140 document.body.style.backgroundColor = backgroundColorForSite(currentSite); 185 document.body.style.backgroundColor = backgroundColorForSite(currentSite);
141 186
142 // Determine how big the children should be (using a very rough heuristic). 187 // Determine how big the children should be (using a very rough heuristic).
143 layout(frameTree); 188 layout(frameTree);
144 189
145 for (var i = 0; i < frameTree.children.length; i++) { 190 for (var i = 0; i < frameTree.children.length; i++) {
146 // Compute the URL for this iframe . 191 // Compute the URL for this iframe.
147 var site = canonicalizeSite(frameTree.children[i].value); 192 var site = canonicalizeSite(frameTree.children[i].value);
148 var subtreeString = TreeParserUtil.flatten(frameTree.children[i]); 193 var subtreeString = TreeParserUtil.flatten(frameTree.children[i]);
149 var url = ''; 194 var url = '';
150 url += window.location.protocol + '//'; // scheme (preserved) 195 url += window.location.protocol + '//'; // scheme (preserved)
151 url += goCrossSite ? site : window.location.host; // host 196 url += goCrossSite ? site : window.location.host; // host
152 if (window.location.port) 197 if (window.location.port)
153 url += ':' + window.location.port; // port (preserved) 198 url += ':' + window.location.port; // port (preserved)
154 url += window.location.pathname; // path (preserved) 199 url += window.location.pathname; // path (preserved)
155 url += '?' + encodeURIComponent(subtreeString); // query 200 url += '?' + encodeURIComponent(subtreeString); // query
156 201
157 // Add the iframe to the document. 202 // Construct the iframe.
158 var iframe = document.createElement('iframe'); 203 var iframe = document.createElement('iframe');
159 iframe.src = url; 204 iframe.src = url;
160 iframe.id = "child-" + i; 205 iframe.id = "child-" + i;
161 iframe.style.borderColor = borderColorForSite(site); 206 iframe.style.borderColor = borderColorForSite(site);
162 iframe.width = frameTree.children[i].layoutX; 207 iframe.width = frameTree.children[i].layoutX;
163 iframe.height = frameTree.children[i].layoutY; 208 iframe.height = frameTree.children[i].layoutY;
209 // Apply any additional attributes.
210 applyIFrameOptions(iframe, frameTree.children[i].attributes);
211
212 // Add the iframe to the document.
164 document.body.appendChild(iframe); 213 document.body.appendChild(iframe);
165 } 214 }
166 } 215 }
167 216
168 main(); 217 main();
169 </script> 218 </script>
170 </body></html> 219 </body></html>
OLDNEW
« no previous file with comments | « chrome/browser/site_per_process_interactive_browsertest.cc ('k') | content/test/data/tree_parser_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698