Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc |
| diff --git a/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc b/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc |
| index b516c97a21aac4e93677f7dafbecc1d6996332bd..63fcfcd3aa6adc7a994a7b60c69c8948361687d9 100644 |
| --- a/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc |
| +++ b/chrome/browser/extensions/api/system_info_cpu/system_info_cpu_apitest.cc |
| @@ -5,7 +5,9 @@ |
| #include "base/message_loop.h" |
| #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" |
| #include "chrome/browser/extensions/extension_apitest.h" |
| +#include "chrome/browser/extensions/extension_test_message_listener.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| namespace extensions { |
| @@ -13,18 +15,44 @@ using api::experimental_system_info_cpu::CpuInfo; |
| class MockCpuInfoProviderImpl : public CpuInfoProvider { |
| public: |
| - MockCpuInfoProviderImpl() {} |
| + MockCpuInfoProviderImpl() : num_of_processors_(4) { |
| + // Set sampling interval to 200ms for testing. |
| + sampling_interval_ = 200; |
| + } |
| ~MockCpuInfoProviderImpl() {} |
| virtual bool QueryInfo(CpuInfo* info) OVERRIDE { |
| if (!info) return false; |
| - info->num_of_processors = 4; |
| + info->num_of_processors = num_of_processors_; |
| info->arch_name = "x86"; |
| info->model_name = "unknown"; |
| return true; |
| } |
| + |
| + private: |
| + virtual bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times) OVERRIDE { |
| + if (!times) return false; |
|
benwells
2012/09/21 08:19:50
This should be DCHECK so your test can catch (and
Hongbo Min
2012/09/21 09:00:23
Done.
|
| + |
| + times->clear(); |
| + static int user_step = 3; |
| + static int kernel_step = 2; |
| + static int idle_step = 1; |
| + static int count = 0; |
| + for (int i = 0; i < num_of_processors_; i++) { |
| + CpuTime time; |
| + time.user += user_step * count; |
| + time.kernel += kernel_step * count; |
| + time.idle += idle_step * count; |
| + times->push_back(time); |
| + |
| + count++; |
| + } |
| + return true; |
| + } |
| + |
| + int num_of_processors_; |
| }; |
| class SystemInfoCpuApiTest: public ExtensionApiTest { |
| @@ -40,7 +68,6 @@ class SystemInfoCpuApiTest: public ExtensionApiTest { |
| virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
| - |
| CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); |
| // The provider is owned by the single CpuInfoProvider instance. |
| CpuInfoProvider::InitializeForTesting(provider); |