Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/web_view/common/cleardata_persistent/guest.html |
| diff --git a/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_persistent/guest.html b/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_persistent/guest.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..73310bdaf680402831948febd89361953131b2b4 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_persistent/guest.html |
| @@ -0,0 +1,95 @@ |
| +<!doctype html> |
| +<!-- |
| + * Copyright 2013 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. |
| +--> |
| +<html> |
| + <head> |
| + <script type="text/javascript"> |
| + // A guest that stores and deletes cookies. |
| + // Note that the embedder has to initiate a postMessage first so that |
| + // the guest has a reference to the embedder's window. |
| + |
| + // The window reference of the embedder to send post message reply. |
| + var embedderWindowChannel = null; |
| + |
| + // A value that uniquely identifies the guest sending the messages to the |
| + // embedder. |
| + var channelId = 0; |
| + var notifyEmbedder = function(msg_array) { |
|
lazyboy
2017/02/15 21:45:26
msgArray
lfg
2017/02/15 22:44:00
Done.
|
| + var msg = msg_array.concat([channelId]); |
| + embedderWindowChannel.postMessage(JSON.stringify(msg), '*'); |
| + }; |
| + |
| + var SPLIT_RE_ = /\s*;\s*/; |
| + var setCookie = function(name, value) { // Just a random future time. |
| + var futureDate = new Date((+new Date) + 10000 * 1000); |
| + document.cookie = |
| + name + '=' + value + ';expires=' + futureDate.toUTCString(); |
| + }; |
| + var setSessionCookie = function (name, value) { // Session cookie. |
| + document.cookie = name + '=' + value; |
| + }; |
| + var getCookie = function (name) { |
| + var nameEq = name + '='; |
| + var parts = (document.cookie || '').split(SPLIT_RE_); |
| + for (var i = 0; i < parts.length; ++i) { |
| + var part = parts[i]; |
| + if (part.lastIndexOf(nameEq, 0) == 0) { |
|
lazyboy
2017/02/15 21:45:26
part.startsWith(nameEq) will also work.
lfg
2017/02/15 22:44:00
Done.
|
| + return part.substr(nameEq.length); |
| + } |
| + if (part == name) { |
| + return ''; |
| + } |
| + } |
| + return undefined; |
| + }; |
| + |
| + var addCookies = function() { |
| + window.console.log('setCookie: foo = fooValue'); |
| + setCookie("foo", "fooValue"); |
|
lazyboy
2017/02/15 21:45:26
nit: here and elsewhere: all strings single quoted
lfg
2017/02/15 22:44:00
Done.
|
| + window.console.log('setSessionCookie: bar = barValue'); |
| + setSessionCookie("bar", "barValue"); |
| + notifyEmbedder(['step2.cookies-added']); |
| + }; |
| + |
| + var onPostMessageReceived = function(e) { |
| + embedderWindowChannel = e.source; |
| + var data = JSON.parse(e.data); |
| + if (data[0] == 'create-channel') { |
| + window.console.log('guest: create-channel'); |
| + channelId = data[1]; |
| + notifyEmbedder(['channel-created']); |
| + return; |
| + } |
| + |
| + window.console.log('guest.onPostMessageReceived: ' + data[0]); |
| + // Tests. |
| + // These logs trigger event listeners in the embedder. |
| + switch (data[0]) { |
| + case 'step1.add-cookies': |
| + window.console.log('guest.' + data[0]); |
| + addCookies(); |
| + break; |
| + case 'step3.get-cookies': |
| + window.console.log('guest.' + data[0]); |
| + var retValues = ['step4.got-cookies']; |
| + var cookieValues = []; |
| + for (var i = 1; i < data.length; ++i) { |
| + cookieValues.push(getCookie(data[i])); |
| + } |
| + retValues.push(cookieValues); |
| + notifyEmbedder(retValues); |
| + break; |
| + default: |
| + break; |
| + } |
| + }; |
| + window.addEventListener('message', onPostMessageReceived, false); |
| + </script> |
| + </head> |
| + <body> |
| + <div>Guest that stores and retrieves certain cookies.</div> |
| + </body> |
| +</html> |