Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / cookies / events / test.js
blob0734ba06661790e429e9793fdcb0974568647eab
1 // Copyright (c) 2011 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.
5 // These are the cookies we expect to see along the way.
6 var SET_REMOVE_COOKIE = {
7 name: 'testSetRemove',
8 value: '42',
9 domain: 'a.com',
10 hostOnly: true,
11 path: '/',
12 secure: false,
13 httpOnly: false,
14 session: false,
15 expirationDate: 12345678900,
16 storeId: "0"
19 var OVERWRITE_COOKIE_PRE = {
20 name: 'testOverwrite',
21 value: '42',
22 domain: 'a.com',
23 hostOnly: true,
24 path: '/',
25 secure: false,
26 httpOnly: false,
27 session: false,
28 expirationDate: 12345678900,
29 storeId: "0"
32 var OVERWRITE_COOKIE_POST = {
33 name: 'testOverwrite',
34 value: '43',
35 domain: 'a.com',
36 hostOnly: true,
37 path: '/',
38 secure: false,
39 httpOnly: false,
40 session: false,
41 expirationDate: 12345678900,
42 storeId: "0"
45 chrome.test.runTests([
46 function testSet() {
47 chrome.test.listenOnce(chrome.cookies.onChanged, function (info) {
48 chrome.test.assertFalse(info.removed);
49 chrome.test.assertEq('explicit', info.cause);
50 chrome.test.assertEq(SET_REMOVE_COOKIE, info.cookie);
51 });
52 chrome.cookies.set({
53 url: 'http://a.com/path',
54 name: 'testSetRemove',
55 value: '42',
56 expirationDate: 12345678900
57 });
59 function testRemove() {
60 chrome.test.listenOnce(chrome.cookies.onChanged, function (info) {
61 chrome.test.assertTrue(info.removed);
62 chrome.test.assertEq('explicit', info.cause);
63 chrome.test.assertEq(SET_REMOVE_COOKIE, info.cookie);
64 });
65 chrome.cookies.remove({
66 url: 'http://a.com/path',
67 name: 'testSetRemove'
68 });
70 function overwriteFirstSet() {
71 chrome.test.listenOnce(chrome.cookies.onChanged, function (info) {
72 chrome.test.assertFalse(info.removed);
73 chrome.test.assertEq('explicit', info.cause);
74 chrome.test.assertEq(OVERWRITE_COOKIE_PRE, info.cookie);
75 });
76 chrome.cookies.set({
77 url: 'http://a.com/path',
78 name: 'testOverwrite',
79 value: '42',
80 expirationDate: 12345678900
81 });
83 function overwriteSecondSet() {
84 var haveRemoved = false;
85 var haveSet = false;
86 var done = chrome.test.listenForever(chrome.cookies.onChanged,
87 function(info) {
88 if (info.removed) {
89 chrome.test.assertEq('overwrite', info.cause);
90 chrome.test.assertEq(OVERWRITE_COOKIE_PRE, info.cookie);
91 chrome.test.assertFalse(haveRemoved);
92 chrome.test.assertFalse(haveSet);
93 haveRemoved = true;
94 } else {
95 chrome.test.assertEq('explicit', info.cause);
96 chrome.test.assertEq(OVERWRITE_COOKIE_POST, info.cookie);
97 chrome.test.assertTrue(haveRemoved);
98 chrome.test.assertFalse(haveSet);
99 haveSet = true;
101 if (haveRemoved && haveSet) {
102 done();
105 chrome.cookies.set({
106 url: 'http://a.com/path',
107 name: 'testOverwrite',
108 value: '43',
109 expirationDate: 12345678900
112 function overwriteExpired() {
113 chrome.test.listenOnce(chrome.cookies.onChanged, function (info) {
114 chrome.test.assertTrue(info.removed);
115 chrome.test.assertEq('expired_overwrite', info.cause);
116 chrome.test.assertEq(OVERWRITE_COOKIE_POST, info.cookie);
118 chrome.cookies.set({
119 url: 'http://a.com/path',
120 name: 'testOverwrite',
121 value: '43',
122 expirationDate: 1