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

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

Issue 10831353: Add a generic template for system info provider (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code polishment Created 8 years, 4 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/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
7 9
8 namespace extensions { 10 namespace extensions {
11
12 using api::experimental_system_info_cpu::CpuInfo;
13 using api::experimental_system_info_cpu::CpuCoreInfo;
14
15 class MockCpuInfoProviderImpl : public CpuInfoProvider {
16 public:
17 MockCpuInfoProviderImpl() {}
18 ~MockCpuInfoProviderImpl() {}
19
20 virtual bool QueryInfo(CpuInfo* info) OVERRIDE {
21 DCHECK(info);
22
23 info->cores.clear();
24
25 static const unsigned int kNumberOfCores = 4;
26 for (unsigned int i = 0; i < kNumberOfCores; ++i) {
27 linked_ptr<CpuCoreInfo> core(new CpuCoreInfo());
28 core->load = i*10;
29 info->cores.push_back(core);
30 }
31 return true;
32 }
33 };
34
9 class SystemInfoCpuApiTest: public ExtensionApiTest { 35 class SystemInfoCpuApiTest: public ExtensionApiTest {
10 public: 36 public:
11 SystemInfoCpuApiTest() {} 37 SystemInfoCpuApiTest() {}
12 ~SystemInfoCpuApiTest() {} 38 ~SystemInfoCpuApiTest() {}
39
13 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
14 ExtensionApiTest::SetUpCommandLine(command_line); 41 ExtensionApiTest::SetUpCommandLine(command_line);
15 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 42 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
16 } 43 }
44
45 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
46 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
47 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
48
49 CpuInfoProvider* provider = new MockCpuInfoProviderImpl();
50 // The provider is owned by the single CpuInfoProvider instance.
51 CpuInfoProvider::InitializeForTesting(provider);
52 }
53
54 private:
55 scoped_ptr<MessageLoop> message_loop_;
17 }; 56 };
18 57
19 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { 58 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) {
20 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; 59 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_;
21 } 60 }
22 61
23 } // namespace extensions 62 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/system_info_cpu/system_info_cpu_api.cc ('k') | chrome/browser/extensions/system_info_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698