OLD | NEW |
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/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_number_conversions.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/performance_monitor/constants.h" | 13 #include "chrome/browser/performance_monitor/constants.h" |
12 #include "chrome/browser/performance_monitor/database.h" | 14 #include "chrome/browser/performance_monitor/database.h" |
13 #include "chrome/browser/performance_monitor/performance_monitor.h" | 15 #include "chrome/browser/performance_monitor/performance_monitor.h" |
14 #include "chrome/browser/extensions/extension_browsertest.h" | 16 #include "chrome/browser/extensions/extension_browsertest.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/unpacked_installer.h" | 18 #include "chrome/browser/extensions/unpacked_installer.h" |
17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
| 23 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
23 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
24 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
28 | 32 |
29 using extensions::Extension; | 33 using extensions::Extension; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 193 |
190 PerformanceMonitor* performance_monitor() const { | 194 PerformanceMonitor* performance_monitor() const { |
191 return performance_monitor_; | 195 return performance_monitor_; |
192 } | 196 } |
193 | 197 |
194 protected: | 198 protected: |
195 ScopedTempDir db_dir_; | 199 ScopedTempDir db_dir_; |
196 PerformanceMonitor* performance_monitor_; | 200 PerformanceMonitor* performance_monitor_; |
197 }; | 201 }; |
198 | 202 |
| 203 class PerformanceMonitorUncleanExitBrowserTest |
| 204 : public PerformanceMonitorBrowserTest { |
| 205 public: |
| 206 virtual bool SetUpUserDataDirectory() OVERRIDE { |
| 207 FilePath user_data_directory; |
| 208 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); |
| 209 |
| 210 FilePath default_profile = user_data_directory.AppendASCII("Default"); |
| 211 CHECK(file_util::CreateDirectory(default_profile)); |
| 212 |
| 213 FilePath stock_prefs_file; |
| 214 PathService::Get(chrome::DIR_TEST_DATA, &stock_prefs_file); |
| 215 stock_prefs_file = stock_prefs_file.AppendASCII("performance_monitor") |
| 216 .AppendASCII("unclean_exit_prefs"); |
| 217 CHECK(file_util::PathExists(stock_prefs_file)); |
| 218 |
| 219 FilePath default_profile_prefs_file = |
| 220 default_profile.Append(chrome::kPreferencesFilename); |
| 221 CHECK(file_util::CopyFile(stock_prefs_file, default_profile_prefs_file)); |
| 222 CHECK(file_util::PathExists(default_profile_prefs_file)); |
| 223 |
| 224 FilePath second_profile = user_data_directory.AppendASCII("Profile 1"); |
| 225 CHECK(file_util::CreateDirectory(second_profile)); |
| 226 |
| 227 FilePath second_profile_prefs_file = |
| 228 second_profile.Append(chrome::kPreferencesFilename); |
| 229 CHECK(file_util::CopyFile(stock_prefs_file, second_profile_prefs_file)); |
| 230 CHECK(file_util::PathExists(second_profile_prefs_file)); |
| 231 |
| 232 return true; |
| 233 } |
| 234 }; |
| 235 |
199 // Test that PerformanceMonitor will correctly record an extension installation | 236 // Test that PerformanceMonitor will correctly record an extension installation |
200 // event. | 237 // event. |
201 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { | 238 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, InstallExtensionEvent) { |
202 FilePath extension_path; | 239 FilePath extension_path; |
203 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | 240 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
204 extension_path = extension_path.AppendASCII("performance_monitor") | 241 extension_path = extension_path.AppendASCII("performance_monitor") |
205 .AppendASCII("extensions") | 242 .AppendASCII("extensions") |
206 .AppendASCII("simple_extension_v1"); | 243 .AppendASCII("simple_extension_v1"); |
207 const Extension* extension = LoadExtension(extension_path); | 244 const Extension* extension = LoadExtension(extension_path); |
208 | 245 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 449 |
413 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) { | 450 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) { |
414 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 451 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
415 | 452 |
416 std::vector<linked_ptr<Event> > events = GetEvents(); | 453 std::vector<linked_ptr<Event> > events = GetEvents(); |
417 ASSERT_EQ(1u, events.size()); | 454 ASSERT_EQ(1u, events.size()); |
418 | 455 |
419 CheckEventType(EVENT_RENDERER_CRASH, events[0]); | 456 CheckEventType(EVENT_RENDERER_CRASH, events[0]); |
420 } | 457 } |
421 | 458 |
| 459 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest, |
| 460 OneProfileUncleanExit) { |
| 461 const std::string profile_name = "Default"; |
| 462 const std::string time = "12985807272597591"; |
| 463 const size_t kNumEvents = 1; |
| 464 |
| 465 // Initialize the database value (if there's no value in the database, it |
| 466 // can't determine the last active time of the profile, and doesn't insert |
| 467 // the event). |
| 468 AddStateValue(kStateProfilePrefix + profile_name, time); |
| 469 |
| 470 performance_monitor()->CheckForUncleanExits(); |
| 471 |
| 472 ui_test_utils::RunAllPendingInMessageLoop(); |
| 473 |
| 474 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 475 ASSERT_EQ(kNumEvents, events.size()); |
| 476 |
| 477 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); |
| 478 |
| 479 std::string event_profile; |
| 480 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); |
| 481 ASSERT_EQ(profile_name, event_profile); |
| 482 } |
| 483 |
| 484 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest, |
| 485 TwoProfileUncleanExit) { |
| 486 const std::string profile1_name = "Default"; |
| 487 const std::string profile2_name = "Profile 1"; |
| 488 const std::string time1 = "12985807272597591"; |
| 489 const std::string time2 = "12985807272599918"; |
| 490 const size_t kNumEvents = 2; |
| 491 |
| 492 FilePath profile2_path; |
| 493 PathService::Get(chrome::DIR_USER_DATA, &profile2_path); |
| 494 profile2_path = profile2_path.AppendASCII(profile2_name); |
| 495 |
| 496 AddStateValue(kStateProfilePrefix + profile1_name, time1); |
| 497 AddStateValue(kStateProfilePrefix + profile2_name, time2); |
| 498 |
| 499 performance_monitor()->CheckForUncleanExits(); |
| 500 ui_test_utils::RunAllPendingInMessageLoop(); |
| 501 |
| 502 // Load the second profile, which has also exited uncleanly. |
| 503 g_browser_process->profile_manager()->GetProfile(profile2_path); |
| 504 ui_test_utils::RunAllPendingInMessageLoop(); |
| 505 |
| 506 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 507 |
| 508 ASSERT_EQ(kNumEvents, events.size()); |
| 509 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); |
| 510 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]); |
| 511 |
| 512 std::string event_profile; |
| 513 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); |
| 514 ASSERT_EQ(profile1_name, event_profile); |
| 515 |
| 516 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile)); |
| 517 ASSERT_EQ(profile2_name, event_profile); |
| 518 } |
| 519 |
422 } // namespace performance_monitor | 520 } // namespace performance_monitor |
OLD | NEW |