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

Side by Side Diff: chrome/test/data/extensions/api_test/native_bindings/extension/background.js

Issue 2718543004: [Extensions Bindings] Add ChromeSetting custom type (Closed)
Patch Set: rebase Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/native_bindings/extension/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 if (!chrome || !chrome.test) 5 if (!chrome || !chrome.test)
6 throw new Error('chrome.test is undefined'); 6 throw new Error('chrome.test is undefined');
7 7
8 var portNumber; 8 var portNumber;
9 9
10 // This is a good end-to-end test for two reasons. The first is obvious - it 10 // This is a good end-to-end test for two reasons. The first is obvious - it
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 chrome.test.assertTrue(!!results.foo, 'no foo'); 149 chrome.test.assertTrue(!!results.foo, 'no foo');
150 chrome.test.assertEq('bar', results.foo); 150 chrome.test.assertEq('bar', results.foo);
151 chrome.test.succeed(); 151 chrome.test.succeed();
152 }); 152 });
153 }); 153 });
154 }, 154 },
155 function testBrowserActionWithCustomSendRequest() { 155 function testBrowserActionWithCustomSendRequest() {
156 // browserAction.setIcon uses a custom hook that calls sendRequest(). 156 // browserAction.setIcon uses a custom hook that calls sendRequest().
157 chrome.browserAction.setIcon({path: 'icon.png'}, chrome.test.succeed); 157 chrome.browserAction.setIcon({path: 'icon.png'}, chrome.test.succeed);
158 }, 158 },
159 function testChromeSetting() {
160 chrome.test.assertTrue(!!chrome.privacy, 'privacy');
161 chrome.test.assertTrue(!!chrome.privacy.websites, 'websites');
162 var cookiePolicy = chrome.privacy.websites.thirdPartyCookiesAllowed;
163 chrome.test.assertTrue(!!cookiePolicy, 'cookie policy');
164 chrome.test.assertTrue(!!cookiePolicy.get, 'get');
165 chrome.test.assertTrue(!!cookiePolicy.set, 'set');
166 chrome.test.assertTrue(!!cookiePolicy.clear, 'clear');
167 chrome.test.assertTrue(!!cookiePolicy.onChange, 'onchange');
168
169 // The JSON spec for ChromeSettings is weird, because it claims it allows
170 // any type for <val> in ChromeSetting.set({value: <val>}), but this is just
171 // a hack in our schema generation because we curry in the different types
172 // of restrictions. Trying to pass in the wrong type for value should fail
173 // (synchronously).
174 var caught = false;
175 try {
176 cookiePolicy.set({value: 'not a bool'});
177 } catch (e) {
178 caught = true;
179 }
180 chrome.test.assertTrue(caught, 'caught');
181
182 var listenerPromise = new Promise((resolve, reject) => {
183 cookiePolicy.onChange.addListener(function listener(details) {
184 chrome.test.assertTrue(!!details, 'listener details');
185 chrome.test.assertEq(false, details.value);
186 cookiePolicy.onChange.removeListener(listener);
187 resolve();
188 });
189 });
190
191 var methodPromise = new Promise((resolve, reject) => {
192 cookiePolicy.get({}, (details) => {
193 chrome.test.assertTrue(!!details, 'get details');
194 chrome.test.assertTrue(details.value, 'details value true');
195 cookiePolicy.set({value: false}, () => {
196 cookiePolicy.get({}, (details) => {
197 chrome.test.assertTrue(!!details, 'get details');
198 chrome.test.assertFalse(details.value, 'details value false');
199 resolve();
200 });
201 });
202 });
203 });
204
205 Promise.all([listenerPromise, methodPromise]).then(() => {
206 chrome.test.succeed();
207 });
208 },
159 ]; 209 ];
160 210
161 chrome.test.getConfig(config => { 211 chrome.test.getConfig(config => {
162 chrome.test.assertTrue(!!config, 'config does not exist'); 212 chrome.test.assertTrue(!!config, 'config does not exist');
163 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); 213 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist');
164 portNumber = config.testServer.port; 214 portNumber = config.testServer.port;
165 chrome.test.runTests(tests); 215 chrome.test.runTests(tests);
166 }); 216 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/native_bindings/extension/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698