Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1635)

Unified Diff: chrome/browser/performance_monitor/performance_monitor_browsertest.cc

Issue 10834015: Add Startup Timing to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e10d8ba0a41cff7a03acb818cd8de96b3937b6df..c8163e45037337248a5bb99c391d94b44a2ca237 100644
--- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc
+++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc
@@ -17,10 +17,16 @@
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/unpacked_installer.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_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,6 +38,11 @@
#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"
+
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
using extensions::Extension;
using performance_monitor::Event;
@@ -178,6 +189,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();
+ ui_test_utils::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
@@ -262,6 +298,52 @@ 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.
+ SessionServiceFactory::GetForProfile(browser()->profile())->
+ force_browser_not_alive_with_no_windows_ = true;
+#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) {
@@ -549,4 +631,35 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
ASSERT_EQ(second_profile_name_, event_profile);
}
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, StartupTime) {
+ // Since the test itself is limited to a timeout of 45 seconds, we should
+ // never report a startup time of a minute or more.
+ const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(1);
Yoyo Zhou 2012/07/31 09:57:32 Seems like you could put this in an anonymous name
Devlin 2012/07/31 16:43:40 Moved to anonymous namespace, but I'm not sure abo
+
+ 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) {
+ const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(1);
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698