OLD | NEW |
1 <script> | 1 <!-- |
2 var pass = chrome.test.callbackPass; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
3 var fail = chrome.test.callbackFail; | 3 * source code is governed by a BSD-style license that can be found in the |
4 | 4 * LICENSE file. |
5 function getTestFunctionFor(keys, fails) { | 5 --> |
6 return function generatedTest () { | 6 <script src="background.js"></script> |
7 // Debug. | |
8 console.log("keys: " + keys + "; fails: " + fails); | |
9 | |
10 chrome.chromeosInfoPrivate.get( | |
11 keys, | |
12 pass( | |
13 function(values) { | |
14 for (var i = 0; i < keys.length; ++i) { | |
15 // Debug | |
16 if (keys[i] in values) { | |
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 ); | |
29 } | |
30 } | |
31 | |
32 // Automatically generates tests for the given possible keys. Note, this | |
33 // tests do not check return value, only the fact that it is presented. | |
34 function generateTestsForKeys(keys) { | |
35 var tests = []; | |
36 // Test with all the keys at one. | |
37 tests.push(getTestFunctionFor(keys, [])); | |
38 // Tests with key which hasn't corresponding value. | |
39 var noValueKey = "noValueForThisKey"; | |
40 tests.push(getTestFunctionFor([noValueKey], [noValueKey])); | |
41 | |
42 if (keys.length > 1) { | |
43 // Tests with the separate keys. | |
44 for (var i = 0; i < keys.length; ++i) { | |
45 tests.push(getTestFunctionFor([keys[i]], [])); | |
46 } | |
47 } | |
48 if (keys.length >= 2) { | |
49 tests.push(getTestFunctionFor([keys[0], keys[1]], [])); | |
50 tests.push(getTestFunctionFor([keys[0], noValueKey, keys[1]], | |
51 [noValueKey])); | |
52 } | |
53 return tests; | |
54 } | |
55 | |
56 var tests = generateTestsForKeys(["hwid", "homeProvider", "initialLocale"]) | |
57 chrome.test.runTests(tests); | |
58 </script> | |
OLD | NEW |