OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function getRootURL(port) { |
| 6 return new URL('http://127.0.0.1:' + port + |
| 7 '/extensions/platform_apps/web_view/download_cookie_isolation/'); |
| 8 } |
| 9 |
| 10 // Creates a new WebView using |props| and returns a Promise that resolves once |
| 11 // the 'loadstop' event is observed for the WebView. |
| 12 function createWebView(props) { |
| 13 var webview = document.createElement('webview'); |
| 14 webview.id = props.id; |
| 15 webview.partition = props.partition; |
| 16 webview.addEventListener('permissionrequest', function(e) { |
| 17 console.log("Permission request for " + e.permission); |
| 18 if (e.permission === 'download') { |
| 19 e.request.allow(); |
| 20 }; |
| 21 }); |
| 22 webview.addEventListener('consolemessage', function(e) { |
| 23 console.log(props.id + " : " + e.message); |
| 24 }); |
| 25 document.getElementById('container').appendChild(webview); |
| 26 |
| 27 return new Promise(function(accept, reject) { |
| 28 webview.addEventListener('loadstop', function() { |
| 29 console.log('loadstop received with src=' + webview.src); |
| 30 accept(true); |
| 31 }); |
| 32 webview.src = props.url.href; |
| 33 }); |
| 34 } |
| 35 |
| 36 // Creates the WebView elements and returns a promise that resolves once all |
| 37 // webviews have finished loading. |
| 38 function createWebViews(rootUrl) { |
| 39 var webviews = []; |
| 40 |
| 41 return Promise.all([ |
| 42 createWebView({ |
| 43 url: new URL('guest.html#cookie=first', rootUrl), |
| 44 id: 'first', |
| 45 partition: 'persist:p' |
| 46 }), |
| 47 createWebView({ |
| 48 url: new URL('guest.html#cookie=second', rootUrl), |
| 49 id: 'second', |
| 50 partition: 'q' |
| 51 }) |
| 52 ]); |
| 53 } |
| 54 |
| 55 // Called from test runner. Sends a message to the contained WebView to |
| 56 // initiate a download. |
| 57 function startDownload(id, url) { |
| 58 console.log("Received download for " + url + " on " + id); |
| 59 var webview = document.getElementById(id); |
| 60 webview.contentWindow.postMessage({ |
| 61 command: 'start-download', |
| 62 url: url |
| 63 }, (new URL(webview.src)).origin); |
| 64 } |
| 65 |
| 66 function run() { |
| 67 var p = new Promise(function(accept, reject) { |
| 68 chrome.test.getConfig(function(config) { |
| 69 accept(config); |
| 70 }); |
| 71 }).then(function(config) { |
| 72 return createWebViews(getRootURL(config.testServer.port)); |
| 73 }).then(function() { |
| 74 chrome.test.sendMessage('created-webviews'); |
| 75 }); |
| 76 } |
| 77 window.onload = run; |
OLD | NEW |