OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // systeminfo.cpu api test | 5 // systeminfo.cpu api test |
6 // browser_tests.exe --gtest_filter=SystemInfoCpuApiTest.* | 6 // browser_tests.exe --gtest_filter=SystemInfoCpuApiTest.* |
7 | 7 |
8 var userStep = 3; | |
9 var kernelStep = 2; | |
10 var idleStep = 1; | |
11 function calculateUsage(count) { | |
12 return (100 - idleStep * 100/(userStep + kernelStep + idleStep)); | |
13 } | |
14 | |
15 chrome.test.runTests([ | 8 chrome.test.runTests([ |
16 function testGet() { | 9 function testGet() { |
17 for(var i = 0; i < 20; ++i) { | 10 for(var i = 0; i < 20; ++i) { |
18 chrome.systemInfo.cpu.get(chrome.test.callbackPass(function(result) { | 11 chrome.systemInfo.cpu.get(chrome.test.callbackPass(function(result) { |
19 chrome.test.assertEq(4, result.numOfProcessors); | 12 chrome.test.assertEq(4, result.numOfProcessors); |
20 chrome.test.assertEq("x86", result.archName); | 13 chrome.test.assertEq("x86", result.archName); |
21 chrome.test.assertEq("unknown", result.modelName); | 14 chrome.test.assertEq("unknown", result.modelName); |
22 })); | 15 })); |
23 } | 16 } |
24 }, | |
25 | |
26 function testUpdatedEvent() { | |
27 var numOfUpdatedEvent = 0; | |
28 var doneUpdatedEvent = chrome.test.listenForever( | |
29 chrome.systemInfo.cpu.onUpdated, | |
30 function listener(updateInfo) { | |
31 var expectedUsage = calculateUsage(numOfUpdatedEvent); | |
32 chrome.test.assertEq(updateInfo.averageUsage, expectedUsage); | |
33 | |
34 chrome.test.assertEq(updateInfo.usagePerProcessor.length, 4); | |
35 for (var i = 0; i < updateInfo.usagePerProcessor.length; ++i) | |
36 chrome.test.assertEq(updateInfo.usagePerProcessor[i], expectedUsage); | |
37 if (++numOfUpdatedEvent > 5) | |
38 doneUpdatedEvent(); | |
39 }); | |
40 } | 17 } |
41 ]); | 18 ]); |
42 | 19 |
OLD | NEW |