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 = 'download.default_directory'; | 9 var kTestPrefName = 'download.default_directory'; |
10 var kTestPrefValue = '/Downloads'; | 10 var kTestPrefValue = '/Downloads'; |
| 11 |
| 12 // This corresponds to policy key: kHomepageIsNewTabPage used in |
| 13 // settings_private_apitest.cc. |
| 14 var kTestEnforcedPrefName = 'homepage_is_newtabpage'; |
| 15 |
11 var kTestPageId = 'pageId'; | 16 var kTestPageId = 'pageId'; |
12 | 17 |
13 function callbackResult(result) { | 18 function callbackResult(result) { |
14 if (chrome.runtime.lastError) | 19 if (chrome.runtime.lastError) |
15 chrome.test.fail(chrome.runtime.lastError.message); | 20 chrome.test.fail(chrome.runtime.lastError.message); |
16 else if (result == false) | 21 else if (result == false) |
17 chrome.test.fail('Failed: ' + result); | 22 chrome.test.fail('Failed: ' + result); |
18 } | 23 } |
19 | 24 |
20 var availableTests = [ | 25 var availableTests = [ |
(...skipping 19 matching lines...) Expand all Loading... |
40 }, | 45 }, |
41 function getPref() { | 46 function getPref() { |
42 chrome.settingsPrivate.getPref( | 47 chrome.settingsPrivate.getPref( |
43 kTestPrefName, | 48 kTestPrefName, |
44 function(value) { | 49 function(value) { |
45 chrome.test.assertTrue(value !== null); | 50 chrome.test.assertTrue(value !== null); |
46 callbackResult(true); | 51 callbackResult(true); |
47 chrome.test.succeed(); | 52 chrome.test.succeed(); |
48 }); | 53 }); |
49 }, | 54 }, |
| 55 function getEnforcedPref() { |
| 56 chrome.settingsPrivate.getPref(kTestEnforcedPrefName, function(value) { |
| 57 chrome.test.assertEq('object', typeof value); |
| 58 callbackResult(true); |
| 59 chrome.test.assertEq( |
| 60 chrome.settingsPrivate.ControlledBy.USER_POLICY, value.controlledBy); |
| 61 chrome.test.assertEq( |
| 62 chrome.settingsPrivate.Enforcement.ENFORCED, value.enforcement); |
| 63 chrome.test.succeed(); |
| 64 }); |
| 65 }, |
| 66 function getRecommendedPref() { |
| 67 chrome.settingsPrivate.getPref(kTestEnforcedPrefName, function(value) { |
| 68 chrome.test.assertEq('object', typeof value); |
| 69 callbackResult(true); |
| 70 chrome.test.assertEq(true, value.value); |
| 71 chrome.test.assertEq( |
| 72 chrome.settingsPrivate.ControlledBy.USER_POLICY, value.controlledBy); |
| 73 chrome.test.assertEq( |
| 74 chrome.settingsPrivate.Enforcement.RECOMMENDED, value.enforcement); |
| 75 // Set the value to false, policy properties should still be set. |
| 76 chrome.settingsPrivate.setPref( |
| 77 kTestEnforcedPrefName, false, kTestPageId, function(success) { |
| 78 callbackResult(success); |
| 79 chrome.settingsPrivate.getPref( |
| 80 kTestEnforcedPrefName, function(value) { |
| 81 chrome.test.assertEq('object', typeof value); |
| 82 callbackResult(true); |
| 83 chrome.test.assertEq(false, value.value); |
| 84 chrome.test.assertEq( |
| 85 chrome.settingsPrivate.ControlledBy.USER_POLICY, |
| 86 value.controlledBy); |
| 87 chrome.test.assertEq( |
| 88 chrome.settingsPrivate.Enforcement.RECOMMENDED, |
| 89 value.enforcement); |
| 90 chrome.test.succeed(); |
| 91 }); |
| 92 }); |
| 93 }); |
| 94 }, |
50 function getPref_CrOSSetting() { | 95 function getPref_CrOSSetting() { |
51 chrome.settingsPrivate.getPref( | 96 chrome.settingsPrivate.getPref( |
52 'cros.accounts.allowBWSI', | 97 'cros.accounts.allowBWSI', |
53 function(value) { | 98 function(value) { |
54 chrome.test.assertTrue(value !== null); | 99 chrome.test.assertTrue(value !== null); |
55 callbackResult(true); | 100 callbackResult(true); |
56 chrome.test.succeed(); | 101 chrome.test.succeed(); |
57 }); | 102 }); |
58 }, | 103 }, |
59 function getAllPrefs() { | 104 function getAllPrefs() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 false, | 138 false, |
94 kTestPageId, | 139 kTestPageId, |
95 function() {}); | 140 function() {}); |
96 }, | 141 }, |
97 ]; | 142 ]; |
98 | 143 |
99 var testToRun = window.location.search.substring(1); | 144 var testToRun = window.location.search.substring(1); |
100 chrome.test.runTests(availableTests.filter(function(op) { | 145 chrome.test.runTests(availableTests.filter(function(op) { |
101 return op.name == testToRun; | 146 return op.name == testToRun; |
102 })); | 147 })); |
103 | |
OLD | NEW |