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

Side by Side Diff: chrome/test/data/extensions/platform_apps/iframes/main.js

Issue 2775953002: Some cleanup of app and extension CSP tests.
Patch Set: Created 3 years, 9 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
« no previous file with comments | « chrome/test/data/extensions/api_test/sandboxed_pages_csp/sandboxed.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 chrome.test.getConfig(function(config) { 5 chrome.test.getConfig(function(config) {
6 var LOCAL_URL = 'local-iframe.html'; 6 var LOCAL_URL = 'local-iframe.html';
7 var DATA_URL = 'data:text/plain,This frame should be displayed.'; 7 var DATA_URL = 'data:text/plain,This frame should be displayed.';
8 var REMOTE_URL = 'http://localhost:' + config.testServer.port 8 var REMOTE_URL = 'http://localhost:' + config.testServer.port
9 '/extensions/platform_apps/iframes/remote-iframe.html'; 9 '/extensions/platform_apps/iframes/remote-iframe.html';
10 10
11 function onEvent(target, event_name) {
12 return new Promise((resolve, reject) => {
13 target.addEventListener(event_name, resolve);
14 });
15 }
16
17 function onCspViolation(url) {
18 return onEvent(window, 'securitypolicyviolation').then(event => {
19 chrome.test.assertEq(url, event.blockedURI);
20 });
21 }
22
11 chrome.test.runTests([ 23 chrome.test.runTests([
12 function localIframe() { 24 function localIframe() {
13 var iframe = document.createElement('iframe'); 25 var iframe = document.createElement('iframe');
14 iframe.onload = chrome.test.callbackPass(function() { 26 iframe.src = LOCAL_URL;
27
28 // Expect this to load normally.
29 onEvent(iframe, 'load').then(() => {
15 console.log('Local iframe loaded'); 30 console.log('Local iframe loaded');
31 chrome.test.succeed();
16 }); 32 });
17 iframe.src = LOCAL_URL; 33
18 document.body.appendChild(iframe); 34 document.body.appendChild(iframe);
19 }, 35 },
20 36
21 function dataUrlIframe() { 37 function dataUrlIframe() {
22 var iframe = document.createElement('iframe'); 38 var iframe = document.createElement('iframe');
23 iframe.onload = chrome.test.callbackPass(function() { 39 iframe.src = DATA_URL;
40
41 // Expect this to load normally.
42 onEvent(iframe, 'load').then(() => {
24 console.log('data: URL iframe loaded'); 43 console.log('data: URL iframe loaded');
44 chrome.test.succeed();
25 }); 45 });
26 iframe.src = DATA_URL; 46
27 document.body.appendChild(iframe); 47 document.body.appendChild(iframe);
28 }, 48 },
29 49
30 function filesystemUrlIframe() { 50 function filesystemUrlIframe() {
31 var iframe = document.createElement('iframe'); 51 var iframe = document.createElement('iframe');
32 iframe.onload = chrome.test.callbackPass(function() { 52
33 console.log('filesystem: URL iframe loaded'); 53 // The filesystem: document should load and postMessage back.
34 }); 54 Promise.all([onEvent(iframe, 'load'), onEvent(window, 'message')])
55 .then(chrome.test.succeed);
56
57 var blob = new Blob(['This filesystem: frame should be displayed',
58 '<script src="', document.origin, '/post_to_parent.js"></scri',
59 'pt>'], {type: 'text/html'});
35 60
36 webkitRequestFileSystem( 61 webkitRequestFileSystem(
37 window.TEMPORARY, 62 window.TEMPORARY,
38 1024, 63 1024,
39 function(fs) { 64 function(fs) {
40 fs.root.getFile( 65 fs.root.getFile(
41 'test.html', 66 'test.html',
42 {create: true, exclusive: false}, 67 {create: true, exclusive: false},
43 function(fileEntry) { 68 function(fileEntry) {
44 fileEntry.createWriter(function(fileWriter) { 69 fileEntry.createWriter(function(fileWriter) {
45 fileWriter.onwriteend = function(e) { 70 fileWriter.onwriteend = function(e) {
46 var url = fileEntry.toURL(); 71 var url = fileEntry.toURL();
47 chrome.test.assertEq(0, url.indexOf('filesystem:')); 72 chrome.test.assertEq(0, url.indexOf('filesystem:'));
48 iframe.src = url; 73 iframe.src = url;
49 document.body.appendChild(iframe); 74 document.body.appendChild(iframe);
50 }; 75 };
51 76
52 var blob = new Blob(['This frame should be displayed'],
53 {type: 'text/html'});
54 fileWriter.write(blob); 77 fileWriter.write(blob);
55 }); 78 });
56 }); 79 });
57 }); 80 });
58 }, 81 },
59 82
60 function blobUrlIframe() { 83 function blobUrlIframe() {
61 var blob = new Blob(['This frame should be displayed'], 84 var iframe = document.createElement('iframe');
62 {type: 'text/html'}); 85
86 // The blob: document should load and postMessage back.
87 Promise.all([onEvent(iframe, 'load'), onEvent(window, 'message')])
88 .then(chrome.test.succeed);
89
90 var blob = new Blob(['This blob: frame should be displayed',
91 '<script src="', document.origin, '/post_to_parent.js"></scri',
92 'pt>'], {type: 'text/html'});
63 var blobUrl = window.URL.createObjectURL(blob); 93 var blobUrl = window.URL.createObjectURL(blob);
64 var iframe = document.createElement('iframe'); 94
65 iframe.onload = chrome.test.callbackPass(function() {
66 console.log('blob: URL iframe loaded');
67 });
68 iframe.src = blobUrl; 95 iframe.src = blobUrl;
69 document.body.appendChild(iframe); 96 document.body.appendChild(iframe);
70 }, 97 },
71 98
72 function remoteIframe() { 99 function remoteIframe() {
73 var iframe = document.createElement('iframe'); 100 var iframe = document.createElement('iframe');
74 iframe.src = REMOTE_URL; 101 iframe.src = REMOTE_URL;
102
103 // Expect this to be blocked by the CSP.
104 onCspViolation(REMOTE_URL).then(chrome.test.succeed);
105
75 document.body.appendChild(iframe); 106 document.body.appendChild(iframe);
76 107 },
77 // Load failure should happen synchronously, but wait a bit before
78 // declaring success.
79 setTimeout(chrome.test.succeed, 500);
80 }
81 ]); 108 ]);
82 }); 109 });
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/sandboxed_pages_csp/sandboxed.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698