Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / settings_private / test.js
blobe61166889368df9ef8a70d96697f4060fb3dc388
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 = [
21 function setPref() {
22 chrome.settingsPrivate.setPref(
23 kTestPrefName,
24 kTestPrefValue,
25 kTestPageId,
26 function(success) {
27 callbackResult(success);
28 chrome.test.succeed();
29 });
31 function setPref_CrOSSetting() {
32 chrome.settingsPrivate.setPref(
33 'cros.accounts.allowBWSI',
34 false,
35 kTestPageId,
36 function(success) {
37 callbackResult(success);
38 chrome.test.succeed();
39 });
41 function getPref() {
42 chrome.settingsPrivate.getPref(
43 kTestPrefName,
44 function(value) {
45 chrome.test.assertTrue(value !== null);
46 callbackResult(true);
47 chrome.test.succeed();
48 });
50 function getPref_CrOSSetting() {
51 chrome.settingsPrivate.getPref(
52 'cros.accounts.allowBWSI',
53 function(value) {
54 chrome.test.assertTrue(value !== null);
55 callbackResult(true);
56 chrome.test.succeed();
57 });
59 function getAllPrefs() {
60 chrome.settingsPrivate.getAllPrefs(
61 function(prefs) {
62 chrome.test.assertTrue(prefs.length > 0);
63 callbackResult(true);
64 chrome.test.succeed();
65 });
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);
72 callbackResult(true);
73 chrome.test.succeed();
74 });
76 chrome.settingsPrivate.setPref(
77 kTestPrefName,
78 kTestPrefValue,
79 kTestPageId,
80 function() {});
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);
87 callbackResult(true);
88 chrome.test.succeed();
89 });
91 chrome.settingsPrivate.setPref(
92 'cros.accounts.allowBWSI',
93 false,
94 kTestPageId,
95 function() {});
99 var testToRun = window.location.search.substring(1);
100 chrome.test.runTests(availableTests.filter(function(op) {
101 return op.name == testToRun;
102 }));