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
3 // found in the LICENSE file.
5 // This just tests the interface. It does not test for specific results, only
6 // that callbacks are correctly invoked, expected parameters are correct,
7 // and failures are detected.
9 var kTestPrefName
= 'download.default_directory';
10 var kTestPrefValue
= '/Downloads';
11 var kTestPageId
= 'pageId';
13 function callbackResult(result
) {
14 if (chrome
.runtime
.lastError
)
15 chrome
.test
.fail(chrome
.runtime
.lastError
.message
);
16 else if (result
== false)
17 chrome
.test
.fail('Failed: ' + result
);
20 var availableTests
= [
22 chrome
.settingsPrivate
.setPref(
27 callbackResult(success
);
28 chrome
.test
.succeed();
31 function setPref_CrOSSetting() {
32 chrome
.settingsPrivate
.setPref(
33 'cros.accounts.allowBWSI',
37 callbackResult(success
);
38 chrome
.test
.succeed();
42 chrome
.settingsPrivate
.getPref(
45 chrome
.test
.assertTrue(value
!== null);
47 chrome
.test
.succeed();
50 function getPref_CrOSSetting() {
51 chrome
.settingsPrivate
.getPref(
52 'cros.accounts.allowBWSI',
54 chrome
.test
.assertTrue(value
!== null);
56 chrome
.test
.succeed();
59 function getAllPrefs() {
60 chrome
.settingsPrivate
.getAllPrefs(
62 chrome
.test
.assertTrue(prefs
.length
> 0);
64 chrome
.test
.succeed();
67 function onPrefsChanged() {
68 chrome
.settingsPrivate
.onPrefsChanged
.addListener(function(prefs
) {
69 chrome
.test
.assertTrue(prefs
.length
> 0);
70 chrome
.test
.assertEq(kTestPrefName
, prefs
[0].key
);
71 chrome
.test
.assertEq(kTestPrefValue
, prefs
[0].value
);
73 chrome
.test
.succeed();
76 chrome
.settingsPrivate
.setPref(
82 function onPrefsChanged_CrOSSetting() {
83 chrome
.settingsPrivate
.onPrefsChanged
.addListener(function(prefs
) {
84 chrome
.test
.assertTrue(prefs
.length
> 0);
85 chrome
.test
.assertEq('cros.accounts.allowBWSI', prefs
[0].key
);
86 chrome
.test
.assertEq(false, prefs
[0].value
);
88 chrome
.test
.succeed();
91 chrome
.settingsPrivate
.setPref(
92 'cros.accounts.allowBWSI',
99 var testToRun
= window
.location
.search
.substring(1);
100 chrome
.test
.runTests(availableTests
.filter(function(op
) {
101 return op
.name
== testToRun
;