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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/systeminfo/cpu/test_cpu_api.js
diff --git a/chrome/test/data/extensions/api_test/systeminfo/cpu/test_cpu_api.js b/chrome/test/data/extensions/api_test/systeminfo/cpu/test_cpu_api.js
new file mode 100644
index 0000000000000000000000000000000000000000..6835e2391762a910baa84a503fd0e9a3d59171d1
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/systeminfo/cpu/test_cpu_api.js
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// systeminfo.cpu api test
+// browser_tests.exe --gtest_filter=SystemInfoCpuApiTest.*
+
+chrome.systemInfo = chrome.experimental.systemInfo;
+
+var userStep = 3;
+var kernelStep = 2;
+var idleStep = 1;
+function calculateUsage(count) {
+ return (100 - idleStep * 100/(userStep + kernelStep + idleStep));
+}
+
+chrome.test.runTests([
+ function testGet() {
+ for(var i = 0; i < 20; ++i) {
+ chrome.systemInfo.cpu.get(chrome.test.callbackPass(function(result) {
+ chrome.test.assertEq(4, result.numOfProcessors);
+ chrome.test.assertEq("x86", result.archName);
+ chrome.test.assertEq("unknown", result.modelName);
+ }));
+ }
+ },
+ function testUpdatedEvent() {
benwells 2012/09/21 08:19:50 Blank line above here.
Hongbo Min 2012/09/21 09:00:23 Done.
+ var numOfUpdatedEvent = 0;
+ var doneUpdatedEvent = chrome.test.listenForever(
+ chrome.systemInfo.cpu.onUpdated,
+ 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.
+ var expectedUsage = calculateUsage(numOfUpdatedEvent);
+ chrome.test.assertEq(updateInfo.averageUsage, expectedUsage);
+ chrome.test.assertEq(updateInfo.usagePerProcessor.length, 4);
+ 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.
+ chrome.test.assertEq(updateInfo.usagePerProcessor[i], expectedUsage);
+ }
+ if (++numOfUpdatedEvent > 5)
+ doneUpdatedEvent();
+ });
+ }
+]);
+

Powered by Google App Engine
This is Rietveld 408576698