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

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: Requested changes added 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 9bc3965395f3f1a771b17e1e18ef42d57c241a69..e1606cc5bab704d9e41c8c5935061ba867bb8a54 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,12 +38,19 @@
#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 {
Yoyo Zhou 2012/08/02 11:33:34 nit: newline after
Devlin 2012/08/07 22:51:22 Done.
+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 +192,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 +301,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) {
@@ -550,4 +634,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

Powered by Google App Engine
This is Rietveld 408576698