OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This just tests the interface. It does not test for specific results, only | 5 // This just tests the interface. It does not test for specific results, only |
6 // that callbacks are correctly invoked, expected parameters are correct, | 6 // that callbacks are correctly invoked, expected parameters are correct, |
7 // and failures are detected. | 7 // and failures are detected. |
8 | 8 |
9 var kTestPrefName = 'test.foo_bar'; | 9 var kTestPrefName = 'download.default_directory'; |
| 10 var kTestPrefValue = '/Downloads'; |
10 var kTestPageId = 'pageId'; | 11 var kTestPageId = 'pageId'; |
11 | 12 |
12 function callbackResult(result) { | 13 function callbackResult(result) { |
13 if (chrome.runtime.lastError) | 14 if (chrome.runtime.lastError) |
14 chrome.test.fail(chrome.runtime.lastError.message); | 15 chrome.test.fail(chrome.runtime.lastError.message); |
15 else if (result == false) | 16 else if (result == false) |
16 chrome.test.fail('Failed: ' + result); | 17 chrome.test.fail('Failed: ' + result); |
17 } | 18 } |
18 | 19 |
19 var availableTests = [ | 20 var availableTests = [ |
20 function setPref() { | 21 function setPref() { |
21 chrome.settingsPrivate.setPref( | 22 chrome.settingsPrivate.setPref( |
22 kTestPrefName, | 23 kTestPrefName, |
23 true, | 24 kTestPrefValue, |
24 kTestPageId, | 25 kTestPageId, |
25 function(success) { | 26 function(success) { |
26 callbackResult(success); | 27 callbackResult(success); |
27 chrome.test.succeed(); | 28 chrome.test.succeed(); |
28 }); | 29 }); |
29 }, | 30 }, |
30 function getPref() { | 31 function getPref() { |
31 chrome.settingsPrivate.getPref( | 32 chrome.settingsPrivate.getPref( |
32 kTestPrefName, | 33 kTestPrefName, |
33 function(value) { | 34 function(value) { |
34 chrome.test.assertTrue(value !== null); | 35 chrome.test.assertTrue(value !== null); |
35 callbackResult(true); | 36 callbackResult(true); |
36 chrome.test.succeed(); | 37 chrome.test.succeed(); |
37 }); | 38 }); |
38 }, | 39 }, |
39 function getAllPrefs() { | 40 function getAllPrefs() { |
40 chrome.settingsPrivate.getAllPrefs( | 41 chrome.settingsPrivate.getAllPrefs( |
41 function(prefs) { | 42 function(prefs) { |
42 chrome.test.assertTrue(prefs.length > 0); | 43 chrome.test.assertTrue(prefs.length > 0); |
43 callbackResult(true); | 44 callbackResult(true); |
44 chrome.test.succeed(); | 45 chrome.test.succeed(); |
45 }); | 46 }); |
46 }, | 47 }, |
| 48 function onPrefsChanged() { |
| 49 chrome.settingsPrivate.onPrefsChanged.addListener(function(prefs) { |
| 50 chrome.test.assertTrue(prefs.length > 0); |
| 51 chrome.test.assertEq(kTestPrefName, prefs[0].key); |
| 52 chrome.test.assertEq(kTestPrefValue, prefs[0].value); |
| 53 callbackResult(true); |
| 54 chrome.test.succeed(); |
| 55 }); |
| 56 |
| 57 chrome.settingsPrivate.setPref( |
| 58 kTestPrefName, |
| 59 kTestPrefValue, |
| 60 kTestPageId, |
| 61 function() {}); |
| 62 }, |
47 ]; | 63 ]; |
48 | 64 |
49 var testToRun = window.location.search.substring(1); | 65 var testToRun = window.location.search.substring(1); |
50 chrome.test.runTests(availableTests.filter(function(op) { | 66 chrome.test.runTests(availableTests.filter(function(op) { |
51 return op.name == testToRun; | 67 return op.name == testToRun; |
52 })); | 68 })); |
53 | 69 |
OLD | NEW |