Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1503)

Side by Side Diff: chrome/test/data/extensions/api_test/systeminfo/cpu/test_cpu_api.js

Issue 10905171: Add systemInfo.cpu.onUpdated event implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
28 function testUpdatedEvent() {
29 var numOfUpdatedEvent = 0;
30 var doneUpdatedEvent = chrome.test.listenForever(
31 chrome.systemInfo.cpu.onUpdated,
32 function listener(updateInfo) {
33 var expectedUsage = calculateUsage(numOfUpdatedEvent);
34 chrome.test.assertEq(updateInfo.averageUsage, expectedUsage);
35
36 chrome.test.assertEq(updateInfo.usagePerProcessor.length, 4);
37 for (var i = 0; i < updateInfo.usagePerProcessor.length; ++i)
38 chrome.test.assertEq(updateInfo.usagePerProcessor[i], expectedUsage);
39 if (++numOfUpdatedEvent > 5)
40 doneUpdatedEvent();
41 });
42 }
43 ]);
44
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698