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

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: 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 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 34
29 using extensions::Extension; 35 using extensions::Extension;
30 using performance_monitor::Event; 36 using performance_monitor::Event;
31 37
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 195
190 PerformanceMonitor* performance_monitor() const { 196 PerformanceMonitor* performance_monitor() const {
191 return performance_monitor_; 197 return performance_monitor_;
192 } 198 }
193 199
194 protected: 200 protected:
195 ScopedTempDir db_dir_; 201 ScopedTempDir db_dir_;
196 PerformanceMonitor* performance_monitor_; 202 PerformanceMonitor* performance_monitor_;
197 }; 203 };
198 204
205 class PerformanceMonitorUncleanExitBrowserTest
206 : public PerformanceMonitorBrowserTest {
207 public:
208 virtual bool SetUpUserDataDirectory() OVERRIDE {
209 FilePath user_data_directory;
210 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
211
212 // The default profile directory can be changed on CrOS if we are logged in
Yoyo Zhou 2012/07/30 09:01:02 What does 'can be changed' mean?
Devlin 2012/07/30 17:22:25 I hope this is a bit more descriptive? The entire
213 // (trybots and buildbots are typically logged in as 'user'), so we need
214 // a separate definition.
215 #if defined(OS_CHROMEOS)
216 const CommandLine command_line = *CommandLine::ForCurrentProcess();
217 if (command_line.HasSwitch(switches::kLoginProfile)) {
Yoyo Zhou 2012/07/30 09:01:02 What's the default setup for this switch on the Ch
Devlin 2012/07/30 17:22:25 Unfortunately, I couldn't find anything saying whi
218 first_profile_name_ =
219 command_line.GetSwitchValueASCII(switches::kLoginProfile);
220 } else {
221 first_profile_name_ = chrome::kInitialProfile;
222 }
223 #else
224 first_profile_name_ = chrome::kInitialProfile;
225 #endif
226
227 FilePath first_profile =
228 user_data_directory.AppendASCII(first_profile_name_);
229 CHECK(file_util::CreateDirectory(first_profile));
230
231 FilePath stock_prefs_file;
232 PathService::Get(chrome::DIR_TEST_DATA, &stock_prefs_file);
233 stock_prefs_file = stock_prefs_file.AppendASCII("performance_monitor")
234 .AppendASCII("unclean_exit_prefs");
235 CHECK(file_util::PathExists(stock_prefs_file));
236
237 FilePath first_profile_prefs_file =
238 first_profile.Append(chrome::kPreferencesFilename);
239 CHECK(file_util::CopyFile(stock_prefs_file, first_profile_prefs_file));
240 CHECK(file_util::PathExists(first_profile_prefs_file));
241
242 second_profile_name_ =
243 std::string(chrome::kMultiProfileDirPrefix)
244 .append(base::IntToString(1));
245
246 FilePath second_profile =
247 user_data_directory.AppendASCII(second_profile_name_);
248 CHECK(file_util::CreateDirectory(second_profile));
249
250 FilePath second_profile_prefs_file =
251 second_profile.Append(chrome::kPreferencesFilename);
252 CHECK(file_util::CopyFile(stock_prefs_file, second_profile_prefs_file));
253 CHECK(file_util::PathExists(second_profile_prefs_file));
254
255 return true;
256 }
257
258 std::string first_profile_name() { return first_profile_name_; }
Yoyo Zhou 2012/07/30 09:01:02 nit: it doesn't look like these accessors are nece
Devlin 2012/07/30 17:22:25 Whoops, sorry - habit to have accessors instead of
259 std::string second_profile_name() { return second_profile_name_; }
260
261 protected:
262 std::string first_profile_name_;
263 std::string second_profile_name_;
264 };
265
199 // Test that PerformanceMonitor will correctly record an extension installation 266 // Test that PerformanceMonitor will correctly record an extension installation
200 // event. 267 // event.
201 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { 268 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) {
202 FilePath extension_path; 269 FilePath extension_path;
203 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); 270 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
204 extension_path = extension_path.AppendASCII("performance_monitor") 271 extension_path = extension_path.AppendASCII("performance_monitor")
205 .AppendASCII("extensions") 272 .AppendASCII("extensions")
206 .AppendASCII("simple_extension_v1"); 273 .AppendASCII("simple_extension_v1");
207 const Extension* extension = LoadExtension(extension_path); 274 const Extension* extension = LoadExtension(extension_path);
208 275
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) { 470 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) {
404 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); 471 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser()));
405 472
406 std::vector<linked_ptr<Event> > events = GetEvents(); 473 std::vector<linked_ptr<Event> > events = GetEvents();
407 474
408 ASSERT_EQ(1u, events.size()); 475 ASSERT_EQ(1u, events.size());
409 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]); 476 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]);
410 } 477 }
411 #endif // !defined(OS_WIN) 478 #endif // !defined(OS_WIN)
412 479
413 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, 480 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) {
414 DISABLED_RendererCrashEvent) { 481 content::WindowedNotificationObserver windowed_observer(
482 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
483 content::NotificationService::AllSources());
484
415 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); 485 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL));
416 486
487 windowed_observer.Wait();
488
417 std::vector<linked_ptr<Event> > events = GetEvents(); 489 std::vector<linked_ptr<Event> > events = GetEvents();
418 ASSERT_EQ(1u, events.size()); 490 ASSERT_EQ(1u, events.size());
419 491
420 CheckEventType(EVENT_RENDERER_CRASH, events[0]); 492 CheckEventType(EVENT_RENDERER_CRASH, events[0]);
421 } 493 }
422 494
495 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
496 OneProfileUncleanExit) {
497 const std::string time = "12985807272597591";
498 const size_t kNumEvents = 1;
Yoyo Zhou 2012/07/30 09:01:02 Define this closer to where it's used.
Devlin 2012/07/30 17:22:25 Done.
499
500 // Initialize the database value (if there's no value in the database, it
501 // can't determine the last active time of the profile, and doesn't insert
502 // the event).
503 AddStateValue(kStateProfilePrefix + first_profile_name(), time);
504
505 performance_monitor()->CheckForUncleanExits();
506
507 ui_test_utils::RunAllPendingInMessageLoop();
508
509 std::vector<linked_ptr<Event> > events = GetEvents();
510 ASSERT_EQ(kNumEvents, events.size());
511
512 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]);
513
514 std::string event_profile;
515 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile));
516 ASSERT_EQ(first_profile_name(), event_profile);
517 }
518
519 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest,
520 TwoProfileUncleanExit) {
521 const std::string time1 = "12985807272597591";
522 const std::string time2 = "12985807272599918";
523 const size_t kNumEvents = 2;
Yoyo Zhou 2012/07/30 09:01:02 ditto
Devlin 2012/07/30 17:22:25 Done.
524
525 FilePath second_profile_path;
526 PathService::Get(chrome::DIR_USER_DATA, &second_profile_path);
527 second_profile_path = second_profile_path.AppendASCII(second_profile_name());
528
529 AddStateValue(kStateProfilePrefix + first_profile_name(), time1);
530 AddStateValue(kStateProfilePrefix + second_profile_name(), time2);
531
532 performance_monitor()->CheckForUncleanExits();
533 ui_test_utils::RunAllPendingInMessageLoop();
534
535 // Load the second profile, which has also exited uncleanly.
536 g_browser_process->profile_manager()->GetProfile(second_profile_path);
537 ui_test_utils::RunAllPendingInMessageLoop();
538
539 std::vector<linked_ptr<Event> > events = GetEvents();
540
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
423 } // namespace performance_monitor 553 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698