Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor_browsertest.cc

Issue 10829342: Add BytesRead metric to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
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("title2.html"))));
716 720
717 Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); 721 Database::MetricInfoVector 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, BytesRead) {
729 FilePath test_dir;
730 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
731
732 int64 page1_size = 0;
733 file_util::GetFileSize(test_dir.AppendASCII("title1.html"), &page1_size);
734
735 int64 page2_size = 0;
736 file_util::GetFileSize(test_dir.AppendASCII("title2.html"), &page2_size);
737
738 ui_test_utils::NavigateToURL(
739 browser(),
740 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
741 FilePath(FILE_PATH_LITERAL("title1.html"))));
742 performance_monitor()->DoTimedCollections();
743
744 Database::MetricInfoVector metrics = GetStats(METRIC_BYTES_READ);
745 ASSERT_EQ(1u, metrics.size());
746 ASSERT_EQ(page1_size, metrics[0].value);
747
748 ui_test_utils::NavigateToURL(
749 browser(),
750 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
751 FilePath(FILE_PATH_LITERAL("title2.html"))));
752 performance_monitor()->DoTimedCollections();
753
754 metrics = GetStats(METRIC_BYTES_READ);
755
756 ASSERT_EQ(2u, metrics.size());
757 ASSERT_EQ(page1_size + page2_size, metrics[1].value);
758 }
759
724 } // namespace performance_monitor 760 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698