| 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/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 8 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 9 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/browser_with_test_window_test.h" | 12 #include "chrome/test/base/browser_with_test_window_test.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
| 14 #include "components/power/origin_power_map.h" | 15 #include "components/power/origin_power_map.h" |
| 15 #include "components/power/origin_power_map_factory.h" | 16 #include "components/power/origin_power_map_factory.h" |
| 16 #include "content/public/browser/site_instance.h" | 17 #include "content/public/browser/site_instance.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 std::string error; | 280 std::string error; |
| 280 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 281 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 281 scoped_refptr<extensions::Extension> extension( | 282 scoped_refptr<extensions::Extension> extension( |
| 282 extensions::Extension::Create(extension_path, | 283 extensions::Extension::Create(extension_path, |
| 283 extensions::Manifest::INTERNAL, | 284 extensions::Manifest::INTERNAL, |
| 284 manifest, | 285 manifest, |
| 285 extensions::Extension::NO_FLAGS, | 286 extensions::Extension::NO_FLAGS, |
| 286 kTestAppId, | 287 kTestAppId, |
| 287 &error)); | 288 &error)); |
| 288 EXPECT_TRUE(extension.get()) << error; | 289 EXPECT_TRUE(extension.get()) << error; |
| 289 // Increment the apps count to avoid a DCHECK later. | |
| 290 extensions::AppWindowClient::Get()->IncrementKeepAliveCount(); | |
| 291 | 290 |
| 292 Profile* current_profile = | 291 Profile* current_profile = |
| 293 profile_manager_->CreateTestingProfile("Test user"); | 292 profile_manager_->CreateTestingProfile("Test user"); |
| 294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 293 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 295 extensions::AppWindow* window = new extensions::AppWindow( | 294 extensions::AppWindow* window = new extensions::AppWindow( |
| 296 current_profile, new ChromeAppDelegate(), extension.get()); | 295 current_profile, new ChromeAppDelegate(scoped_ptr<ScopedKeepAlive>()), |
| 296 extension.get()); |
| 297 content::WebContents* web_contents( | 297 content::WebContents* web_contents( |
| 298 content::WebContents::Create(content::WebContents::CreateParams( | 298 content::WebContents::Create(content::WebContents::CreateParams( |
| 299 current_profile, | 299 current_profile, |
| 300 content::SiteInstance::CreateForURL(current_profile, url)))); | 300 content::SiteInstance::CreateForURL(current_profile, url)))); |
| 301 window->SetAppWindowContentsForTesting( | 301 window->SetAppWindowContentsForTesting( |
| 302 scoped_ptr<extensions::AppWindowContents>( | 302 scoped_ptr<extensions::AppWindowContents>( |
| 303 new TestAppWindowContents(web_contents))); | 303 new TestAppWindowContents(web_contents))); |
| 304 extensions::AppWindowRegistry* app_registry = | 304 extensions::AppWindowRegistry* app_registry = |
| 305 extensions::AppWindowRegistry::Get(current_profile); | 305 extensions::AppWindowRegistry::Get(current_profile); |
| 306 app_registry->AddAppWindow(window); | 306 app_registry->AddAppWindow(window); |
| 307 | 307 |
| 308 collector->set_cpu_usage_callback_for_testing( | 308 collector->set_cpu_usage_callback_for_testing( |
| 309 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 309 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
| 310 base::Unretained(this), | 310 base::Unretained(this), |
| 311 5)); | 311 5)); |
| 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 |