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" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
153 // the behavior or mock synchronicity as we must. Wait for initialization | 153 // the behavior or mock synchronicity as we must. Wait for initialization |
154 // to complete fully before proceeding with the test. | 154 // to complete fully before proceeding with the test. |
155 content::WindowedNotificationObserver windowed_observer( | 155 content::WindowedNotificationObserver windowed_observer( |
156 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, | 156 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, |
157 content::NotificationService::AllSources()); | 157 content::NotificationService::AllSources()); |
158 | 158 |
159 performance_monitor_->Start(); | 159 performance_monitor_->Start(); |
160 | 160 |
161 windowed_observer.Wait(); | 161 windowed_observer.Wait(); |
| 162 |
| 163 // We stop the timer in charge of doing timed collections so that we can |
| 164 // enforce when, and how many times, we do these collections. |
| 165 performance_monitor_->timer_.Stop(); |
162 } | 166 } |
163 | 167 |
164 // A handle for gathering statistics from the database, which must be done on | 168 // A handle for gathering statistics from the database, which must be done on |
165 // the background thread. Since we are testing, we can mock synchronicity with | 169 // the background thread. Since we are testing, we can mock synchronicity with |
166 // FlushForTesting(). | 170 // FlushForTesting(). |
167 void GatherStatistics() { | 171 void GatherStatistics() { |
168 content::BrowserThread::PostBlockingPoolSequencedTask( | 172 content::BrowserThread::PostBlockingPoolSequencedTask( |
169 Database::kDatabaseSequenceToken, | 173 Database::kDatabaseSequenceToken, |
170 FROM_HERE, | 174 FROM_HERE, |
171 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread, | 175 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread, |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30); | 709 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30); |
706 | 710 |
707 ui_test_utils::NavigateToURL( | 711 ui_test_utils::NavigateToURL( |
708 browser(), | 712 browser(), |
709 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 713 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
710 FilePath(FILE_PATH_LITERAL("title1.html")))); | 714 FilePath(FILE_PATH_LITERAL("title1.html")))); |
711 | 715 |
712 ui_test_utils::NavigateToURL( | 716 ui_test_utils::NavigateToURL( |
713 browser(), | 717 browser(), |
714 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 718 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
715 FilePath(FILE_PATH_LITERAL("title2.html")))); | 719 FilePath(FILE_PATH_LITERAL("title1.html")))); |
716 | 720 |
717 Database::MetricVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); | 721 Database::MetricVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); |
718 | 722 |
719 ASSERT_EQ(2u, metrics.size()); | 723 ASSERT_EQ(2u, metrics.size()); |
720 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue()); | 724 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue()); |
721 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); | 725 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); |
722 } | 726 } |
723 | 727 |
| 728 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NetworkBytesRead) { |
| 729 FilePath test_dir; |
| 730 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
| 731 |
| 732 int64 page1_size = 0; |
| 733 ASSERT_TRUE(file_util::GetFileSize(test_dir.AppendASCII("title1.html"), |
| 734 &page1_size)); |
| 735 |
| 736 int64 page2_size = 0; |
| 737 ASSERT_TRUE(file_util::GetFileSize(test_dir.AppendASCII("title2.html"), |
| 738 &page2_size)); |
| 739 |
| 740 ASSERT_TRUE(test_server()->Start()); |
| 741 |
| 742 ui_test_utils::NavigateToURL( |
| 743 browser(), |
| 744 test_server()->GetURL(std::string("files/").append("title1.html"))); |
| 745 |
| 746 performance_monitor()->DoTimedCollections(); |
| 747 |
| 748 // Since network bytes are read and set on the IO thread, we must flush this |
| 749 // additional thread to be sure that all messages are run. |
| 750 RunAllPendingInMessageLoop(content::BrowserThread::IO); |
| 751 |
| 752 Database::MetricVector metrics = GetStats(METRIC_NETWORK_BYTES_READ); |
| 753 ASSERT_EQ(1u, metrics.size()); |
| 754 // Since these pages are read over the "network" (actually the test_server), |
| 755 // some extraneous information is carried along, and the best check we can do |
| 756 // is for greater than or equal to. |
| 757 EXPECT_GE(metrics[0].value, page1_size); |
| 758 |
| 759 ui_test_utils::NavigateToURL( |
| 760 browser(), |
| 761 test_server()->GetURL(std::string("files/").append("title2.html"))); |
| 762 |
| 763 performance_monitor()->DoTimedCollections(); |
| 764 |
| 765 metrics = GetStats(METRIC_NETWORK_BYTES_READ); |
| 766 ASSERT_EQ(2u, metrics.size()); |
| 767 EXPECT_GE(metrics[1].value, page1_size + page2_size); |
| 768 } |
| 769 |
724 } // namespace performance_monitor | 770 } // namespace performance_monitor |
OLD | NEW |