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

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor_browsertest.cc

Issue 10815079: CPM: revised unclean exit watching, revised renderer crash test (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master (with OWNERS) for cq Created 8 years, 4 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 unified diff | Download patch
OLDNEW
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/file_path.h" 8 #include "base/file_path.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_number_conversions.h"
10 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/performance_monitor/constants.h" 14 #include "chrome/browser/performance_monitor/constants.h"
12 #include "chrome/browser/performance_monitor/database.h" 15 #include "chrome/browser/performance_monitor/database.h"
13 #include "chrome/browser/performance_monitor/performance_monitor.h" 16 #include "chrome/browser/performance_monitor/performance_monitor.h"
14 #include "chrome/browser/extensions/extension_browsertest.h" 17 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/unpacked_installer.h" 19 #include "chrome/browser/extensions/unpacked_installer.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/chrome_version_info.h" 28 #include "chrome/common/chrome_version_info.h"
23 #include "chrome/common/extensions/extension.h" 29 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/notification_registrar.h" 32 #include "content/public/browser/notification_registrar.h"
27 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
28 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
35 #include "content/public/test/test_utils.h"
29 36
30 using extensions::Extension; 37 using extensions::Extension;
31 using performance_monitor::Event; 38 using performance_monitor::Event;
32 39
33 namespace { 40 namespace {
34 // Helper struct to store the information of an extension; this is needed if the 41 // Helper struct to store the information of an extension; this is needed if the
35 // pointer to the extension ever becomes invalid (e.g., if we uninstall the 42 // pointer to the extension ever becomes invalid (e.g., if we uninstall the
36 // extension). 43 // extension).
37 struct ExtensionBasicInfo { 44 struct ExtensionBasicInfo {
38 // Empty constructor for stl-container-happiness. 45 // Empty constructor for stl-container-happiness.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 197
191 PerformanceMonitor* performance_monitor() const { 198 PerformanceMonitor* performance_monitor() const {
192 return performance_monitor_; 199 return performance_monitor_;
193 } 200 }
194 201
195 protected: 202 protected:
196 ScopedTempDir db_dir_; 203 ScopedTempDir db_dir_;
197 PerformanceMonitor* performance_monitor_; 204 PerformanceMonitor* performance_monitor_;
198 }; 205 };
199 206
207 class PerformanceMonitorUncleanExitBrowserTest
208 : public PerformanceMonitorBrowserTest {
209 public:
210 virtual bool SetUpUserDataDirectory() OVERRIDE {
211 FilePath user_data_directory;
212 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
213
214 // On CrOS, if we are "logged in" with the --login-profile switch,
215 // the default profile will be different. We check if we are logged in, and,
216 // if we are, we use that profile name instead. (Note: trybots will
217 // typically be logged in with 'user'.)
218 #if defined(OS_CHROMEOS)
219 const CommandLine command_line = *CommandLine::ForCurrentProcess();
220 if (command_line.HasSwitch(switches::kLoginProfile)) {
221 first_profile_name_ =
222 command_line.GetSwitchValueASCII(switches::kLoginProfile);
223 } else {
224 first_profile_name_ = chrome::kInitialProfile;
225 }
226 #else
227 first_profile_name_ = chrome::kInitialProfile;
228 #endif
229
230 FilePath first_profile =
231 user_data_directory.AppendASCII(first_profile_name_);
232 CHECK(file_util::CreateDirectory(first_profile));
233
234 FilePath stock_prefs_file;
235 PathService::Get(chrome::DIR_TEST_DATA, &stock_prefs_file);
236 stock_prefs_file = stock_prefs_file.AppendASCII("performance_monitor")
237 .AppendASCII("unclean_exit_prefs");
238 CHECK(file_util::PathExists(stock_prefs_file));
239
240 FilePath first_profile_prefs_file =
241 first_profile.Append(chrome::kPreferencesFilename);
242 CHECK(file_util::CopyFile(stock_prefs_file, first_profile_prefs_file));
243 CHECK(file_util::PathExists(first_profile_prefs_file));
244
245 second_profile_name_ =
246 std::string(chrome::kMultiProfileDirPrefix)
247 .append(base::IntToString(1));
248
249 FilePath second_profile =
250 user_data_directory.AppendASCII(second_profile_name_);
251 CHECK(file_util::CreateDirectory(second_profile));
252
253 FilePath second_profile_prefs_file =
254 second_profile.Append(chrome::kPreferencesFilename);
255 CHECK(file_util::CopyFile(stock_prefs_file, second_profile_prefs_file));
256 CHECK(file_util::PathExists(second_profile_prefs_file));
257
258 return true;
259 }
260
261 protected:
262 std::string first_profile_name_;
263 std::string second_profile_name_;
264 };
265
200 // Test that PerformanceMonitor will correctly record an extension installation 266 // Test that PerformanceMonitor will correctly record an extension installation
201 // event. 267 // event.
202 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { 268 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) {
203 FilePath extension_path; 269 FilePath extension_path;
204 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); 270 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
205 extension_path = extension_path.AppendASCII("performance_monitor") 271 extension_path = extension_path.AppendASCII("performance_monitor")
206 .AppendASCII("extensions") 272 .AppendASCII("extensions")
207 .AppendASCII("simple_extension_v1"); 273 .AppendASCII("simple_extension_v1");
208 const Extension* extension = LoadExtension(extension_path); 274 const Extension* extension = LoadExtension(extension_path);
209 275
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) { 470 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) {
405 content::CrashTab(chrome::GetActiveWebContents(browser())); 471 content::CrashTab(chrome::GetActiveWebContents(browser()));
406 472
407 std::vector<linked_ptr<Event> > events = GetEvents(); 473 std::vector<linked_ptr<Event> > events = GetEvents();
408 474
409 ASSERT_EQ(1u, events.size()); 475 ASSERT_EQ(1u, events.size());
410 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]); 476 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]);
411 } 477 }
412 #endif // !defined(OS_WIN) 478 #endif // !defined(OS_WIN)
413 479
414 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, 480 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) {
415 DISABLED_RendererCrashEvent) { 481 content::WindowedNotificationObserver windowed_observer(
482 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
483 content::NotificationService::AllSources());
484
416 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); 485 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL));
417 486
487 windowed_observer.Wait();
488
418 std::vector<linked_ptr<Event> > events = GetEvents(); 489 std::vector<linked_ptr<Event> > events = GetEvents();
419 ASSERT_EQ(1u, events.size()); 490 ASSERT_EQ(1u, events.size());
420 491
421 CheckEventType(EVENT_RENDERER_CRASH, events[0]); 492 CheckEventType(EVENT_RENDERER_CRASH, events[0]);
422 } 493 }
423 494
495 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
496 OneProfileUncleanExit) {
497 // Initialize the database value (if there's no value in the database, it
498 // can't determine the last active time of the profile, and doesn't insert
499 // the event).
500 const std::string time = "12985807272597591";
501 AddStateValue(kStateProfilePrefix + first_profile_name_, time);
502
503 performance_monitor()->CheckForUncleanExits();
504 content::RunAllPendingInMessageLoop();
505
506 std::vector<linked_ptr<Event> > events = GetEvents();
507
508 const size_t kNumEvents = 1;
509 ASSERT_EQ(kNumEvents, events.size());
510
511 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]);
512
513 std::string event_profile;
514 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile));
515 ASSERT_EQ(first_profile_name_, event_profile);
516 }
517
518 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
519 TwoProfileUncleanExit) {
520 FilePath second_profile_path;
521 PathService::Get(chrome::DIR_USER_DATA, &second_profile_path);
522 second_profile_path = second_profile_path.AppendASCII(second_profile_name_);
523
524 const std::string time1 = "12985807272597591";
525 const std::string time2 = "12985807272599918";
526
527 // Initialize the database.
528 AddStateValue(kStateProfilePrefix + first_profile_name_, time1);
529 AddStateValue(kStateProfilePrefix + second_profile_name_, time2);
530
531 performance_monitor()->CheckForUncleanExits();
532 content::RunAllPendingInMessageLoop();
533
534 // Load the second profile, which has also exited uncleanly.
535 g_browser_process->profile_manager()->GetProfile(second_profile_path);
536 content::RunAllPendingInMessageLoop();
537
538 std::vector<linked_ptr<Event> > events = GetEvents();
539
540 const size_t kNumEvents = 2;
541 ASSERT_EQ(kNumEvents, events.size());
542 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]);
543 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]);
544
545 std::string event_profile;
546 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile));
547 ASSERT_EQ(first_profile_name_, event_profile);
548
549 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile));
550 ASSERT_EQ(second_profile_name_, event_profile);
551 }
552
424 } // namespace performance_monitor 553 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698