| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/performance_monitor/constants.h" | 14 #include "chrome/browser/performance_monitor/constants.h" |
| 15 #include "chrome/browser/performance_monitor/database.h" | 15 #include "chrome/browser/performance_monitor/database.h" |
| 16 #include "chrome/browser/performance_monitor/metric.h" |
| 16 #include "chrome/browser/performance_monitor/performance_monitor.h" | 17 #include "chrome/browser/performance_monitor/performance_monitor.h" |
| 17 #include "chrome/browser/prefs/session_startup_pref.h" | 18 #include "chrome/browser/prefs/session_startup_pref.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/sessions/session_service.h" | 21 #include "chrome/browser/sessions/session_service.h" |
| 21 #include "chrome/browser/sessions/session_service_factory.h" | 22 #include "chrome/browser/sessions/session_service_factory.h" |
| 22 #include "chrome/browser/sessions/session_service_test_helper.h" | 23 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
| 25 #include "chrome/browser/ui/browser_navigator.h" | 26 #include "chrome/browser/ui/browser_navigator.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 #include "content/public/common/page_transition_types.h" | 39 #include "content/public/common/page_transition_types.h" |
| 39 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 40 #include "content/public/test/test_navigation_observer.h" | 41 #include "content/public/test/test_navigation_observer.h" |
| 41 #include "content/public/test/test_utils.h" | 42 #include "content/public/test/test_utils.h" |
| 42 | 43 |
| 43 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 44 #include "base/mac/scoped_nsautorelease_pool.h" | 45 #include "base/mac/scoped_nsautorelease_pool.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 using extensions::Extension; | 48 using extensions::Extension; |
| 48 using performance_monitor::Event; | 49 |
| 50 namespace performance_monitor { |
| 49 | 51 |
| 50 namespace { | 52 namespace { |
| 51 | 53 |
| 52 const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); | 54 const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); |
| 53 | 55 |
| 54 // Helper struct to store the information of an extension; this is needed if the | 56 // Helper struct to store the information of an extension; this is needed if the |
| 55 // pointer to the extension ever becomes invalid (e.g., if we uninstall the | 57 // pointer to the extension ever becomes invalid (e.g., if we uninstall the |
| 56 // extension). | 58 // extension). |
| 57 struct ExtensionBasicInfo { | 59 struct ExtensionBasicInfo { |
| 58 // Empty constructor for stl-container-happiness. | 60 // Empty constructor for stl-container-happiness. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void CheckEventType(int expected_event_type, const linked_ptr<Event>& event) { | 107 void CheckEventType(int expected_event_type, const linked_ptr<Event>& event) { |
| 106 int event_type = -1; | 108 int event_type = -1; |
| 107 ASSERT_TRUE(event->data()->GetInteger("eventType", &event_type)); | 109 ASSERT_TRUE(event->data()->GetInteger("eventType", &event_type)); |
| 108 ASSERT_EQ(expected_event_type, event_type); | 110 ASSERT_EQ(expected_event_type, event_type); |
| 109 ASSERT_EQ(expected_event_type, event->type()); | 111 ASSERT_EQ(expected_event_type, event->type()); |
| 110 } | 112 } |
| 111 | 113 |
| 112 // Verify that we received the proper number of events, checking the type of | 114 // Verify that we received the proper number of events, checking the type of |
| 113 // each one. | 115 // each one. |
| 114 void CheckEventTypes(const std::vector<int> expected_event_types, | 116 void CheckEventTypes(const std::vector<int> expected_event_types, |
| 115 const std::vector<linked_ptr<Event> >& events) { | 117 const Database::EventVector& events) { |
| 116 ASSERT_EQ(expected_event_types.size(), events.size()); | 118 ASSERT_EQ(expected_event_types.size(), events.size()); |
| 117 | 119 |
| 118 for (size_t i = 0; i < expected_event_types.size(); ++i) | 120 for (size_t i = 0; i < expected_event_types.size(); ++i) |
| 119 CheckEventType(expected_event_types[i], events[i]); | 121 CheckEventType(expected_event_types[i], events[i]); |
| 120 } | 122 } |
| 121 | 123 |
| 122 // Check that we received the proper number of events, that each event is of the | 124 // Check that we received the proper number of events, that each event is of the |
| 123 // proper type, and that each event recorded the proper information about the | 125 // proper type, and that each event recorded the proper information about the |
| 124 // extension. | 126 // extension. |
| 125 void CheckExtensionEvents( | 127 void CheckExtensionEvents( |
| 126 const std::vector<int>& expected_event_types, | 128 const std::vector<int>& expected_event_types, |
| 127 const std::vector<linked_ptr<Event> >& events, | 129 const Database::EventVector& events, |
| 128 const std::vector<ExtensionBasicInfo>& extension_infos) { | 130 const std::vector<ExtensionBasicInfo>& extension_infos) { |
| 129 CheckEventTypes(expected_event_types, events); | 131 CheckEventTypes(expected_event_types, events); |
| 130 | 132 |
| 131 for (size_t i = 0; i < expected_event_types.size(); ++i) { | 133 for (size_t i = 0; i < expected_event_types.size(); ++i) { |
| 132 ValidateExtensionInfo(extension_infos[i], events[i]->data()); | 134 ValidateExtensionInfo(extension_infos[i], events[i]->data()); |
| 133 int event_type; | 135 int event_type; |
| 134 ASSERT_TRUE(events[i]->data()->GetInteger("eventType", &event_type)); | 136 ASSERT_TRUE(events[i]->data()->GetInteger("eventType", &event_type)); |
| 135 ASSERT_EQ(expected_event_types[i], event_type); | 137 ASSERT_EQ(expected_event_types[i], event_type); |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 } // namespace | 141 } // namespace |
| 140 | 142 |
| 141 namespace performance_monitor { | |
| 142 | |
| 143 class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { | 143 class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { |
| 144 public: | 144 public: |
| 145 virtual void SetUpOnMainThread() OVERRIDE { | 145 virtual void SetUpOnMainThread() OVERRIDE { |
| 146 CHECK(db_dir_.CreateUniqueTempDir()); | 146 CHECK(db_dir_.CreateUniqueTempDir()); |
| 147 performance_monitor_ = PerformanceMonitor::GetInstance(); | 147 performance_monitor_ = PerformanceMonitor::GetInstance(); |
| 148 performance_monitor_->SetDatabasePath(db_dir_.path()); | 148 performance_monitor_->SetDatabasePath(db_dir_.path()); |
| 149 | 149 |
| 150 // PerformanceMonitor's initialization process involves a significant | 150 // PerformanceMonitor's initialization process involves a significant |
| 151 // amount of thread-hopping between the UI thread and the background thread. | 151 // amount of thread-hopping between the UI thread and the background thread. |
| 152 // If we begin the tests prior to full initialization, we cannot predict | 152 // If we begin the tests prior to full initialization, we cannot predict |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 void GatherStatistics() { | 167 void GatherStatistics() { |
| 168 content::BrowserThread::PostBlockingPoolSequencedTask( | 168 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 169 Database::kDatabaseSequenceToken, | 169 Database::kDatabaseSequenceToken, |
| 170 FROM_HERE, | 170 FROM_HERE, |
| 171 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread, | 171 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread, |
| 172 base::Unretained(performance_monitor()))); | 172 base::Unretained(performance_monitor()))); |
| 173 | 173 |
| 174 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 174 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GetEventsOnBackgroundThread(std::vector<linked_ptr<Event> >* events) { | 177 void GetEventsOnBackgroundThread(Database::EventVector* events) { |
| 178 // base::Time is potentially flaky in that there is no guarantee that it | 178 // base::Time is potentially flaky in that there is no guarantee that it |
| 179 // won't actually decrease between successive calls. If we call GetEvents | 179 // won't actually decrease between successive calls. If we call GetEvents |
| 180 // and the Database uses base::Time::Now() and gets a lesser time, then it | 180 // and the Database uses base::Time::Now() and gets a lesser time, then it |
| 181 // will return 0 events. Thus, we use a time that is guaranteed to be in the | 181 // will return 0 events. Thus, we use a time that is guaranteed to be in the |
| 182 // future (for at least the next couple hundred thousand years). | 182 // future (for at least the next couple hundred thousand years). |
| 183 *events = performance_monitor_->database()->GetEvents( | 183 *events = performance_monitor_->database()->GetEvents( |
| 184 base::Time(), base::Time::FromInternalValue(kint64max)); | 184 base::Time(), base::Time::FromInternalValue(kint64max)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // A handle for getting the events from the database, which must be done on | 187 // A handle for getting the events from the database, which must be done on |
| 188 // the background thread. Since we are testing, we can mock synchronicity | 188 // the background thread. Since we are testing, we can mock synchronicity |
| 189 // with FlushForTesting(). | 189 // with FlushForTesting(). |
| 190 std::vector<linked_ptr<Event> > GetEvents() { | 190 Database::EventVector GetEvents() { |
| 191 // Ensure that any event insertions happen prior to getting events in order | 191 // Ensure that any event insertions happen prior to getting events in order |
| 192 // to avoid race conditions. | 192 // to avoid race conditions. |
| 193 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 193 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 194 content::RunAllPendingInMessageLoop(); | 194 content::RunAllPendingInMessageLoop(); |
| 195 | 195 |
| 196 std::vector<linked_ptr<Event> > events; | 196 Database::EventVector events; |
| 197 content::BrowserThread::PostBlockingPoolSequencedTask( | 197 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 198 Database::kDatabaseSequenceToken, | 198 Database::kDatabaseSequenceToken, |
| 199 FROM_HERE, | 199 FROM_HERE, |
| 200 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, | 200 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, |
| 201 base::Unretained(this), | 201 base::Unretained(this), |
| 202 &events)); | 202 &events)); |
| 203 | 203 |
| 204 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 204 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 205 return events; | 205 return events; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void GetStatsOnBackgroundThread(Database::MetricInfoVector* metrics, | 208 void GetStatsOnBackgroundThread(Database::MetricVector* metrics, |
| 209 MetricType type) { | 209 MetricType type) { |
| 210 *metrics = performance_monitor_->database()->GetStatsForActivityAndMetric( | 210 *metrics = performance_monitor_->database()->GetStatsForActivityAndMetric( |
| 211 type, base::Time(), base::Time::FromInternalValue(kint64max)); | 211 type, base::Time(), base::Time::FromInternalValue(kint64max)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // A handle for getting statistics from the database (see previous comments on | 214 // A handle for getting statistics from the database (see previous comments on |
| 215 // GetEvents() and GetEventsOnBackgroundThread). | 215 // GetEvents() and GetEventsOnBackgroundThread). |
| 216 Database::MetricInfoVector GetStats(MetricType type) { | 216 Database::MetricVector GetStats(MetricType type) { |
| 217 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 217 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 218 content::RunAllPendingInMessageLoop(); | 218 content::RunAllPendingInMessageLoop(); |
| 219 | 219 |
| 220 Database::MetricInfoVector metrics; | 220 Database::MetricVector metrics; |
| 221 content::BrowserThread::PostBlockingPoolSequencedTask( | 221 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 222 Database::kDatabaseSequenceToken, | 222 Database::kDatabaseSequenceToken, |
| 223 FROM_HERE, | 223 FROM_HERE, |
| 224 base::Bind(&PerformanceMonitorBrowserTest::GetStatsOnBackgroundThread, | 224 base::Bind(&PerformanceMonitorBrowserTest::GetStatsOnBackgroundThread, |
| 225 base::Unretained(this), | 225 base::Unretained(this), |
| 226 &metrics, | 226 &metrics, |
| 227 type)); | 227 type)); |
| 228 | 228 |
| 229 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 229 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 230 return metrics; | 230 return metrics; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 .AppendASCII("extensions") | 383 .AppendASCII("extensions") |
| 384 .AppendASCII("simple_extension_v1"); | 384 .AppendASCII("simple_extension_v1"); |
| 385 const Extension* extension = LoadExtension(extension_path); | 385 const Extension* extension = LoadExtension(extension_path); |
| 386 | 386 |
| 387 std::vector<ExtensionBasicInfo> extension_infos; | 387 std::vector<ExtensionBasicInfo> extension_infos; |
| 388 extension_infos.push_back(ExtensionBasicInfo(extension)); | 388 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 389 | 389 |
| 390 std::vector<int> expected_event_types; | 390 std::vector<int> expected_event_types; |
| 391 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 391 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 392 | 392 |
| 393 std::vector<linked_ptr<Event> > events = GetEvents(); | 393 Database::EventVector events = GetEvents(); |
| 394 CheckExtensionEvents(expected_event_types, events, extension_infos); | 394 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Test that PerformanceMonitor will correctly record events as an extension is | 397 // Test that PerformanceMonitor will correctly record events as an extension is |
| 398 // disabled and enabled. | 398 // disabled and enabled. |
| 399 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, | 399 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, |
| 400 DisableAndEnableExtensionEvent) { | 400 DisableAndEnableExtensionEvent) { |
| 401 const int kNumEvents = 3; | 401 const int kNumEvents = 3; |
| 402 | 402 |
| 403 FilePath extension_path; | 403 FilePath extension_path; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 416 // Extension Disable | 416 // Extension Disable |
| 417 // Extension Enable | 417 // Extension Enable |
| 418 for (int i = 0; i < kNumEvents; ++i) | 418 for (int i = 0; i < kNumEvents; ++i) |
| 419 extension_infos.push_back(ExtensionBasicInfo(extension)); | 419 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 420 | 420 |
| 421 std::vector<int> expected_event_types; | 421 std::vector<int> expected_event_types; |
| 422 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 422 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 423 expected_event_types.push_back(EVENT_EXTENSION_DISABLE); | 423 expected_event_types.push_back(EVENT_EXTENSION_DISABLE); |
| 424 expected_event_types.push_back(EVENT_EXTENSION_ENABLE); | 424 expected_event_types.push_back(EVENT_EXTENSION_ENABLE); |
| 425 | 425 |
| 426 std::vector<linked_ptr<Event> > events = GetEvents(); | 426 Database::EventVector events = GetEvents(); |
| 427 CheckExtensionEvents(expected_event_types, events, extension_infos); | 427 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // Test that PerformanceMonitor correctly records an extension update event. | 430 // Test that PerformanceMonitor correctly records an extension update event. |
| 431 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UpdateExtensionEvent) { | 431 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UpdateExtensionEvent) { |
| 432 ScopedTempDir temp_dir; | 432 ScopedTempDir temp_dir; |
| 433 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 433 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 434 | 434 |
| 435 FilePath test_data_dir; | 435 FilePath test_data_dir; |
| 436 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 436 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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[1]); | 480 extension_infos.push_back(extension_infos[1]); |
| 481 | 481 |
| 482 std::vector<int> expected_event_types; | 482 std::vector<int> expected_event_types; |
| 483 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 483 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 484 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 484 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 485 expected_event_types.push_back(EVENT_EXTENSION_UPDATE); | 485 expected_event_types.push_back(EVENT_EXTENSION_UPDATE); |
| 486 | 486 |
| 487 std::vector<linked_ptr<Event> > events = GetEvents(); | 487 Database::EventVector events = GetEvents(); |
| 488 | 488 |
| 489 CheckExtensionEvents(expected_event_types, events, extension_infos); | 489 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 490 } | 490 } |
| 491 | 491 |
| 492 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UninstallExtensionEvent) { | 492 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, UninstallExtensionEvent) { |
| 493 const int kNumEvents = 2; | 493 const int kNumEvents = 2; |
| 494 FilePath extension_path; | 494 FilePath extension_path; |
| 495 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | 495 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
| 496 extension_path = extension_path.AppendASCII("performance_monitor") | 496 extension_path = extension_path.AppendASCII("performance_monitor") |
| 497 .AppendASCII("extensions") | 497 .AppendASCII("extensions") |
| 498 .AppendASCII("simple_extension_v1"); | 498 .AppendASCII("simple_extension_v1"); |
| 499 const Extension* extension = LoadExtension(extension_path); | 499 const Extension* extension = LoadExtension(extension_path); |
| 500 | 500 |
| 501 std::vector<ExtensionBasicInfo> extension_infos; | 501 std::vector<ExtensionBasicInfo> extension_infos; |
| 502 // There will be two events, both pertaining to the same extension: | 502 // There will be two events, both pertaining to the same extension: |
| 503 // Extension Install | 503 // Extension Install |
| 504 // Extension Uninstall | 504 // Extension Uninstall |
| 505 for (int i = 0; i < kNumEvents; ++i) | 505 for (int i = 0; i < kNumEvents; ++i) |
| 506 extension_infos.push_back(ExtensionBasicInfo(extension)); | 506 extension_infos.push_back(ExtensionBasicInfo(extension)); |
| 507 | 507 |
| 508 UninstallExtension(extension->id()); | 508 UninstallExtension(extension->id()); |
| 509 | 509 |
| 510 std::vector<int> expected_event_types; | 510 std::vector<int> expected_event_types; |
| 511 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); | 511 expected_event_types.push_back(EVENT_EXTENSION_INSTALL); |
| 512 expected_event_types.push_back(EVENT_EXTENSION_UNINSTALL); | 512 expected_event_types.push_back(EVENT_EXTENSION_UNINSTALL); |
| 513 | 513 |
| 514 std::vector<linked_ptr<Event> > events = GetEvents(); | 514 Database::EventVector events = GetEvents(); |
| 515 | 515 |
| 516 CheckExtensionEvents(expected_event_types, events, extension_infos); | 516 CheckExtensionEvents(expected_event_types, events, extension_infos); |
| 517 } | 517 } |
| 518 | 518 |
| 519 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) { | 519 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) { |
| 520 const char kOldVersion[] = "0.0"; | 520 const char kOldVersion[] = "0.0"; |
| 521 | 521 |
| 522 // 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 |
| 523 // (gathered at initialization of PerformanceMonitor). Replace this with an | 523 // (gathered at initialization of PerformanceMonitor). Replace this with an |
| 524 // older version so an event is generated. | 524 // older version so an event is generated. |
| 525 AddStateValue(kStateChromeVersion, kOldVersion); | 525 AddStateValue(kStateChromeVersion, kOldVersion); |
| 526 | 526 |
| 527 CheckForVersionUpdate(); | 527 CheckForVersionUpdate(); |
| 528 | 528 |
| 529 chrome::VersionInfo version; | 529 chrome::VersionInfo version; |
| 530 ASSERT_TRUE(version.is_valid()); | 530 ASSERT_TRUE(version.is_valid()); |
| 531 std::string version_string = version.Version(); | 531 std::string version_string = version.Version(); |
| 532 | 532 |
| 533 std::vector<linked_ptr<Event> > events = GetEvents(); | 533 Database::EventVector events = GetEvents(); |
| 534 ASSERT_EQ(1u, events.size()); | 534 ASSERT_EQ(1u, events.size()); |
| 535 ASSERT_EQ(EVENT_CHROME_UPDATE, events[0]->type()); | 535 ASSERT_EQ(EVENT_CHROME_UPDATE, events[0]->type()); |
| 536 | 536 |
| 537 const base::DictionaryValue* value; | 537 const base::DictionaryValue* value; |
| 538 ASSERT_TRUE(events[0]->data()->GetAsDictionary(&value)); | 538 ASSERT_TRUE(events[0]->data()->GetAsDictionary(&value)); |
| 539 | 539 |
| 540 std::string previous_version; | 540 std::string previous_version; |
| 541 std::string current_version; | 541 std::string current_version; |
| 542 | 542 |
| 543 ASSERT_TRUE(value->GetString("previousVersion", &previous_version)); | 543 ASSERT_TRUE(value->GetString("previousVersion", &previous_version)); |
| 544 ASSERT_EQ(kOldVersion, previous_version); | 544 ASSERT_EQ(kOldVersion, previous_version); |
| 545 ASSERT_TRUE(value->GetString("currentVersion", ¤t_version)); | 545 ASSERT_TRUE(value->GetString("currentVersion", ¤t_version)); |
| 546 ASSERT_EQ(version_string, current_version); | 546 ASSERT_EQ(version_string, current_version); |
| 547 } | 547 } |
| 548 | 548 |
| 549 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) { | 549 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) { |
| 550 GatherStatistics(); | 550 GatherStatistics(); |
| 551 | 551 |
| 552 // No stats should be recorded for this CPUUsage because this was the first | 552 // No stats should be recorded for this CPUUsage because this was the first |
| 553 // call to GatherStatistics. | 553 // call to GatherStatistics. |
| 554 Database::MetricInfoVector stats = GetStats(METRIC_CPU_USAGE); | 554 Database::MetricVector stats = GetStats(METRIC_CPU_USAGE); |
| 555 ASSERT_EQ(0u, stats.size()); | 555 ASSERT_EQ(0u, stats.size()); |
| 556 | 556 |
| 557 stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE); | 557 stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE); |
| 558 ASSERT_EQ(1u, stats.size()); | 558 ASSERT_EQ(1u, stats.size()); |
| 559 EXPECT_GT(stats[0].value, 0); | 559 EXPECT_GT(stats[0].value, 0); |
| 560 | 560 |
| 561 stats = GetStats(METRIC_SHARED_MEMORY_USAGE); | 561 stats = GetStats(METRIC_SHARED_MEMORY_USAGE); |
| 562 ASSERT_EQ(1u, stats.size()); | 562 ASSERT_EQ(1u, stats.size()); |
| 563 EXPECT_GT(stats[0].value, 0); | 563 EXPECT_GT(stats[0].value, 0); |
| 564 | 564 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 589 } | 589 } |
| 590 | 590 |
| 591 #if !defined(OS_WIN) | 591 #if !defined(OS_WIN) |
| 592 // Disabled on Windows due to a bug where Windows will return a normal exit | 592 // Disabled on Windows due to a bug where Windows will return a normal exit |
| 593 // code in the testing environment, even if the process died (this is not the | 593 // code in the testing environment, even if the process died (this is not the |
| 594 // case when hand-testing). This code can be traced to MSDN functions in | 594 // case when hand-testing). This code can be traced to MSDN functions in |
| 595 // base::GetTerminationStatus(), so there's not much we can do. | 595 // base::GetTerminationStatus(), so there's not much we can do. |
| 596 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) { | 596 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, KilledByOSEvent) { |
| 597 content::CrashTab(chrome::GetActiveWebContents(browser())); | 597 content::CrashTab(chrome::GetActiveWebContents(browser())); |
| 598 | 598 |
| 599 std::vector<linked_ptr<Event> > events = GetEvents(); | 599 Database::EventVector events = GetEvents(); |
| 600 | 600 |
| 601 ASSERT_EQ(1u, events.size()); | 601 ASSERT_EQ(1u, events.size()); |
| 602 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]); | 602 CheckEventType(EVENT_KILLED_BY_OS_CRASH, events[0]); |
| 603 } | 603 } |
| 604 #endif // !defined(OS_WIN) | 604 #endif // !defined(OS_WIN) |
| 605 | 605 |
| 606 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) { | 606 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, RendererCrashEvent) { |
| 607 content::WindowedNotificationObserver windowed_observer( | 607 content::WindowedNotificationObserver windowed_observer( |
| 608 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 608 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 609 content::NotificationService::AllSources()); | 609 content::NotificationService::AllSources()); |
| 610 | 610 |
| 611 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 611 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
| 612 | 612 |
| 613 windowed_observer.Wait(); | 613 windowed_observer.Wait(); |
| 614 | 614 |
| 615 std::vector<linked_ptr<Event> > events = GetEvents(); | 615 Database::EventVector events = GetEvents(); |
| 616 ASSERT_EQ(1u, events.size()); | 616 ASSERT_EQ(1u, events.size()); |
| 617 | 617 |
| 618 CheckEventType(EVENT_RENDERER_CRASH, events[0]); | 618 CheckEventType(EVENT_RENDERER_CRASH, events[0]); |
| 619 } | 619 } |
| 620 | 620 |
| 621 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest, | 621 IN_PROC_BROWSER_TEST_F(PerformanceMonitorUncleanExitBrowserTest, |
| 622 OneProfileUncleanExit) { | 622 OneProfileUncleanExit) { |
| 623 // Initialize the database value (if there's no value in the database, it | 623 // Initialize the database value (if there's no value in the database, it |
| 624 // can't determine the last active time of the profile, and doesn't insert | 624 // can't determine the last active time of the profile, and doesn't insert |
| 625 // the event). | 625 // the event). |
| 626 const std::string time = "12985807272597591"; | 626 const std::string time = "12985807272597591"; |
| 627 AddStateValue(kStateProfilePrefix + first_profile_name_, time); | 627 AddStateValue(kStateProfilePrefix + first_profile_name_, time); |
| 628 | 628 |
| 629 performance_monitor()->CheckForUncleanExits(); | 629 performance_monitor()->CheckForUncleanExits(); |
| 630 content::RunAllPendingInMessageLoop(); | 630 content::RunAllPendingInMessageLoop(); |
| 631 | 631 |
| 632 std::vector<linked_ptr<Event> > events = GetEvents(); | 632 Database::EventVector events = GetEvents(); |
| 633 | 633 |
| 634 const size_t kNumEvents = 1; | 634 const size_t kNumEvents = 1; |
| 635 ASSERT_EQ(kNumEvents, events.size()); | 635 ASSERT_EQ(kNumEvents, events.size()); |
| 636 | 636 |
| 637 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); | 637 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); |
| 638 | 638 |
| 639 std::string event_profile; | 639 std::string event_profile; |
| 640 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); | 640 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); |
| 641 ASSERT_EQ(first_profile_name_, event_profile); | 641 ASSERT_EQ(first_profile_name_, event_profile); |
| 642 } | 642 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 654 AddStateValue(kStateProfilePrefix + first_profile_name_, time1); | 654 AddStateValue(kStateProfilePrefix + first_profile_name_, time1); |
| 655 AddStateValue(kStateProfilePrefix + second_profile_name_, time2); | 655 AddStateValue(kStateProfilePrefix + second_profile_name_, time2); |
| 656 | 656 |
| 657 performance_monitor()->CheckForUncleanExits(); | 657 performance_monitor()->CheckForUncleanExits(); |
| 658 content::RunAllPendingInMessageLoop(); | 658 content::RunAllPendingInMessageLoop(); |
| 659 | 659 |
| 660 // Load the second profile, which has also exited uncleanly. | 660 // Load the second profile, which has also exited uncleanly. |
| 661 g_browser_process->profile_manager()->GetProfile(second_profile_path); | 661 g_browser_process->profile_manager()->GetProfile(second_profile_path); |
| 662 content::RunAllPendingInMessageLoop(); | 662 content::RunAllPendingInMessageLoop(); |
| 663 | 663 |
| 664 std::vector<linked_ptr<Event> > events = GetEvents(); | 664 Database::EventVector events = GetEvents(); |
| 665 | 665 |
| 666 const size_t kNumEvents = 2; | 666 const size_t kNumEvents = 2; |
| 667 ASSERT_EQ(kNumEvents, events.size()); | 667 ASSERT_EQ(kNumEvents, events.size()); |
| 668 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); | 668 CheckEventType(EVENT_UNCLEAN_EXIT, events[0]); |
| 669 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]); | 669 CheckEventType(EVENT_UNCLEAN_EXIT, events[1]); |
| 670 | 670 |
| 671 std::string event_profile; | 671 std::string event_profile; |
| 672 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); | 672 ASSERT_TRUE(events[0]->data()->GetString("profileName", &event_profile)); |
| 673 ASSERT_EQ(first_profile_name_, event_profile); | 673 ASSERT_EQ(first_profile_name_, event_profile); |
| 674 | 674 |
| 675 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile)); | 675 ASSERT_TRUE(events[1]->data()->GetString("profileName", &event_profile)); |
| 676 ASSERT_EQ(second_profile_name_, event_profile); | 676 ASSERT_EQ(second_profile_name_, event_profile); |
| 677 } | 677 } |
| 678 | 678 |
| 679 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, StartupTime) { | 679 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, StartupTime) { |
| 680 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); | 680 Database::MetricVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
| 681 | 681 |
| 682 ASSERT_EQ(1u, metrics.size()); | 682 ASSERT_EQ(1u, metrics.size()); |
| 683 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); | 683 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 684 } | 684 } |
| 685 | 685 |
| 686 IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, | 686 IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, |
| 687 StartupWithSessionRestore) { | 687 StartupWithSessionRestore) { |
| 688 ui_test_utils::NavigateToURL( | 688 ui_test_utils::NavigateToURL( |
| 689 browser(), | 689 browser(), |
| 690 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 690 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 691 FilePath(FILE_PATH_LITERAL("title1.html")))); | 691 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 692 | 692 |
| 693 QuitBrowserAndRestore(browser(), 1); | 693 QuitBrowserAndRestore(browser(), 1); |
| 694 | 694 |
| 695 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); | 695 Database::MetricVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); |
| 696 ASSERT_EQ(1u, metrics.size()); | 696 ASSERT_EQ(1u, metrics.size()); |
| 697 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); | 697 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 698 | 698 |
| 699 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); | 699 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); |
| 700 ASSERT_EQ(1u, metrics.size()); | 700 ASSERT_EQ(1u, metrics.size()); |
| 701 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); | 701 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); |
| 702 } | 702 } |
| 703 | 703 |
| 704 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { | 704 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { |
| 705 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30); | 705 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30); |
| 706 | 706 |
| 707 ui_test_utils::NavigateToURL( | 707 ui_test_utils::NavigateToURL( |
| 708 browser(), | 708 browser(), |
| 709 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 709 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 710 FilePath(FILE_PATH_LITERAL("title1.html")))); | 710 FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 711 | 711 |
| 712 ui_test_utils::NavigateToURL( | 712 ui_test_utils::NavigateToURL( |
| 713 browser(), | 713 browser(), |
| 714 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 714 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 715 FilePath(FILE_PATH_LITERAL("title2.html")))); | 715 FilePath(FILE_PATH_LITERAL("title2.html")))); |
| 716 | 716 |
| 717 Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); | 717 Database::MetricVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); |
| 718 | 718 |
| 719 ASSERT_EQ(2u, metrics.size()); | 719 ASSERT_EQ(2u, metrics.size()); |
| 720 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue()); | 720 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue()); |
| 721 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); | 721 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); |
| 722 } | 722 } |
| 723 | 723 |
| 724 } // namespace performance_monitor | 724 } // namespace performance_monitor |
| OLD | NEW |