| 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/browser/extensions/extension_test_message_listener.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 using api::experimental_system_info_cpu::CpuInfo; | 14 using api::system_info_cpu::CpuInfo; |
| 15 |
| 16 const char kExtensionId[] = "lfakdgdkbaleijdcpbfbngfphpmgfdfn"; |
| 15 | 17 |
| 16 class MockCpuInfoProviderImpl : public CpuInfoProvider { | 18 class MockCpuInfoProviderImpl : public CpuInfoProvider { |
| 17 public: | 19 public: |
| 18 MockCpuInfoProviderImpl() : num_of_processors_(4) { | 20 MockCpuInfoProviderImpl() : num_of_processors_(4) { |
| 19 // Set sampling interval to 200ms for testing. | 21 // Set sampling interval to 200ms for testing. |
| 20 sampling_interval_ = 200; | 22 sampling_interval_ = 200; |
| 21 } | 23 } |
| 22 | 24 |
| 23 virtual bool QueryInfo(CpuInfo* info) OVERRIDE { | 25 virtual bool QueryInfo(CpuInfo* info) OVERRIDE { |
| 24 if (!info) return false; | 26 if (!info) return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 int num_of_processors_; | 58 int num_of_processors_; |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 class SystemInfoCpuApiTest: public ExtensionApiTest { | 61 class SystemInfoCpuApiTest: public ExtensionApiTest { |
| 60 public: | 62 public: |
| 61 SystemInfoCpuApiTest() {} | 63 SystemInfoCpuApiTest() {} |
| 62 virtual ~SystemInfoCpuApiTest() {} | 64 virtual ~SystemInfoCpuApiTest() {} |
| 63 | 65 |
| 64 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 66 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 65 ExtensionApiTest::SetUpCommandLine(command_line); | 67 ExtensionApiTest::SetUpCommandLine(command_line); |
| 66 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 68 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, |
| 69 kExtensionId); |
| 67 } | 70 } |
| 68 | 71 |
| 69 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 72 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 70 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 73 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 71 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | 74 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
| 72 } | 75 } |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 scoped_ptr<base::MessageLoop> message_loop_; | 78 scoped_ptr<base::MessageLoop> message_loop_; |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { | 81 IN_PROC_BROWSER_TEST_F(SystemInfoCpuApiTest, Cpu) { |
| 79 CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); | 82 CpuInfoProvider* provider = new MockCpuInfoProviderImpl(); |
| 80 // The provider is owned by the single CpuInfoProvider instance. | 83 // The provider is owned by the single CpuInfoProvider instance. |
| 81 CpuInfoProvider::InitializeForTesting(provider); | 84 CpuInfoProvider::InitializeForTesting(provider); |
| 82 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; | 85 ASSERT_TRUE(RunExtensionTest("systeminfo/cpu")) << message_; |
| 83 } | 86 } |
| 84 | 87 |
| 85 } // namespace extensions | 88 } // namespace extensions |
| OLD | NEW |