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 "apps/app_window_contents.h" | 7 #include "apps/app_window_contents.h" |
8 #include "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
9 #include "apps/ui/apps_client.h" | 9 #include "apps/ui/apps_client.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 extensions::Extension::NO_FLAGS, | 285 extensions::Extension::NO_FLAGS, |
286 kTestAppId, | 286 kTestAppId, |
287 &error)); | 287 &error)); |
288 EXPECT_TRUE(extension.get()) << error; | 288 EXPECT_TRUE(extension.get()) << error; |
289 // Increment the apps count to avoid a DCHECK later. | 289 // Increment the apps count to avoid a DCHECK later. |
290 apps::AppsClient::Get()->IncrementKeepAliveCount(); | 290 apps::AppsClient::Get()->IncrementKeepAliveCount(); |
291 | 291 |
292 Profile* current_profile = | 292 Profile* current_profile = |
293 profile_manager_->CreateTestingProfile("Test user"); | 293 profile_manager_->CreateTestingProfile("Test user"); |
294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
295 apps::AppWindow* window = | 295 apps::AppWindow* window = new apps::AppWindow( |
296 new apps::AppWindow(current_profile, new ChromeAppDelegate(), extension); | 296 current_profile, new ChromeAppDelegate(), 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(scoped_ptr<apps::AppWindowContents>( | 301 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>( |
302 new TestAppWindowContents(web_contents))); | 302 new TestAppWindowContents(web_contents))); |
303 apps::AppWindowRegistry* app_registry = | 303 apps::AppWindowRegistry* app_registry = |
304 apps::AppWindowRegistry::Get(current_profile); | 304 apps::AppWindowRegistry::Get(current_profile); |
305 app_registry->AddAppWindow(window); | 305 app_registry->AddAppWindow(window); |
306 | 306 |
307 collector->set_cpu_usage_callback_for_testing( | 307 collector->set_cpu_usage_callback_for_testing( |
308 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 308 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
309 base::Unretained(this), | 309 base::Unretained(this), |
310 5)); | 310 5)); |
311 collector->UpdatePowerConsumptionForTesting(); | 311 collector->UpdatePowerConsumptionForTesting(); |
312 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); | 312 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); |
313 | 313 |
314 // Clear the AppWindowContents before trying to close. | 314 // Clear the AppWindowContents before trying to close. |
315 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>()); | 315 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>()); |
316 window->OnNativeClose(); | 316 window->OnNativeClose(); |
317 collector->UpdatePowerConsumptionForTesting(); | 317 collector->UpdatePowerConsumptionForTesting(); |
318 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 318 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
319 } | 319 } |
OLD | NEW |