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..027e388aea034ea4d70406cb264153b314c743a6 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 |
@@ -567,7 +582,7 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) { |
chrome::NavigateParams params( |
browser(), |
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
- FilePath(FILE_PATH_LITERAL("title1.html"))), |
+ FilePath(FILE_PATH_LITERAL(kSimplePage1))), |
content::PAGE_TRANSITION_LINK); |
params.disposition = NEW_BACKGROUND_TAB; |
ui_test_utils::NavigateToURL(¶ms); |
@@ -688,7 +703,7 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, |
ui_test_utils::NavigateToURL( |
browser(), |
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
- FilePath(FILE_PATH_LITERAL("title1.html")))); |
+ FilePath(FILE_PATH_LITERAL(kSimplePage1)))); |
QuitBrowserAndRestore(browser(), 1); |
@@ -707,12 +722,12 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { |
ui_test_utils::NavigateToURL( |
browser(), |
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
- FilePath(FILE_PATH_LITERAL("title1.html")))); |
+ FilePath(FILE_PATH_LITERAL(kSimplePage1)))); |
ui_test_utils::NavigateToURL( |
browser(), |
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
- FilePath(FILE_PATH_LITERAL("title2.html")))); |
+ FilePath(FILE_PATH_LITERAL(kSimplePage1)))); |
Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); |
@@ -721,4 +736,37 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { |
ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); |
} |
+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); |
battre
2012/08/22 08:25:24
It this still correct? (just a question, I have no
Devlin
2012/08/22 16:22:05
Done, added in an extra flush to be safe.
battre
2012/08/22 19:23:02
Did you check whether it was needed?
Devlin
2012/08/22 20:34:55
Yeah, it's needed to ensure that it will be done (
|
+ 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 |