| 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..21f4e174585612fec96caa86bf2f4f05924afbf3 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 {
|
| + DCHECK(times);
|
| +
|
| + 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,10 +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);
|
| }
|
|
|
| private:
|
| @@ -51,6 +75,9 @@ class SystemInfoCpuApiTest: public ExtensionApiTest {
|
| };
|
|
|
| IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) {
|
| + CpuInfoProvider* provider = new MockCpuInfoProviderImpl();
|
| + // The provider is owned by the single CpuInfoProvider instance.
|
| + CpuInfoProvider::InitializeForTesting(provider);
|
| ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_;
|
| }
|
|
|
|
|