| 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" | |
| 6 | |
| 7 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 11 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/unpacked_installer.h" | |
| 17 #include "chrome/browser/performance_monitor/constants.h" | 14 #include "chrome/browser/performance_monitor/constants.h" |
| 18 #include "chrome/browser/performance_monitor/database.h" | 15 #include "chrome/browser/performance_monitor/database.h" |
| 19 #include "chrome/browser/performance_monitor/performance_monitor.h" | 16 #include "chrome/browser/performance_monitor/performance_monitor.h" |
| 20 #include "chrome/browser/prefs/session_startup_pref.h" | 17 #include "chrome/browser/prefs/session_startup_pref.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/sessions/session_restore.h" | |
| 24 #include "chrome/browser/sessions/session_service.h" | 20 #include "chrome/browser/sessions/session_service.h" |
| 21 #include "chrome/browser/sessions/session_service_factory.h" |
| 25 #include "chrome/browser/sessions/session_service_test_helper.h" | 22 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 26 #include "chrome/browser/sessions/session_service_factory.h" | |
| 27 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 29 #include "chrome/browser/ui/browser_navigator.h" | 25 #include "chrome/browser/ui/browser_navigator.h" |
| 30 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 34 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 35 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 36 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/chrome_version_info.h" | 32 #include "chrome/common/chrome_version_info.h" |
| 39 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
| 40 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 41 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 42 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
| 43 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 Database::kDatabaseSequenceToken, | 239 Database::kDatabaseSequenceToken, |
| 246 FROM_HERE, | 240 FROM_HERE, |
| 247 base::Bind(base::IgnoreResult(&Database::AddStateValue), | 241 base::Bind(base::IgnoreResult(&Database::AddStateValue), |
| 248 base::Unretained(performance_monitor()->database()), | 242 base::Unretained(performance_monitor()->database()), |
| 249 key, | 243 key, |
| 250 value)); | 244 value)); |
| 251 | 245 |
| 252 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 246 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 253 } | 247 } |
| 254 | 248 |
| 249 // A handle for PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread(); |
| 250 // we mock synchronicity with FlushForTesting(). |
| 251 void CheckForVersionUpdate() { |
| 252 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 253 Database::kDatabaseSequenceToken, |
| 254 FROM_HERE, |
| 255 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread, |
| 256 base::Unretained(performance_monitor()))); |
| 257 |
| 258 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 259 } |
| 260 |
| 255 PerformanceMonitor* performance_monitor() const { | 261 PerformanceMonitor* performance_monitor() const { |
| 256 return performance_monitor_; | 262 return performance_monitor_; |
| 257 } | 263 } |
| 258 | 264 |
| 259 protected: | 265 protected: |
| 260 ScopedTempDir db_dir_; | 266 ScopedTempDir db_dir_; |
| 261 PerformanceMonitor* performance_monitor_; | 267 PerformanceMonitor* performance_monitor_; |
| 262 }; | 268 }; |
| 263 | 269 |
| 264 class PerformanceMonitorUncleanExitBrowserTest | 270 class PerformanceMonitorUncleanExitBrowserTest |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 .AppendASCII("extensions") | 406 .AppendASCII("extensions") |
| 401 .AppendASCII("simple_extension_v1"); | 407 .AppendASCII("simple_extension_v1"); |
| 402 const Extension* extension = LoadExtension(extension_path); | 408 const Extension* extension = LoadExtension(extension_path); |
| 403 | 409 |
| 404 DisableExtension(extension->id()); | 410 DisableExtension(extension->id()); |
| 405 EnableExtension(extension->id()); | 411 EnableExtension(extension->id()); |
| 406 | 412 |
| 407 std::vector<ExtensionBasicInfo> extension_infos; | 413 std::vector<ExtensionBasicInfo> extension_infos; |
| 408 // There will be three events in all, each pertaining to the same extension: | 414 // There will be three events in all, each pertaining to the same extension: |
| 409 // Extension Install | 415 // Extension Install |
| 410 // Extension Unload | 416 // Extension Disable |
| 411 // Extension Enable | 417 // Extension Enable |
| 412 for (int i = 0; i < kNumEvents; ++i) | 418 for (int i = 0; i < kNumEvents; ++i) |
| 413 extension_infos.push_back(ExtensionBasicInfo(extension)); | 419 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 414 | 420 |
| 415 std::vector<int> expected_event_types; | 421 std::vector<int> expected_event_types; |
| 416 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 422 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 417 expected_event_types.push_back(EVENT_EXTENSION_UNLOAD); | 423 expected_event_types.push_back(EVENT_EXTENSION_DISABLE); |
| 418 expected_event_types.push_back(EVENT_EXTENSION_ENABLE); | 424 expected_event_types.push_back(EVENT_EXTENSION_ENABLE); |
| 419 | 425 |
| 420 std::vector<linked_ptr<Event> > events = GetEvents(); | 426 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 421 CheckExtensionEvents(expected_event_types, events, extension_infos); | 427 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 422 | |
| 423 // There will be an additional field on the unload event: Unload Reason. | |
| 424 int unload_reason = -1; | |
| 425 ASSERT_TRUE(events[1]->data()->GetInteger("unloadReason", &unload_reason)); | |
| 426 ASSERT_EQ(extension_misc::UNLOAD_REASON_DISABLE, unload_reason); | |
| 427 } | 428 } |
| 428 | 429 |
| 429 // Test that PerformanceMonitor correctly records an extension update event. | 430 // Test that PerformanceMonitor correctly records an extension update event. |
| 430 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UpdateExtensionEvent) { | 431 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UpdateExtensionEvent) { |
| 431 ScopedTempDir temp_dir; | 432 ScopedTempDir temp_dir; |
| 432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 433 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 433 | 434 |
| 434 FilePath test_data_dir; | 435 FilePath test_data_dir; |
| 435 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 436 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 436 test_data_dir = test_data_dir.AppendASCII("performance_monitor") | 437 test_data_dir = test_data_dir.AppendASCII("performance_monitor") |
| (...skipping 29 matching lines...) Expand all Loading... |
| 466 ASSERT_TRUE(extension_service-> | 467 ASSERT_TRUE(extension_service-> |
| 467 UpdateExtension(extension->id(), path_v2_, GURL(), &crx_installer)); | 468 UpdateExtension(extension->id(), path_v2_, GURL(), &crx_installer)); |
| 468 windowed_observer.Wait(); | 469 windowed_observer.Wait(); |
| 469 | 470 |
| 470 extension = extension_service->GetExtensionById( | 471 extension = extension_service->GetExtensionById( |
| 471 extension_infos[0].id, false); // don't include disabled extensions. | 472 extension_infos[0].id, false); // don't include disabled extensions. |
| 472 | 473 |
| 473 // The total series of events for this process will be: | 474 // The total series of events for this process will be: |
| 474 // Extension Install - install version 1 | 475 // Extension Install - install version 1 |
| 475 // Extension Install - install version 2 | 476 // Extension Install - install version 2 |
| 476 // Extension Unload - disable version 1 | |
| 477 // Extension Update - signal the udate to version 2 | 477 // Extension Update - signal the udate to version 2 |
| 478 // We push back the corresponding ExtensionBasicInfos. | 478 // We push back the corresponding ExtensionBasicInfos. |
| 479 extension_infos.push_back(ExtensionBasicInfo(extension)); | 479 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 480 extension_infos.push_back(extension_infos[0]); | |
| 481 extension_infos.push_back(extension_infos[1]); | 480 extension_infos.push_back(extension_infos[1]); |
| 482 | 481 |
| 483 std::vector<int> expected_event_types; | 482 std::vector<int> expected_event_types; |
| 484 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 483 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 485 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 484 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 486 expected_event_types.push_back(EVENT_EXTENSION_UNLOAD); | |
| 487 expected_event_types.push_back(EVENT_EXTENSION_UPDATE); | 485 expected_event_types.push_back(EVENT_EXTENSION_UPDATE); |
| 488 | 486 |
| 489 std::vector<linked_ptr<Event> > events = GetEvents(); | 487 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 490 | 488 |
| 491 CheckExtensionEvents(expected_event_types, events, extension_infos); | 489 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 492 | |
| 493 // There will be an additional field: The unload reason. | |
| 494 int unload_reason = -1; | |
| 495 ASSERT_TRUE(events[2]->data()->GetInteger("unloadReason", &unload_reason)); | |
| 496 ASSERT_EQ(extension_misc::UNLOAD_REASON_UPDATE, unload_reason); | |
| 497 } | 490 } |
| 498 | 491 |
| 499 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UninstallExtensionEvent) { | 492 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UninstallExtensionEvent) { |
| 500 const int kNumEvents = 3; | 493 const int kNumEvents = 2; |
| 501 FilePath extension_path; | 494 FilePath extension_path; |
| 502 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | 495 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
| 503 extension_path = extension_path.AppendASCII("performance_monitor") | 496 extension_path = extension_path.AppendASCII("performance_monitor") |
| 504 .AppendASCII("extensions") | 497 .AppendASCII("extensions") |
| 505 .AppendASCII("simple_extension_v1"); | 498 .AppendASCII("simple_extension_v1"); |
| 506 const Extension* extension = LoadExtension(extension_path); | 499 const Extension* extension = LoadExtension(extension_path); |
| 507 | 500 |
| 508 std::vector<ExtensionBasicInfo> extension_infos; | 501 std::vector<ExtensionBasicInfo> extension_infos; |
| 509 // There will be three events in all, each pertaining to the same extension: | 502 // There will be two events, both pertaining to the same extension: |
| 510 // Extension Install | 503 // Extension Install |
| 511 // Extension Disable (Unload) | |
| 512 // Extension Uninstall | 504 // Extension Uninstall |
| 513 for (int i = 0; i < kNumEvents; ++i) | 505 for (int i = 0; i < kNumEvents; ++i) |
| 514 extension_infos.push_back(ExtensionBasicInfo(extension)); | 506 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 515 | 507 |
| 516 UninstallExtension(extension->id()); | 508 UninstallExtension(extension->id()); |
| 517 | 509 |
| 518 std::vector<int> expected_event_types; | 510 std::vector<int> expected_event_types; |
| 519 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 511 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 520 expected_event_types.push_back(EVENT_EXTENSION_UNLOAD); | |
| 521 expected_event_types.push_back(EVENT_EXTENSION_UNINSTALL); | 512 expected_event_types.push_back(EVENT_EXTENSION_UNINSTALL); |
| 522 | 513 |
| 523 std::vector<linked_ptr<Event> > events = GetEvents(); | 514 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 524 | 515 |
| 525 CheckExtensionEvents(expected_event_types, events, extension_infos); | 516 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 526 | |
| 527 // There will be an additional field: The unload reason. | |
| 528 int unload_reason = -1; | |
| 529 ASSERT_TRUE(events[1]->data()->GetInteger("unloadReason", &unload_reason)); | |
| 530 ASSERT_EQ(extension_misc::UNLOAD_REASON_UNINSTALL, unload_reason); | |
| 531 } | 517 } |
| 532 | 518 |
| 533 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) { | 519 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) { |
| 534 const char kOldVersion[] = "0.0"; | 520 const char kOldVersion[] = "0.0"; |
| 535 | 521 |
| 536 // The version in the database right now will be the current version of chrome | 522 // The version in the database right now will be the current version of chrome |
| 537 // (gathered at initialization of PerformanceMonitor). Replace this with an | 523 // (gathered at initialization of PerformanceMonitor). Replace this with an |
| 538 // older version so an event is generated. | 524 // older version so an event is generated. |
| 539 AddStateValue(kStateChromeVersion, kOldVersion); | 525 AddStateValue(kStateChromeVersion, kOldVersion); |
| 540 | 526 |
| 541 content::BrowserThread::PostBlockingPoolSequencedTask( | 527 CheckForVersionUpdate(); |
| 542 Database::kDatabaseSequenceToken, | |
| 543 FROM_HERE, | |
| 544 base::Bind(&PerformanceMonitor::CheckForVersionUpdateOnBackgroundThread, | |
| 545 base::Unretained(performance_monitor()))); | |
| 546 | |
| 547 // Wait for event insertion. | |
| 548 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 549 | 528 |
| 550 chrome::VersionInfo version; | 529 chrome::VersionInfo version; |
| 551 ASSERT_TRUE(version.is_valid()); | 530 ASSERT_TRUE(version.is_valid()); |
| 552 std::string version_string = version.Version(); | 531 std::string version_string = version.Version(); |
| 553 | 532 |
| 554 std::vector<linked_ptr<Event> > events = GetEvents(); | 533 std::vector<linked_ptr<Event> > events = GetEvents(); |
| 555 ASSERT_EQ(1u, events.size()); | 534 ASSERT_EQ(1u, events.size()); |
| 556 ASSERT_EQ(EVENT_CHROME_UPDATE, events[0]->type()); | 535 ASSERT_EQ(EVENT_CHROME_UPDATE, events[0]->type()); |
| 557 | 536 |
| 558 const base::DictionaryValue* value; | 537 const base::DictionaryValue* value; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 577 | 556 |
| 578 stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE); | 557 stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE); |
| 579 ASSERT_EQ(1u, stats.size()); | 558 ASSERT_EQ(1u, stats.size()); |
| 580 EXPECT_GT(stats[0].value, 0); | 559 EXPECT_GT(stats[0].value, 0); |
| 581 | 560 |
| 582 stats = GetStats(METRIC_SHARED_MEMORY_USAGE); | 561 stats = GetStats(METRIC_SHARED_MEMORY_USAGE); |
| 583 ASSERT_EQ(1u, stats.size()); | 562 ASSERT_EQ(1u, stats.size()); |
| 584 EXPECT_GT(stats[0].value, 0); | 563 EXPECT_GT(stats[0].value, 0); |
| 585 | 564 |
| 586 // Open new tabs to incur CPU usage. | 565 // Open new tabs to incur CPU usage. |
| 587 for (int i = 0; i < 3; ++i) { | 566 for (int i = 0; i < 10; ++i) { |
| 588 chrome::NavigateParams params(browser(), GURL("http://www.google.com"), | 567 chrome::NavigateParams params( |
| 568 browser(), |
| 569 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 570 FilePath(FILE_PATH_LITERAL("title1.html"))), |
| 589 content::PAGE_TRANSITION_LINK); | 571 content::PAGE_TRANSITION_LINK); |
| 590 params.disposition = NEW_BACKGROUND_TAB; | 572 params.disposition = NEW_BACKGROUND_TAB; |
| 591 ui_test_utils::NavigateToURL(¶ms); | 573 ui_test_utils::NavigateToURL(¶ms); |
| 592 } | 574 } |
| 593 GatherStatistics(); | 575 GatherStatistics(); |
| 594 | 576 |
| 595 // One CPUUsage stat should exist now. | 577 // One CPUUsage stat should exist now. |
| 596 stats = GetStats(METRIC_CPU_USAGE); | 578 stats = GetStats(METRIC_CPU_USAGE); |
| 597 ASSERT_EQ(1u, stats.size()); | 579 ASSERT_EQ(1u, stats.size()); |
| 598 EXPECT_GT(stats[0].value, 0); | 580 EXPECT_GT(stats[0].value, 0); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); | 695 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
| 714 ASSERT_EQ(1u, metrics.size()); | 696 ASSERT_EQ(1u, metrics.size()); |
| 715 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); | 697 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 716 | 698 |
| 717 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); | 699 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); |
| 718 ASSERT_EQ(1u, metrics.size()); | 700 ASSERT_EQ(1u, metrics.size()); |
| 719 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); | 701 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 720 } | 702 } |
| 721 | 703 |
| 722 } // namespace performance_monitor | 704 } // namespace performance_monitor |
| OLD | NEW |