OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 4 |
5 #include "chrome/browser/power/process_power_collector.h" | 5 #include "chrome/browser/power/process_power_collector.h" |
6 | 6 |
7 #include "chrome/browser/apps/scoped_keep_alive.h" | 7 #include "chrome/browser/apps/scoped_keep_alive.h" |
8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
9 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 9 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #endif | 30 #endif |
31 | 31 |
32 using power::OriginPowerMap; | 32 using power::OriginPowerMap; |
33 using power::OriginPowerMapFactory; | 33 using power::OriginPowerMapFactory; |
34 | 34 |
35 class BrowserProcessPowerTest : public BrowserWithTestWindowTest { | 35 class BrowserProcessPowerTest : public BrowserWithTestWindowTest { |
36 public: | 36 public: |
37 BrowserProcessPowerTest() {} | 37 BrowserProcessPowerTest() {} |
38 virtual ~BrowserProcessPowerTest() {} | 38 virtual ~BrowserProcessPowerTest() {} |
39 | 39 |
40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() override { |
41 BrowserWithTestWindowTest::SetUp(); | 41 BrowserWithTestWindowTest::SetUp(); |
42 collector.reset(new ProcessPowerCollector); | 42 collector.reset(new ProcessPowerCollector); |
43 | 43 |
44 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
45 power_manager::PowerSupplyProperties prop; | 45 power_manager::PowerSupplyProperties prop; |
46 prop.set_external_power(power_manager::PowerSupplyProperties::AC); | 46 prop.set_external_power(power_manager::PowerSupplyProperties::AC); |
47 prop.set_battery_state(power_manager::PowerSupplyProperties::DISCHARGING); | 47 prop.set_battery_state(power_manager::PowerSupplyProperties::DISCHARGING); |
48 prop.set_battery_percent(20.00); | 48 prop.set_battery_percent(20.00); |
49 prop.set_battery_discharge_rate(1); | 49 prop.set_battery_discharge_rate(1); |
50 collector->PowerChanged(prop); | 50 collector->PowerChanged(prop); |
51 #endif | 51 #endif |
52 | 52 |
53 profile_manager_.reset( | 53 profile_manager_.reset( |
54 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 54 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
55 ASSERT_TRUE(profile_manager_->SetUp()); | 55 ASSERT_TRUE(profile_manager_->SetUp()); |
56 } | 56 } |
57 | 57 |
58 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() override { |
59 collector.reset(); | 59 collector.reset(); |
60 BrowserWithTestWindowTest::TearDown(); | 60 BrowserWithTestWindowTest::TearDown(); |
61 } | 61 } |
62 | 62 |
63 // Mocks out CPU usage for all processes as |value| percent. | 63 // Mocks out CPU usage for all processes as |value| percent. |
64 double ReturnCpuAsConstant(double value, base::ProcessHandle handle) { | 64 double ReturnCpuAsConstant(double value, base::ProcessHandle handle) { |
65 return value; | 65 return value; |
66 } | 66 } |
67 | 67 |
68 protected: | 68 protected: |
(...skipping 20 matching lines...) Expand all Loading... |
89 scoped_ptr<TestingProfileManager> profile_manager_; | 89 scoped_ptr<TestingProfileManager> profile_manager_; |
90 }; | 90 }; |
91 | 91 |
92 class TestAppWindowContents : public extensions::AppWindowContents { | 92 class TestAppWindowContents : public extensions::AppWindowContents { |
93 public: | 93 public: |
94 explicit TestAppWindowContents(content::WebContents* web_contents) | 94 explicit TestAppWindowContents(content::WebContents* web_contents) |
95 : web_contents_(web_contents) {} | 95 : web_contents_(web_contents) {} |
96 | 96 |
97 // apps:AppWindowContents | 97 // apps:AppWindowContents |
98 virtual void Initialize(content::BrowserContext* context, | 98 virtual void Initialize(content::BrowserContext* context, |
99 const GURL& url) OVERRIDE {} | 99 const GURL& url) override {} |
100 virtual void LoadContents(int32 creator_process_id) OVERRIDE {} | 100 virtual void LoadContents(int32 creator_process_id) override {} |
101 virtual void NativeWindowChanged( | 101 virtual void NativeWindowChanged( |
102 extensions::NativeAppWindow* native_app_window) OVERRIDE {} | 102 extensions::NativeAppWindow* native_app_window) override {} |
103 virtual void NativeWindowClosed() OVERRIDE {} | 103 virtual void NativeWindowClosed() override {} |
104 virtual void DispatchWindowShownForTests() const OVERRIDE {} | 104 virtual void DispatchWindowShownForTests() const override {} |
105 virtual content::WebContents* GetWebContents() const OVERRIDE { | 105 virtual content::WebContents* GetWebContents() const override { |
106 return web_contents_.get(); | 106 return web_contents_.get(); |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 scoped_ptr<content::WebContents> web_contents_; | 110 scoped_ptr<content::WebContents> web_contents_; |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(BrowserProcessPowerTest, NoSite) { | 113 TEST_F(BrowserProcessPowerTest, NoSite) { |
114 collector->UpdatePowerConsumptionForTesting(); | 114 collector->UpdatePowerConsumptionForTesting(); |
115 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 115 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 collector->UpdatePowerConsumptionForTesting(); | 312 collector->UpdatePowerConsumptionForTesting(); |
313 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); | 313 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); |
314 | 314 |
315 // Clear the AppWindowContents before trying to close. | 315 // Clear the AppWindowContents before trying to close. |
316 window->SetAppWindowContentsForTesting( | 316 window->SetAppWindowContentsForTesting( |
317 scoped_ptr<extensions::AppWindowContents>()); | 317 scoped_ptr<extensions::AppWindowContents>()); |
318 window->OnNativeClose(); | 318 window->OnNativeClose(); |
319 collector->UpdatePowerConsumptionForTesting(); | 319 collector->UpdatePowerConsumptionForTesting(); |
320 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 320 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
321 } | 321 } |
OLD | NEW |