| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/apps/scoped_keep_alive.h" | 8 #include "chrome/browser/apps/scoped_keep_alive.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 10 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 collector->set_cpu_usage_callback_for_testing( | 112 collector->set_cpu_usage_callback_for_testing( |
| 113 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 113 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
| 114 base::Unretained(this), | 114 base::Unretained(this), |
| 115 5)); | 115 5)); |
| 116 EXPECT_DOUBLE_EQ(5, collector->UpdatePowerConsumptionForTesting()); | 116 EXPECT_DOUBLE_EQ(5, collector->UpdatePowerConsumptionForTesting()); |
| 117 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); | 117 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(BrowserProcessPowerTest, MultipleSites) { | 120 TEST_F(BrowserProcessPowerTest, MultipleSites) { |
| 121 Browser::CreateParams native_params(profile(), | 121 Browser::CreateParams native_params(profile()); |
| 122 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 123 GURL url1("http://www.google.com"); | 122 GURL url1("http://www.google.com"); |
| 124 GURL url2("http://www.example.com"); | 123 GURL url2("http://www.example.com"); |
| 125 GURL url3("https://www.google.com"); | 124 GURL url3("https://www.google.com"); |
| 126 scoped_ptr<Browser> browser2( | 125 scoped_ptr<Browser> browser2( |
| 127 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | 126 chrome::CreateBrowserWithTestWindowForParams(&native_params)); |
| 128 scoped_ptr<Browser> browser3( | 127 scoped_ptr<Browser> browser3( |
| 129 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | 128 chrome::CreateBrowserWithTestWindowForParams(&native_params)); |
| 130 AddTab(browser(), url1); | 129 AddTab(browser(), url1); |
| 131 AddTab(browser2.get(), url2); | 130 AddTab(browser2.get(), url2); |
| 132 AddTab(browser3.get(), url3); | 131 AddTab(browser3.get(), url3); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 | 159 |
| 161 // Close some tabs and verify that they are removed from the metrics map. | 160 // Close some tabs and verify that they are removed from the metrics map. |
| 162 chrome::CloseTab(browser2.get()); | 161 chrome::CloseTab(browser2.get()); |
| 163 chrome::CloseTab(browser3.get()); | 162 chrome::CloseTab(browser3.get()); |
| 164 | 163 |
| 165 collector->UpdatePowerConsumptionForTesting(); | 164 collector->UpdatePowerConsumptionForTesting(); |
| 166 EXPECT_EQ(1u, metrics_map->size()); | 165 EXPECT_EQ(1u, metrics_map->size()); |
| 167 } | 166 } |
| 168 | 167 |
| 169 TEST_F(BrowserProcessPowerTest, IncognitoDoesntRecordPowerUsage) { | 168 TEST_F(BrowserProcessPowerTest, IncognitoDoesntRecordPowerUsage) { |
| 170 Browser::CreateParams native_params(profile()->GetOffTheRecordProfile(), | 169 Browser::CreateParams native_params(profile()->GetOffTheRecordProfile()); |
| 171 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 172 scoped_ptr<Browser> incognito_browser( | 170 scoped_ptr<Browser> incognito_browser( |
| 173 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | 171 chrome::CreateBrowserWithTestWindowForParams(&native_params)); |
| 174 GURL url("http://www.google.com"); | 172 GURL url("http://www.google.com"); |
| 175 AddTab(browser(), url); | 173 AddTab(browser(), url); |
| 176 | 174 |
| 177 GURL hidden_url("http://foo.com"); | 175 GURL hidden_url("http://foo.com"); |
| 178 AddTab(incognito_browser.get(), hidden_url); | 176 AddTab(incognito_browser.get(), hidden_url); |
| 179 | 177 |
| 180 // Create fake process numbers. | 178 // Create fake process numbers. |
| 181 GetProcess(browser())->SetProcessHandle(MakeProcessHandle(1)); | 179 GetProcess(browser())->SetProcessHandle(MakeProcessHandle(1)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 198 | 196 |
| 199 // Verify that the incognito data was not stored. | 197 // Verify that the incognito data was not stored. |
| 200 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); | 198 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); |
| 201 EXPECT_EQ(0, origin_power_map->GetPowerForOrigin(hidden_url)); | 199 EXPECT_EQ(0, origin_power_map->GetPowerForOrigin(hidden_url)); |
| 202 | 200 |
| 203 chrome::CloseTab(incognito_browser.get()); | 201 chrome::CloseTab(incognito_browser.get()); |
| 204 } | 202 } |
| 205 | 203 |
| 206 TEST_F(BrowserProcessPowerTest, MultipleProfilesRecordSeparately) { | 204 TEST_F(BrowserProcessPowerTest, MultipleProfilesRecordSeparately) { |
| 207 scoped_ptr<Profile> other_profile(CreateProfile()); | 205 scoped_ptr<Profile> other_profile(CreateProfile()); |
| 208 Browser::CreateParams native_params(other_profile.get(), | 206 Browser::CreateParams native_params(other_profile.get()); |
| 209 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 210 scoped_ptr<Browser> other_user( | 207 scoped_ptr<Browser> other_user( |
| 211 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | 208 chrome::CreateBrowserWithTestWindowForParams(&native_params)); |
| 212 | 209 |
| 213 GURL url("http://www.google.com"); | 210 GURL url("http://www.google.com"); |
| 214 AddTab(browser(), url); | 211 AddTab(browser(), url); |
| 215 | 212 |
| 216 GURL hidden_url("http://foo.com"); | 213 GURL hidden_url("http://foo.com"); |
| 217 AddTab(other_user.get(), hidden_url); | 214 AddTab(other_user.get(), hidden_url); |
| 218 | 215 |
| 219 // Create fake process numbers. | 216 // Create fake process numbers. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 284 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
| 288 base::Unretained(this), | 285 base::Unretained(this), |
| 289 5)); | 286 5)); |
| 290 collector->UpdatePowerConsumptionForTesting(); | 287 collector->UpdatePowerConsumptionForTesting(); |
| 291 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); | 288 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); |
| 292 | 289 |
| 293 window->OnNativeClose(); | 290 window->OnNativeClose(); |
| 294 collector->UpdatePowerConsumptionForTesting(); | 291 collector->UpdatePowerConsumptionForTesting(); |
| 295 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 292 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
| 296 } | 293 } |
| OLD | NEW |