Chromium Code Reviews| 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" | 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" | 6 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
| 8 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | |
| 9 | 11 |
| 10 namespace extensions { | 12 namespace extensions { |
| 11 | 13 |
| 12 using api::experimental_system_info_cpu::CpuInfo; | 14 using api::experimental_system_info_cpu::CpuInfo; |
| 13 | 15 |
| 14 class MockCpuInfoProviderImpl : public CpuInfoProvider { | 16 class MockCpuInfoProviderImpl : public CpuInfoProvider { |
| 15 public: | 17 public: |
| 16 MockCpuInfoProviderImpl() {} | 18 MockCpuInfoProviderImpl() : num_of_processors_(4) { |
| 19 // Set sampling interval to 200ms for testing. | |
| 20 sampling_interval_ = 200; | |
| 21 } | |
| 17 ~MockCpuInfoProviderImpl() {} | 22 ~MockCpuInfoProviderImpl() {} |
| 18 | 23 |
| 19 virtual bool QueryInfo(CpuInfo* info) OVERRIDE { | 24 virtual bool QueryInfo(CpuInfo* info) OVERRIDE { |
| 20 if (!info) return false; | 25 if (!info) return false; |
| 21 | 26 |
| 22 info->num_of_processors = 4; | 27 info->num_of_processors = num_of_processors_; |
| 23 info->arch_name = "x86"; | 28 info->arch_name = "x86"; |
| 24 info->model_name = "unknown"; | 29 info->model_name = "unknown"; |
| 25 | 30 |
| 26 return true; | 31 return true; |
| 27 } | 32 } |
| 33 private: | |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
Add a newline before this.
Hongbo Min
2012/09/16 14:07:49
Done.
| |
| 34 virtual bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times) OVERRIDE { | |
| 35 if (!times) return false; | |
| 36 | |
| 37 times->clear(); | |
| 38 static int user_step = 3; | |
| 39 static int kernel_step = 2; | |
| 40 static int idle_step = 1; | |
| 41 static int count = 0; | |
| 42 for (int i = 0; i < num_of_processors_; i++) { | |
| 43 CpuTime time; | |
| 44 time.user += user_step * count; | |
| 45 time.kernel += kernel_step * count; | |
| 46 time.idle += idle_step * count; | |
| 47 times->push_back(time); | |
| 48 | |
| 49 count++; | |
| 50 } | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 int num_of_processors_; | |
| 28 }; | 55 }; |
| 29 | 56 |
| 30 class SystemInfoCpuApiTest: public ExtensionApiTest { | 57 class SystemInfoCpuApiTest: public ExtensionApiTest { |
| 31 public: | 58 public: |
| 32 SystemInfoCpuApiTest() {} | 59 SystemInfoCpuApiTest() {} |
| 33 ~SystemInfoCpuApiTest() {} | 60 ~SystemInfoCpuApiTest() {} |
| 34 | 61 |
| 35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 62 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 36 ExtensionApiTest::SetUpCommandLine(command_line); | 63 ExtensionApiTest::SetUpCommandLine(command_line); |
| 37 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 64 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 38 } | 65 } |
| 39 | 66 |
| 40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 67 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 41 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 68 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 42 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); | 69 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
| 43 | |
| 44 CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); | 70 CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); |
| 45 // The provider is owned by the single CpuInfoProvider instance. | 71 // The provider is owned by the single CpuInfoProvider instance. |
| 46 CpuInfoProvider::InitializeForTesting(provider); | 72 CpuInfoProvider::InitializeForTesting(provider); |
| 47 } | 73 } |
| 48 | 74 |
| 49 private: | 75 private: |
| 50 scoped_ptr<MessageLoop> message_loop_; | 76 scoped_ptr<MessageLoop> message_loop_; |
| 51 }; | 77 }; |
| 52 | 78 |
| 53 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { | 79 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { |
| 54 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; | 80 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; |
| 55 } | 81 } |
| 56 | 82 |
| 57 } // namespace extensions | 83 } // namespace extensions |
| OLD | NEW |