| 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 | 4 |
| 5 #include "chrome/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/unpacked_installer.h" |
| 14 #include "chrome/browser/performance_monitor/constants.h" | 17 #include "chrome/browser/performance_monitor/constants.h" |
| 15 #include "chrome/browser/performance_monitor/database.h" | 18 #include "chrome/browser/performance_monitor/database.h" |
| 16 #include "chrome/browser/performance_monitor/performance_monitor.h" | 19 #include "chrome/browser/performance_monitor/performance_monitor.h" |
| 17 #include "chrome/browser/extensions/extension_browsertest.h" | 20 #include "chrome/browser/prefs/session_startup_pref.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | |
| 19 #include "chrome/browser/extensions/unpacked_installer.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/sessions/session_restore.h" |
| 24 #include "chrome/browser/sessions/session_service.h" |
| 25 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 26 #include "chrome/browser/sessions/session_service_factory.h" |
| 22 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/browser_navigator.h" | 29 #include "chrome/browser/ui/browser_navigator.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" | 30 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
| 31 #include "chrome/common/extensions/extension.h" | 39 #include "chrome/common/extensions/extension.h" |
| 32 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
| 34 #include "content/public/browser/notification_registrar.h" | 42 #include "content/public/browser/notification_registrar.h" |
| 35 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/common/page_transition_types.h" | 44 #include "content/public/common/page_transition_types.h" |
| 37 #include "content/public/test/browser_test_utils.h" | 45 #include "content/public/test/browser_test_utils.h" |
| 46 #include "content/public/test/test_navigation_observer.h" |
| 38 #include "content/public/test/test_utils.h" | 47 #include "content/public/test/test_utils.h" |
| 39 | 48 |
| 49 #if defined(OS_MACOSX) |
| 50 #include "base/mac/scoped_nsautorelease_pool.h" |
| 51 #endif |
| 52 |
| 40 using extensions::Extension; | 53 using extensions::Extension; |
| 41 using performance_monitor::Event; | 54 using performance_monitor::Event; |
| 42 | 55 |
| 43 namespace { | 56 namespace { |
| 44 | 57 |
| 58 const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); |
| 59 |
| 45 // Helper struct to store the information of an extension; this is needed if the | 60 // Helper struct to store the information of an extension; this is needed if the |
| 46 // pointer to the extension ever becomes invalid (e.g., if we uninstall the | 61 // pointer to the extension ever becomes invalid (e.g., if we uninstall the |
| 47 // extension). | 62 // extension). |
| 48 struct ExtensionBasicInfo { | 63 struct ExtensionBasicInfo { |
| 49 // Empty constructor for stl-container-happiness. | 64 // Empty constructor for stl-container-happiness. |
| 50 ExtensionBasicInfo() { | 65 ExtensionBasicInfo() { |
| 51 } | 66 } |
| 52 explicit ExtensionBasicInfo(const Extension* extension) | 67 explicit ExtensionBasicInfo(const Extension* extension) |
| 53 : description(extension->description()), | 68 : description(extension->description()), |
| 54 id(extension->id()), | 69 id(extension->id()), |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 CHECK(file_util::PathExists(second_profile_prefs_file)); | 313 CHECK(file_util::PathExists(second_profile_prefs_file)); |
| 299 | 314 |
| 300 return true; | 315 return true; |
| 301 } | 316 } |
| 302 | 317 |
| 303 protected: | 318 protected: |
| 304 std::string first_profile_name_; | 319 std::string first_profile_name_; |
| 305 std::string second_profile_name_; | 320 std::string second_profile_name_; |
| 306 }; | 321 }; |
| 307 | 322 |
| 323 class PerformanceMonitorSessionRestoreBrowserTest |
| 324 : public PerformanceMonitorBrowserTest { |
| 325 public: |
| 326 virtual void SetUpOnMainThread() OVERRIDE { |
| 327 SessionStartupPref pref(SessionStartupPref::LAST); |
| 328 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 329 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) |
| 330 // Undo the effect of kBrowserAliveWithNoWindows in defaults.cc so that we |
| 331 // can get these test to work without quitting. |
| 332 SessionServiceTestHelper helper( |
| 333 SessionServiceFactory::GetForProfile(browser()->profile())); |
| 334 helper.SetForceBrowserNotAliveWithNoWindows(true); |
| 335 helper.ReleaseService(); |
| 336 #endif |
| 337 |
| 338 PerformanceMonitorBrowserTest::SetUpOnMainThread(); |
| 339 } |
| 340 |
| 341 Browser* QuitBrowserAndRestore(Browser* browser, int expected_tab_count) { |
| 342 Profile* profile = browser->profile(); |
| 343 |
| 344 // Close the browser. |
| 345 g_browser_process->AddRefModule(); |
| 346 content::WindowedNotificationObserver observer( |
| 347 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 348 content::NotificationService::AllSources()); |
| 349 browser->window()->Close(); |
| 350 #if defined(OS_MACOSX) |
| 351 // BrowserWindowController depends on the auto release pool being recycled |
| 352 // in the message loop to delete itself, which frees the Browser object |
| 353 // which fires this event. |
| 354 AutoreleasePool()->Recycle(); |
| 355 #endif |
| 356 observer.Wait(); |
| 357 |
| 358 // Create a new window, which should trigger session restore. |
| 359 ui_test_utils::BrowserAddedObserver window_observer; |
| 360 content::TestNavigationObserver navigation_observer( |
| 361 content::NotificationService::AllSources(), NULL, expected_tab_count); |
| 362 chrome::NewEmptyWindow(profile); |
| 363 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
| 364 navigation_observer.Wait(); |
| 365 g_browser_process->ReleaseModule(); |
| 366 |
| 367 return new_browser; |
| 368 } |
| 369 }; |
| 370 |
| 308 // Test that PerformanceMonitor will correctly record an extension installation | 371 // Test that PerformanceMonitor will correctly record an extension installation |
| 309 // event. | 372 // event. |
| 310 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { | 373 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { |
| 311 FilePath extension_path; | 374 FilePath extension_path; |
| 312 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | 375 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
| 313 extension_path = extension_path.AppendASCII("performance_monitor") | 376 extension_path = extension_path.AppendASCII("performance_monitor") |
| 314 .AppendASCII("extensions") | 377 .AppendASCII("extensions") |
| 315 .AppendASCII("simple_extension_v1"); | 378 .AppendASCII("simple_extension_v1"); |
| 316 const Extension* extension = LoadExtension(extension_path); | 379 const Extension* extension = LoadExtension(extension_path); |
| 317 | 380 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]); | 687 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]); |
| 625 | 688 |
| 626 std::string event_profile; | 689 std::string event_profile; |
| 627 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); | 690 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); |
| 628 ASSERT_EQ(first_profile_name_, event_profile); | 691 ASSERT_EQ(first_profile_name_, event_profile); |
| 629 | 692 |
| 630 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile)); | 693 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile)); |
| 631 ASSERT_EQ(second_profile_name_, event_profile); | 694 ASSERT_EQ(second_profile_name_, event_profile); |
| 632 } | 695 } |
| 633 | 696 |
| 697 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, StartupTime) { |
| 698 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
| 699 |
| 700 ASSERT_EQ(1u, metrics.size()); |
| 701 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 702 } |
| 703 |
| 704 IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, |
| 705 StartupWithSessionRestore) { |
| 706 ui_test_utils::NavigateToURL( |
| 707 browser(), |
| 708 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 709 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 710 |
| 711 QuitBrowserAndRestore(browser(), 1); |
| 712 |
| 713 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
| 714 ASSERT_EQ(1u, metrics.size()); |
| 715 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 716 |
| 717 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); |
| 718 ASSERT_EQ(1u, metrics.size()); |
| 719 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 720 } |
| 721 |
| 634 } // namespace performance_monitor | 722 } // namespace performance_monitor |
| OLD | NEW |