Index: chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
diff --git a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
index 9bc3965395f3f1a771b17e1e18ef42d57c241a69..578338c7ca01b5ed35036f04f5c4551e97d5f12f 100644 |
--- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
+++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
@@ -11,16 +11,23 @@ |
#include "base/string_number_conversions.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/performance_monitor/constants.h" |
-#include "chrome/browser/performance_monitor/database.h" |
-#include "chrome/browser/performance_monitor/performance_monitor.h" |
#include "chrome/browser/extensions/extension_browsertest.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/unpacked_installer.h" |
+#include "chrome/browser/performance_monitor/constants.h" |
+#include "chrome/browser/performance_monitor/database.h" |
+#include "chrome/browser/performance_monitor/performance_monitor.h" |
+#include "chrome/browser/prefs/session_startup_pref.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/sessions/session_restore.h" |
+#include "chrome/browser/sessions/session_service.h" |
+#include "chrome/browser/sessions/session_service_test_helper.h" |
+#include "chrome/browser/sessions/session_service_factory.h" |
#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_commands.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
+#include "chrome/browser/ui/browser_window.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/chrome_paths.h" |
@@ -32,12 +39,20 @@ |
#include "content/public/browser/notification_registrar.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/test/browser_test_utils.h" |
+#include "content/public/test/test_navigation_observer.h" |
#include "content/public/test/test_utils.h" |
+#if defined(OS_MACOSX) |
+#include "base/mac/scoped_nsautorelease_pool.h" |
+#endif |
+ |
using extensions::Extension; |
using performance_monitor::Event; |
namespace { |
+ |
+const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); |
+ |
// Helper struct to store the information of an extension; this is needed if the |
// pointer to the extension ever becomes invalid (e.g., if we uninstall the |
// extension). |
@@ -179,6 +194,31 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { |
return events; |
} |
+ void GetStatsOnBackgroundThread(Database::MetricInfoVector* metrics, |
+ MetricType type) { |
+ *metrics = performance_monitor_->database()->GetStatsForActivityAndMetric( |
+ type, base::Time(), base::Time::FromInternalValue(kint64max)); |
+ } |
+ |
+ // A handle for getting statistics from the database (see previous comments on |
+ // GetEvents() and GetEventsOnBackgroundThread). |
+ Database::MetricInfoVector GetStats(MetricType type) { |
+ content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
+ content::RunAllPendingInMessageLoop(); |
+ |
+ Database::MetricInfoVector metrics; |
+ content::BrowserThread::PostBlockingPoolSequencedTask( |
+ Database::kDatabaseSequenceToken, |
+ FROM_HERE, |
+ base::Bind(&PerformanceMonitorBrowserTest::GetStatsOnBackgroundThread, |
+ base::Unretained(this), |
+ &metrics, |
+ type)); |
+ |
+ content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
+ return metrics; |
+ } |
+ |
// A handle for inserting a state value into the database, which must be done |
// on the background thread. This is useful for mocking up a scenario in which |
// the database has prior data stored. We mock synchronicity with |
@@ -263,6 +303,54 @@ class PerformanceMonitorUncleanExitBrowserTest |
std::string second_profile_name_; |
}; |
+class PerformanceMonitorSessionRestoreBrowserTest |
+ : public PerformanceMonitorBrowserTest { |
+ public: |
+ virtual void SetUpOnMainThread() OVERRIDE { |
+ SessionStartupPref pref(SessionStartupPref::LAST); |
+ SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
+#if defined(OS_CHROMEOS) || defined (OS_MACOSX) |
+ // Undo the effect of kBrowserAliveWithNoWindows in defaults.cc so that we |
+ // can get these test to work without quitting. |
+ SessionServiceTestHelper helper( |
+ SessionServiceFactory::GetForProfile(browser()->profile())); |
+ helper.SetForceBrowserNotAliveWithNoWindows(true); |
+ helper.ReleaseService(); |
+#endif |
+ |
+ PerformanceMonitorBrowserTest::SetUpOnMainThread(); |
+ } |
+ |
+ Browser* QuitBrowserAndRestore(Browser* browser, int expected_tab_count) { |
+ Profile* profile = browser->profile(); |
+ |
+ // Close the browser. |
+ g_browser_process->AddRefModule(); |
+ content::WindowedNotificationObserver observer( |
+ chrome::NOTIFICATION_BROWSER_CLOSED, |
+ content::NotificationService::AllSources()); |
+ browser->window()->Close(); |
+#if defined(OS_MACOSX) |
+ // BrowserWindowController depends on the auto release pool being recycled |
+ // in the message loop to delete itself, which frees the Browser object |
+ // which fires this event. |
+ AutoreleasePool()->Recycle(); |
+#endif |
+ observer.Wait(); |
+ |
+ // Create a new window, which should trigger session restore. |
+ ui_test_utils::BrowserAddedObserver window_observer; |
+ content::TestNavigationObserver navigation_observer( |
+ content::NotificationService::AllSources(), NULL, expected_tab_count); |
+ chrome::NewEmptyWindow(profile); |
+ Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
+ navigation_observer.Wait(); |
+ g_browser_process->ReleaseModule(); |
+ |
+ return new_browser; |
+ } |
+}; |
+ |
// Test that PerformanceMonitor will correctly record an extension installation |
// event. |
IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { |
@@ -550,4 +638,29 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest, |
ASSERT_EQ(second_profile_name_, event_profile); |
} |
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, StartupTime) { |
+ Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
+ |
+ ASSERT_EQ(1u, metrics.size()); |
+ ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, |
+ StartupWithSessionRestore) { |
+ ui_test_utils::NavigateToURL( |
+ browser(), |
+ ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
+ FilePath(FILE_PATH_LITERAL("title1.html")))); |
+ |
+ QuitBrowserAndRestore(browser(), 1); |
+ |
+ Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
+ ASSERT_EQ(1u, metrics.size()); |
+ ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
+ |
+ metrics = GetStats(METRIC_SESSION_RESTORE_TIME); |
+ ASSERT_EQ(1u, metrics.size()); |
+ ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
+} |
+ |
} // namespace performance_monitor |