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

Side by Side Diff: chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc

Issue 15817008: Move systemInfo.cpu API out out experimental namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
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 #include "base/command_line.h" 4 #include "base/command_line.h"
5 #include "base/message_loop.h"
6 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" 5 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/common/chrome_switches.h" 7 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
11 9
12 namespace extensions { 10 namespace extensions {
13 11
14 using api::system_info_cpu::CpuInfo; 12 using api::system_info_cpu::CpuInfo;
15 13
16 const char kExtensionId[] = "lfakdgdkbaleijdcpbfbngfphpmgfdfn"; 14 const char kExtensionId[] = "lfakdgdkbaleijdcpbfbngfphpmgfdfn";
17 15
18 class MockCpuInfoProviderImpl : public CpuInfoProvider { 16 class MockCpuInfoProviderImpl : public CpuInfoProvider {
19 public: 17 public:
20 MockCpuInfoProviderImpl() : num_of_processors_(4) { 18 MockCpuInfoProviderImpl() {}
21 // Set sampling interval to 200ms for testing.
22 sampling_interval_ = 200;
23 }
24 19
25 virtual bool QueryInfo(CpuInfo* info) OVERRIDE { 20 virtual bool QueryInfo(CpuInfo* info) OVERRIDE {
26 if (!info) return false; 21 if (!info) return false;
27 22
28 info->num_of_processors = num_of_processors_; 23 info->num_of_processors = 4;
29 info->arch_name = "x86"; 24 info->arch_name = "x86";
30 info->model_name = "unknown"; 25 info->model_name = "unknown";
31 26
32 return true; 27 return true;
33 } 28 }
34 29
35 private: 30 private:
36 virtual ~MockCpuInfoProviderImpl() {} 31 virtual ~MockCpuInfoProviderImpl() {}
37
38 virtual bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times) OVERRIDE {
39 DCHECK(times);
40
41 times->clear();
42 static int user_step = 3;
43 static int kernel_step = 2;
44 static int idle_step = 1;
45 static int count = 0;
46 for (int i = 0; i < num_of_processors_; i++) {
47 CpuTime time;
48 time.user += user_step * count;
49 time.kernel += kernel_step * count;
50 time.idle += idle_step * count;
51 times->push_back(time);
52
53 count++;
54 }
55 return true;
56 }
57
58 int num_of_processors_;
59 }; 32 };
60 33
61 class SystemInfoCpuApiTest: public ExtensionApiTest { 34 class SystemInfoCpuApiTest: public ExtensionApiTest {
62 public: 35 public:
63 SystemInfoCpuApiTest() {} 36 SystemInfoCpuApiTest() {}
64 virtual ~SystemInfoCpuApiTest() {} 37 virtual ~SystemInfoCpuApiTest() {}
65 38
66 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
67 ExtensionApiTest::SetUpCommandLine(command_line); 40 ExtensionApiTest::SetUpCommandLine(command_line);
68 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, 41 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID,
69 kExtensionId); 42 kExtensionId);
70 } 43 }
71 44
72 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 45 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
73 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 46 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
74 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
75 } 47 }
76
77 private:
78 scoped_ptr<base::MessageLoop> message_loop_;
79 }; 48 };
80 49
81 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { 50 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) {
82 CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); 51 CpuInfoProvider* provider = new MockCpuInfoProviderImpl();
83 // The provider is owned by the single CpuInfoProvider instance. 52 // The provider is owned by the single CpuInfoProvider instance.
84 CpuInfoProvider::InitializeForTesting(provider); 53 CpuInfoProvider::InitializeForTesting(provider);
85 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; 54 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_;
86 } 55 }
87 56
88 } // namespace extensions 57 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc ('k') | chrome/browser/extensions/event_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698