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 // Run generated chrome.chromeosInfoPrivate.get() tests.
72 var tests = generateTestsForKeys(["hwid",
78 "supportedTimezones"])
80 // Add chrome.chromeosInfoPrivate.set() test.
81 tests.push(timezoneSetTest);
83 chrome.test.runTests(tests);