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

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/common/cleardata_session/guest.html

Issue 2700473003: Support the removal of only session cookies or persistent cookies (Closed)
Patch Set: adding comment Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/platform_apps/web_view/common/cleardata_session/guest.html
diff --git a/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_session/guest.html b/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_session/guest.html
new file mode 100644
index 0000000000000000000000000000000000000000..37d2be08b415f25796a0774cc17bb17ca7057890
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/web_view/common/cleardata_session/guest.html
@@ -0,0 +1,95 @@
+<!doctype html>
+<!--
+ * 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.
+-->
+<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(msgArray) {
+ var msg = msgArray.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.startsWith(nameEq)) {
+ return part.substr(nameEq.length);
+ }
+ if (part == name) {
+ return '';
+ }
+ }
+ return undefined;
+ };
+
+ var addCookies = function() {
+ window.console.log('setCookie: foo = fooValue');
+ setCookie('foo', 'fooValue');
+ 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>

Powered by Google App Engine
This is Rietveld 408576698