OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var pass = chrome.test.callbackPass; |
| 6 var fail = chrome.test.callbackFail; |
| 7 |
| 8 function getTestFunctionFor(keys, fails) { |
| 9 return function generatedTest () { |
| 10 // Debug. |
| 11 console.log("keys: " + keys + "; fails: " + fails); |
| 12 |
| 13 chrome.chromeosInfoPrivate.get( |
| 14 keys, |
| 15 pass( |
| 16 function(values) { |
| 17 for (var i = 0; i < keys.length; ++i) { |
| 18 // Debug |
| 19 if (keys[i] in values) { |
| 20 console.log(" values['" + keys[i] + "'] = " + |
| 21 values[keys[i]]); |
| 22 } else { |
| 23 console.log(" " + keys[i] + " is missing in values"); |
| 24 } |
| 25 |
| 26 chrome.test.assertEq(fails.indexOf(keys[i]) == -1, |
| 27 keys[i] in values); |
| 28 } |
| 29 } |
| 30 ) |
| 31 ); |
| 32 } |
| 33 } |
| 34 |
| 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) { |
| 38 var tests = []; |
| 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])); |
| 44 |
| 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]], [])); |
| 49 } |
| 50 } |
| 51 if (keys.length >= 2) { |
| 52 tests.push(getTestFunctionFor([keys[0], keys[1]], [])); |
| 53 tests.push(getTestFunctionFor([keys[0], noValueKey, keys[1]], |
| 54 [noValueKey])); |
| 55 } |
| 56 return tests; |
| 57 } |
| 58 |
| 59 var tests = generateTestsForKeys(["hwid", "homeProvider", "initialLocale"]) |
| 60 chrome.test.runTests(tests); |
OLD | NEW |