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

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

Issue 10703078: Add Unclean Exit Watching to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_crash_event_watching
Patch Set: Created 8 years, 6 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 88be360c35f127268f867da85524a5a4476b6891..328ed96196b3f218bcfe1d99d81044f567a1869c 100644
--- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc
+++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc
@@ -7,7 +7,9 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
+#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"
@@ -15,8 +17,10 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_version_info.h"
@@ -130,6 +134,7 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
// Wait for DB to finish setting up.
content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ ui_test_utils::RunAllPendingInMessageLoop();
}
void GetEventsOnBackgroundThread(std::vector<linked_ptr<Event> >* events) {
@@ -152,6 +157,18 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
return events;
}
+ void AddStateValue(const std::string& key, const std::string& value) {
+ content::BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(base::IgnoreResult(&Database::AddStateValue),
+ base::Unretained(performance_monitor()->database()),
+ key,
+ value));
+
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ }
+
PerformanceMonitor* performance_monitor() const {
return performance_monitor_;
}
@@ -161,6 +178,39 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
PerformanceMonitor* performance_monitor_;
};
+class PerformanceMonitorUncleanExitBrowserTest
+ : public PerformanceMonitorBrowserTest {
+ public:
+ virtual bool SetUpUserDataDirectory() OVERRIDE {
+ FilePath user_data_directory;
+ PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
+
+ FilePath default_profile = user_data_directory.AppendASCII("Default");
+ CHECK(file_util::CreateDirectory(default_profile));
+
+ FilePath stock_prefs_file;
+ PathService::Get(chrome::DIR_TEST_DATA, &stock_prefs_file);
+ stock_prefs_file = stock_prefs_file.AppendASCII("performance_monitor")
+ .AppendASCII("unclean_exit_prefs");
+ CHECK(file_util::PathExists(stock_prefs_file));
+
+ FilePath default_profile_prefs_file =
+ default_profile.AppendASCII(chrome::kPreferencesFilename);
+ CHECK(file_util::CopyFile(stock_prefs_file, default_profile_prefs_file));
+ CHECK(file_util::PathExists(default_profile_prefs_file));
+
+ FilePath second_profile = user_data_directory.AppendASCII("Profile 1");
+ CHECK(file_util::CreateDirectory(second_profile));
+
+ FilePath second_profile_prefs_file =
+ second_profile.AppendASCII(chrome::kPreferencesFilename);
+ CHECK(file_util::CopyFile(stock_prefs_file, second_profile_prefs_file));
+ CHECK(file_util::PathExists(second_profile_prefs_file));
+
+ return true;
+ }
+};
+
// Test that PerformanceMonitor will correctly record an extension installation
// event.
IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) {
@@ -295,6 +345,67 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UpdateExtensionEvent) {
ASSERT_EQ(extension_misc::UNLOAD_REASON_UPDATE, unload_reason);
}
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
+ OneProfileUncleanExit) {
+ const std::string profile_name = "Default";
+ const std::string time = "12985807272597591";
+ const size_t kNumEvents = 1;
+
+ // Initialize the database value (if there's no value in the database, it
+ // can't determine the last active time of the profile, and doesn't insert
+ // the event).
+ AddStateValue(kStateProfile + profile_name, time);
+
+ performance_monitor()->CheckForUncleanExit();
+
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ std::vector<linked_ptr<Event> > events = GetEvents();
+ ASSERT_EQ(kNumEvents, events.size());
+
+ CheckEvent(EVENT_UNCLEAN_EXIT, events[0]);
+
+ std::string event_profile;
+ ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile));
+ ASSERT_EQ(profile_name, event_profile);
+}
+
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
+ TwoProfileUncleanExit) {
Yoyo Zhou 2012/07/10 02:35:06 It looks like these tests are only testing one of
Devlin 2012/07/10 17:18:32 I assume that by the "Two paths" you mean either a
Yoyo Zhou 2012/07/12 18:13:44 Yes, that's what I meant. Apparently I didn't read
+ const std::string profile1_name = "Default";
+ const std::string profile2_name = "Profile 1";
+ const std::string time1 = "12985807272597591";
+ const std::string time2 = "12985807272599918";
+ const size_t kNumEvents = 2;
+
+ FilePath profile2_path;
+ PathService::Get(chrome::DIR_USER_DATA, &profile2_path);
+ profile2_path = profile2_path.AppendASCII(profile2_name);
+
+ AddStateValue(kStateProfile + profile1_name, time1);
+ AddStateValue(kStateProfile + profile2_name, time2);
+
+ performance_monitor()->CheckForUncleanExit();
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // Load the second profile, which has also exited uncleanly.
+ g_browser_process->profile_manager()->GetProfile(profile2_path);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ std::vector<linked_ptr<Event> > events = GetEvents();
+
+ ASSERT_EQ(kNumEvents, events.size());
+ CheckEvent(EVENT_UNCLEAN_EXIT, events[0]);
+ CheckEvent(EVENT_UNCLEAN_EXIT, events[1]);
+
+ std::string event_profile;
+ ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile));
+ ASSERT_EQ(profile1_name, event_profile);
+
+ ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile));
+ ASSERT_EQ(profile2_name, event_profile);
+}
+
IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) {
ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser()));
@@ -316,15 +427,7 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) {
IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) {
const char kOldVersion[] = "0.0";
- content::BrowserThread::PostBlockingPoolSequencedTask(
- Database::kDatabaseSequenceToken,
- FROM_HERE,
- base::Bind(base::IgnoreResult(&Database::AddStateValue),
- base::Unretained(performance_monitor()->database()),
- std::string(kStateChromeVersion),
- std::string(kOldVersion)));
-
- content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ AddStateValue(kStateChromeVersion, kOldVersion);
performance_monitor()->CheckForVersionUpdate();

Powered by Google App Engine
This is Rietveld 408576698