1 // Copyright (c) 2011 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 var pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail;
8 function getTestFunctionFor(keys, fails) {
9 return function generatedTest () {
11 console.warn('keys: ' + keys + '; fails: ' + fails);
13 chrome.chromeosInfoPrivate.get(
17 for (var i = 0; i < keys.length; ++i) {
19 if (keys[i] in values) {
20 console.log(' values["' + keys[i] + '"] = ' +
23 console.log(' ' + keys[i] + ' is missing in values');
26 chrome.test.assertEq(fails.indexOf(keys[i]) == -1,
35 // Automatically generates tests for the given possible keys. Note, this
36 // tests do not check return value, only the fact that it is presented.
37 function generateTestsForKeys(keys) {
39 // Test with all the keys at one.
40 tests.push(getTestFunctionFor(keys, []));
41 // Tests with key which hasn't corresponding value.
42 var noValueKey = 'noValueForThisKey';
43 tests.push(getTestFunctionFor([noValueKey], [noValueKey]));
45 if (keys.length > 1) {
46 // Tests with the separate keys.
47 for (var i = 0; i < keys.length; ++i) {
48 tests.push(getTestFunctionFor([keys[i]], []));
51 if (keys.length >= 2) {
52 tests.push(getTestFunctionFor([keys[0], keys[1]], []));
53 tests.push(getTestFunctionFor([keys[0], noValueKey, keys[1]],
59 function timezoneSetTest() {
60 chrome.chromeosInfoPrivate.set('timezone', 'Pacific/Kiritimati');
61 chrome.chromeosInfoPrivate.get(
65 chrome.test.assertEq(values['timezone'],
66 'Pacific/Kiritimati');
71 function prefsTest() {
72 chrome.chromeosInfoPrivate.set('a11yLargeCursorEnabled', true);
73 chrome.chromeosInfoPrivate.set('a11yStickyKeysEnabled', true);
74 chrome.chromeosInfoPrivate.set('a11ySpokenFeedbackEnabled', true);
75 chrome.chromeosInfoPrivate.set('a11yHighContrastEnabled', true);
76 chrome.chromeosInfoPrivate.set('a11yScreenMagnifierEnabled', true);
77 chrome.chromeosInfoPrivate.set('a11yAutoClickEnabled', true);
78 chrome.chromeosInfoPrivate.set('a11yVirtualKeyboardEnabled', true);
79 chrome.chromeosInfoPrivate.set('sendFunctionKeys', true);
80 chrome.chromeosInfoPrivate.get(
81 ['a11yLargeCursorEnabled',
82 'a11yStickyKeysEnabled',
83 'a11ySpokenFeedbackEnabled',
84 'a11yHighContrastEnabled',
85 'a11yScreenMagnifierEnabled',
86 'a11yAutoClickEnabled',
87 'a11yVirtualKeyboardEnabled',
91 chrome.test.assertEq(values['a11yLargeCursorEnabled'], true);
92 chrome.test.assertEq(values['a11yStickyKeysEnabled'], true);
93 chrome.test.assertEq(values['a11ySpokenFeedbackEnabled'], true);
94 chrome.test.assertEq(values['a11yHighContrastEnabled'], true);
95 chrome.test.assertEq(values['a11yScreenMagnifierEnabled'], true);
96 chrome.test.assertEq(values['a11yAutoClickEnabled'], true);
97 chrome.test.assertEq(values['a11yVirtualKeyboardEnabled'], true);
98 chrome.test.assertEq(values['sendFunctionKeys'], true);
103 // Run generated chrome.chromeosInfoPrivate.get() tests.
104 var tests = generateTestsForKeys(['hwid',
111 'a11yLargeCursorEnabled',
112 'a11yStickyKeysEnabled',
113 'a11ySpokenFeedbackEnabled',
114 'a11yHighContrastEnabled',
115 'a11yScreenMagnifierEnabled',
116 'a11yAutoClickEnabled',
117 'a11yVirtualKeyboardEnabled',
120 'supportedTimezones'])
122 // Add chrome.chromeosInfoPrivate.set() test.
123 tests.push(timezoneSetTest);
124 tests.push(prefsTest);
126 chrome.test.runTests(tests);