Index: chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
diff --git a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
index 3d0234cefc8b4a2a30da6a4eeef673fdc17a1c35..0e8c27089f9977174d35e96983e549bd0dded031 100644 |
--- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
+++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
@@ -50,6 +50,8 @@ using performance_monitor::Event; |
namespace { |
const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); |
+const char kSimplePage1[] = "title1.html"; |
+const char kSimplePage2[] = "title2.html"; |
// Helper struct to store the information of an extension; this is needed if the |
// pointer to the extension ever becomes invalid (e.g., if we uninstall the |
@@ -136,6 +138,15 @@ void CheckExtensionEvents( |
} |
} |
+// A wrapper for file_util::GetFileSize which takes an ASCII path relative to |
+// chrome::DIR_TEST_DATA. |
+bool GetFileSize(const std::string& relative_path, int64* size) { |
+ FilePath test_dir; |
+ PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
+ |
+ return file_util::GetFileSize(test_dir.AppendASCII(relative_path), size); |
+} |
+ |
} // namespace |
namespace performance_monitor { |
@@ -159,6 +170,10 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { |
performance_monitor_->Start(); |
windowed_observer.Wait(); |
+ |
+ // We stop the timer in charge of doing timed collections so that we can |
+ // enforce when, and how many times, we do these collections. |
+ performance_monitor_->timer_.Stop(); |
} |
// A handle for gathering statistics from the database, which must be done on |
@@ -721,4 +736,65 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { |
ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); |
} |
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, DiskBytesRead) { |
+ int64 page1_size = 0; |
+ ASSERT_TRUE(GetFileSize(kSimplePage1, &page1_size)); |
+ |
+ int64 page2_size = 0; |
+ ASSERT_TRUE(GetFileSize(kSimplePage2, &page2_size)); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), |
+ ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
+ FilePath(FILE_PATH_LITERAL(kSimplePage1)))); |
+ performance_monitor()->DoTimedCollections(); |
+ |
+ Database::MetricInfoVector metrics = GetStats(METRIC_DISK_BYTES_READ); |
+ ASSERT_EQ(1u, metrics.size()); |
+ ASSERT_EQ(page1_size, metrics[0].value); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), |
+ ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
+ FilePath(FILE_PATH_LITERAL(kSimplePage2)))); |
+ performance_monitor()->DoTimedCollections(); |
+ |
+ metrics = GetStats(METRIC_DISK_BYTES_READ); |
+ ASSERT_EQ(2u, metrics.size()); |
+ ASSERT_EQ(page1_size + page2_size, metrics[1].value); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NetworkBytesRead) { |
+ int64 page1_size = 0; |
+ ASSERT_TRUE(GetFileSize(kSimplePage1, &page1_size)); |
+ |
+ int64 page2_size = 0; |
+ ASSERT_TRUE(GetFileSize(kSimplePage2, &page2_size)); |
+ |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), |
+ test_server()->GetURL(std::string("files/").append(kSimplePage1))); |
+ |
+ performance_monitor()->DoTimedCollections(); |
+ |
+ Database::MetricInfoVector metrics = GetStats(METRIC_NETWORK_BYTES_READ); |
+ ASSERT_EQ(1u, metrics.size()); |
+ // Since these pages are read over the "network" (actually the test_server), |
+ // some extraneous information is carried along, and the best check we can do |
+ // is for greater than or equal to. |
+ ASSERT_GE(metrics[0].value, page1_size); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), |
+ test_server()->GetURL(std::string("files/").append(kSimplePage2))); |
+ |
+ performance_monitor()->DoTimedCollections(); |
+ |
+ metrics = GetStats(METRIC_NETWORK_BYTES_READ); |
+ ASSERT_EQ(2u, metrics.size()); |
+ ASSERT_GE(metrics[1].value, page1_size + page2_size); |
+} |
+ |
} // namespace performance_monitor |