Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // systeminfo.cpu api test | |
| 6 // browser_tests.exe --gtest_filter=SystemInfoCpuApiTest.* | |
| 7 | |
| 8 chrome.systemInfo = chrome.experimental.systemInfo; | |
| 9 | |
| 10 var userStep = 3; | |
| 11 var kernelStep = 2; | |
| 12 var idleStep = 1; | |
| 13 function calculateUsage(count) { | |
| 14 return (100 - idleStep * 100/(userStep + kernelStep + idleStep)); | |
| 15 } | |
| 16 | |
| 17 chrome.test.runTests([ | |
| 18 function testGet() { | |
| 19 for(var i = 0; i < 20; ++i) { | |
| 20 chrome.systemInfo.cpu.get(chrome.test.callbackPass(function(result) { | |
| 21 chrome.test.assertEq(4, result.numOfProcessors); | |
| 22 chrome.test.assertEq("x86", result.archName); | |
| 23 chrome.test.assertEq("unknown", result.modelName); | |
| 24 })); | |
| 25 } | |
| 26 }, | |
| 27 function testUpdatedEvent() { | |
|
benwells
2012/09/21 08:19:50
Blank line above here.
Hongbo Min
2012/09/21 09:00:23
Done.
| |
| 28 var numOfUpdatedEvent = 0; | |
| 29 var doneUpdatedEvent = chrome.test.listenForever( | |
| 30 chrome.systemInfo.cpu.onUpdated, | |
| 31 function listener(updateInfo) { | |
|
benwells
2012/09/21 08:19:50
Indent this two block two more spaces.
Hongbo Min
2012/09/21 09:00:23
Done.
| |
| 32 var expectedUsage = calculateUsage(numOfUpdatedEvent); | |
| 33 chrome.test.assertEq(updateInfo.averageUsage, expectedUsage); | |
| 34 chrome.test.assertEq(updateInfo.usagePerProcessor.length, 4); | |
| 35 for (var i = 0; i < updateInfo.usagePerProcessor.length; ++i) { | |
|
benwells
2012/09/21 08:19:50
Can drop these curly braces.
Hongbo Min
2012/09/21 09:00:23
Done.
| |
| 36 chrome.test.assertEq(updateInfo.usagePerProcessor[i], expectedUsage); | |
| 37 } | |
| 38 if (++numOfUpdatedEvent > 5) | |
| 39 doneUpdatedEvent(); | |
| 40 }); | |
| 41 } | |
| 42 ]); | |
| 43 | |
| OLD | NEW |