OLD | NEW |
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 'managed quota bytes'); | 145 'managed quota bytes'); |
146 chrome.storage.local.set({foo: 'bar'}, () => { | 146 chrome.storage.local.set({foo: 'bar'}, () => { |
147 chrome.storage.local.get('foo', (results) => { | 147 chrome.storage.local.get('foo', (results) => { |
148 chrome.test.assertTrue(!!results, 'no results'); | 148 chrome.test.assertTrue(!!results, 'no results'); |
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 testChromeSetting() { |
| 156 chrome.test.assertTrue(!!chrome.privacy, 'privacy'); |
| 157 chrome.test.assertTrue(!!chrome.privacy.websites, 'websites'); |
| 158 var cookiePolicy = chrome.privacy.websites.thirdPartyCookiesAllowed; |
| 159 chrome.test.assertTrue(!!cookiePolicy, 'cookie policy'); |
| 160 chrome.test.assertTrue(!!cookiePolicy.get, 'get'); |
| 161 chrome.test.assertTrue(!!cookiePolicy.set, 'set'); |
| 162 chrome.test.assertTrue(!!cookiePolicy.clear, 'clear'); |
| 163 chrome.test.assertTrue(!!cookiePolicy.onChange, 'onchange'); |
| 164 |
| 165 // The JSON spec for ChromeSettings is weird, because it claims it allows |
| 166 // any type for <val> in ChromeSetting.set({value: <val>}), but this is just |
| 167 // a hack in our schema generation because we curry in the different types |
| 168 // of restrictions. Trying to pass in the wrong type for value should fail |
| 169 // (synchronously). |
| 170 var caught = false; |
| 171 try { |
| 172 cookiePolicy.set({value: 'not a bool'}); |
| 173 } catch (e) { |
| 174 caught = true; |
| 175 } |
| 176 chrome.test.assertTrue(caught, 'caught'); |
| 177 |
| 178 var listenerPromise = new Promise((resolve, reject) => { |
| 179 cookiePolicy.onChange.addListener(function listener(details) { |
| 180 chrome.test.assertTrue(!!details, 'listener details'); |
| 181 chrome.test.assertEq(false, details.value); |
| 182 cookiePolicy.onChange.removeListener(listener); |
| 183 resolve(); |
| 184 }); |
| 185 }); |
| 186 |
| 187 var methodPromise = new Promise((resolve, reject) => { |
| 188 cookiePolicy.get({}, (details) => { |
| 189 chrome.test.assertTrue(!!details, 'get details'); |
| 190 chrome.test.assertTrue(details.value, 'details value true'); |
| 191 cookiePolicy.set({value: false}, () => { |
| 192 cookiePolicy.get({}, (details) => { |
| 193 chrome.test.assertTrue(!!details, 'get details'); |
| 194 chrome.test.assertFalse(details.value, 'details value false'); |
| 195 resolve(); |
| 196 }); |
| 197 }); |
| 198 }); |
| 199 }); |
| 200 |
| 201 Promise.all([listenerPromise, methodPromise]).then(() => { |
| 202 chrome.test.succeed(); |
| 203 }); |
| 204 }, |
155 ]; | 205 ]; |
156 | 206 |
157 chrome.test.getConfig(config => { | 207 chrome.test.getConfig(config => { |
158 chrome.test.assertTrue(!!config, 'config does not exist'); | 208 chrome.test.assertTrue(!!config, 'config does not exist'); |
159 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); | 209 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); |
160 portNumber = config.testServer.port; | 210 portNumber = config.testServer.port; |
161 chrome.test.runTests(tests); | 211 chrome.test.runTests(tests); |
162 }); | 212 }); |
OLD | NEW |