[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / preference / onchange_split / test.js
blob6067887ed6af54427a2b71b48fecb072ca55e430
1 // Copyright (c) 2012 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 // Content settings API test
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.PreferenceOnChangeSplit
8 var inIncognitoContext = chrome.extension.inIncognitoContext;
9 var pass = chrome.test.callbackPass;
10 var sendMessage = chrome.test.sendMessage;
11 var allowCookies = chrome.privacy.websites.thirdPartyCookiesAllowed;
13 // Listen until |event| has fired with all of the values in |expected|.
14 function listenUntil(event, expected) {
15 var done = chrome.test.listenForever(event, function(value) {
16 for (var i = 0; i < expected.length; i++) {
17 if (chrome.test.checkDeepEq(expected[i], value)) {
18 expected.splice(i, 1);
19 if (expected.length == 0)
20 done();
21 return;
24 chrome.test.fail("Unexpected event: " + JSON.stringify(value));
25 });
28 // Fail if |event| is fired (with any values). Because listenUntil stops
29 // listening when |event| has fired with all the values in |expected|, it may
30 // not capture superfluous unexpected events.
31 function listenAndFailWhen(event) {
32 return chrome.test.listenForever(event, function(value) {
33 chrome.test.fail("Unexpected event: " + JSON.stringify(value));
34 });
37 // Constructs messages to be sent via chrome.test.sendMessage
38 function constructMessage(str, caller) {
39 caller = caller || arguments.callee.caller.name;
40 var incognitoStr = inIncognitoContext ? " incognito " : " regular ";
41 console.log(caller + incognitoStr + str);
42 return caller + incognitoStr + str;
45 chrome.test.runTests([
46 // Changing the regular settings when no incognito-specific settings are
47 // defined should fire one event in the regular window, and two in the
48 // incognito.
49 function changeDefault() {
50 var expected = [{
51 'value': false,
52 'levelOfControl': 'controlled_by_this_extension'
53 }];
55 if (inIncognitoContext) {
56 expected.push({
57 'value': false,
58 'incognitoSpecific': false,
59 'levelOfControl': 'controlled_by_this_extension'
60 });
63 listenUntil(allowCookies.onChange, expected);
65 sendMessage(constructMessage("ready"), pass(function() {
66 if (!inIncognitoContext) {
67 allowCookies.set({
68 'value': false
69 }, pass());
71 }));
74 // Changing incognito-specific settings should only be visible to the
75 // incognito window.
76 function changeIncognitoOnly() {
77 if (!inIncognitoContext) {
78 var done = listenAndFailWhen(allowCookies.onChange);
79 sendMessage(constructMessage("listening"), done);
80 } else {
81 listenUntil(allowCookies.onChange, [{
82 'value': true,
83 'incognitoSpecific': true,
84 'levelOfControl': 'controlled_by_this_extension'
85 }]);
88 sendMessage(constructMessage("ready"), pass(function() {
89 if (inIncognitoContext) {
90 allowCookies.set({
91 'value': true,
92 'scope': 'incognito_session_only'
93 }, pass(sendMessage(constructMessage("pref set", "changeIncognitoOnly"),
94 pass())));
96 }));
99 // Changing the regular settings when incognito-specific settings are
100 // defined should only be visible to the regular window.
101 function changeDefaultOnly() {
102 if (!inIncognitoContext) {
103 listenUntil(allowCookies.onChange, [{
104 'value': true,
105 'levelOfControl': 'controlled_by_this_extension'
106 }]);
107 } else {
108 var done = listenAndFailWhen(allowCookies.onChange);
109 sendMessage(constructMessage("listening"), done);
112 sendMessage(constructMessage("ready"), pass(function() {
113 if (!inIncognitoContext) {
114 allowCookies.set({
115 'value': true
116 }, pass(sendMessage(constructMessage("pref set", "changeDefaultOnly"),
117 pass())));
119 }));
122 // Change the incognito setting back to false so that we get an event when
123 // clearing the value. Should not be visible to regular window.
124 function changeIncognitoOnlyBack() {
125 if (!inIncognitoContext) {
126 var done = listenAndFailWhen(allowCookies.onChange);
127 sendMessage(constructMessage("listening"), done);
128 } else {
129 listenUntil(allowCookies.onChange, [{
130 'value': false,
131 'incognitoSpecific': true,
132 'levelOfControl': 'controlled_by_this_extension'
133 }]);
136 sendMessage(constructMessage("ready"), pass(function() {
137 if (inIncognitoContext) {
138 allowCookies.set({
139 'value': false,
140 'scope': 'incognito_session_only'
141 }, pass(sendMessage(constructMessage("pref set",
142 "changeIncognitoOnlyBack"),
143 pass())));
145 }));
148 function clearIncognito() {
149 if (!inIncognitoContext) {
150 var done = listenAndFailWhen(allowCookies.onChange);
151 sendMessage(constructMessage("listening"), done);
152 } else {
153 listenUntil(allowCookies.onChange, [{
154 'value': true,
155 'incognitoSpecific': false,
156 'levelOfControl': 'controlled_by_this_extension'
157 }]);
160 sendMessage(constructMessage("ready"), pass(function() {
161 if (inIncognitoContext) {
162 allowCookies.clear({
163 'scope': 'incognito_session_only'
164 }, pass(sendMessage(constructMessage("pref cleared", "clearIncognito"),
165 pass())));
167 }));
170 function clearDefault() {
171 var expected = [{
172 'value': true,
173 'levelOfControl': 'controllable_by_this_extension'
176 if (inIncognitoContext) {
177 expected[1] = {
178 'value': true,
179 'incognitoSpecific': false,
180 'levelOfControl': 'controllable_by_this_extension'
184 listenUntil(allowCookies.onChange, expected);
186 sendMessage(constructMessage("ready"), pass(function() {
187 if (!inIncognitoContext)
188 allowCookies.clear({}, pass());
189 }));