Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/web_view/content_script_fetch/content_script.js |
| diff --git a/chrome/test/data/extensions/platform_apps/web_view/content_script_fetch/content_script.js b/chrome/test/data/extensions/platform_apps/web_view/content_script_fetch/content_script.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3ec97f41b215d8744330169a7c8daaadbb828584 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/web_view/content_script_fetch/content_script.js |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var embedder = null; |
| + |
| +function reportResult(result) { |
| + window.console.log('Reporting ' + result + ' to embedder.'); |
| + var msg = ['fetch-' + result]; |
| + embedder.postMessage(JSON.stringify(msg), '*'); |
| +} |
| + |
| +window.addEventListener('message', function(e) { |
| + window.console.log('Content script received message.') |
| + embedder = e.source; |
| + var data = JSON.parse(e.data); |
| + switch (data[0]) { |
| + case 'start-fetch': { |
|
Devlin
2017/04/06 18:32:13
A switch for a single case is a little weird. Can
Charlie Reis
2017/04/06 19:21:59
Done.
|
| + fetch('http://127.0.0.1:' + location.port + '/extensions/xhr.txt') |
| + .then((result) => result.text()) |
| + .then((text) => { |
| + reportResult( |
| + (text == 'File to request via XHR.\n') ? 'success' : 'failure'); |
| + }) |
| + .catch(err => { |
| + console.log('Error: ' + err); |
| + reportResult('failure'); |
| + }); |
| + break; |
| + } |
| + } |
| +}); |
| + |
| +window.console.log('Script has been successfully injected.'); |