OLD | NEW |
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 |
OLD | NEW |