OLD | NEW |
1 <script> | 1 <script> |
2 var pass = chrome.test.callbackPass; | 2 var pass = chrome.test.callbackPass; |
3 var fail = chrome.test.callbackFail; | 3 var fail = chrome.test.callbackFail; |
4 | 4 |
5 function getTestFunctionFor(keys, fails) { | 5 function getTestFunctionFor(keys, fails) { |
6 return function generatedTest () { | 6 return function generatedTest () { |
7 // Debug. | 7 // Debug. |
8 console.log("keys: " + keys + ", fails: " + fails); | 8 console.log("keys: " + keys + "; fails: " + fails); |
9 | 9 |
10 chrome.chromeosInfoPrivate.get( | 10 chrome.chromeosInfoPrivate.get( |
11 keys, | 11 keys, |
12 pass(function(values) { | 12 pass( |
13 // Debug | 13 function(values) { |
14 console.log("values: ", values); | 14 for (var i = 0; i < keys.length; ++i) { |
15 for (var i = 0; i < keys.length; ++i) | 15 // Debug |
16 chrome.test.assertEq(!(i in fails), keys[i] in values); | 16 if (keys[i] in values) { |
17 })); | 17 console.log(" values['" + keys[i] + "'] = " + |
| 18 values[keys[i]]); |
| 19 } else { |
| 20 console.log(" " + keys[i] + " is missing in values"); |
| 21 } |
| 22 |
| 23 chrome.test.assertEq(fails.indexOf(keys[i]) == -1, |
| 24 keys[i] in values); |
| 25 } |
| 26 } |
| 27 ) |
| 28 ); |
18 } | 29 } |
19 } | 30 } |
20 | 31 |
21 // Automatically generates tests for the given possible keys. Note, this | 32 // Automatically generates tests for the given possible keys. Note, this |
22 // tests do not check return value, only the fact that it is presented. | 33 // tests do not check return value, only the fact that it is presented. |
23 function generateTestsForKeys(keys) { | 34 function generateTestsForKeys(keys) { |
24 var tests = []; | 35 var tests = []; |
25 // Test with all the keys at one. | 36 // Test with all the keys at one. |
26 tests.push(getTestFunctionFor(keys, [])); | 37 tests.push(getTestFunctionFor(keys, [])); |
27 // Tests with key which hasn't corresponding value. | 38 // Tests with key which hasn't corresponding value. |
28 var noValueKey = "no-value-for-this-key"; | 39 var noValueKey = "noValueForThisKey"; |
29 tests.push(getTestFunctionFor([noValueKey], [0])); | 40 tests.push(getTestFunctionFor([noValueKey], [noValueKey])); |
30 | 41 |
31 if (keys.length > 1) { | 42 if (keys.length > 1) { |
32 // Tests with the separate keys. | 43 // Tests with the separate keys. |
33 for (var i = 0; i < keys.length; ++i) { | 44 for (var i = 0; i < keys.length; ++i) { |
34 tests.push(getTestFunctionFor([keys[i]], [])); | 45 tests.push(getTestFunctionFor([keys[i]], [])); |
35 } | 46 } |
36 } | 47 } |
37 if (keys.length > 2) { | 48 if (keys.length >= 2) { |
38 tests.push(getTestFunctionFor([keys[0], keys[1]], [])); | 49 tests.push(getTestFunctionFor([keys[0], keys[1]], [])); |
39 tests.push(getTestFunctionFor([keys[0], noValueKey, keys[1]], [1])); | 50 tests.push(getTestFunctionFor([keys[0], noValueKey, keys[1]], |
| 51 [noValueKey])); |
40 } | 52 } |
41 return tests; | 53 return tests; |
42 } | 54 } |
43 | 55 |
44 var tests = generateTestsForKeys(["hwid", "homeProvider"]) | 56 var tests = generateTestsForKeys(["hwid", "homeProvider", "initialLocale"]) |
45 chrome.test.runTests(tests); | 57 chrome.test.runTests(tests); |
46 </script> | 58 </script> |
OLD | NEW |