| Index: components/page_load_metrics/browser/page_load_metrics_web_contents_observer_unittest.cc
|
| diff --git a/components/page_load_metrics/browser/page_load_metrics_web_contents_observer_unittest.cc b/components/page_load_metrics/browser/page_load_metrics_web_contents_observer_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6315b524ca97b17ca240a27a840641755cde3489
|
| --- /dev/null
|
| +++ b/components/page_load_metrics/browser/page_load_metrics_web_contents_observer_unittest.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/page_load_metrics/browser/page_load_metrics_web_contents_observer.h"
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/test/histogram_tester.h"
|
| +#include "base/time/time.h"
|
| +#include "components/page_load_metrics/common/page_load_metrics_messages.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace page_load_metrics {
|
| +
|
| +class PageLoadMetricsWebContentsObserverTest : public testing::Test {
|
| + public:
|
| + const char* kHistogramNameFirstLayout = "PageLoad.Timing.FirstLayout";
|
| + const char* kHistogramNameDomContent =
|
| + "PageLoad.Timing.DOMContentLoadedEventFired";
|
| + const char* kHistogramNameLoad = "PageLoad.Timing.LoadEventFired";
|
| +
|
| + PageLoadMetricsWebContentsObserverTest() : observer_(nullptr) {}
|
| +
|
| + protected:
|
| + base::HistogramTester histogram_tester_;
|
| + PageLoadMetricsWebContentsObserver observer_;
|
| +};
|
| +
|
| +// These tests no longer work and need to be updated.
|
| +
|
| +#if 0
|
| +
|
| +TEST_F(PageLoadMetricsWebContentsObserverTest, NoMetrics) {
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0);
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0);
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 0);
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsWebContentsObserverTest, SingleMetric) {
|
| + base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1);
|
| +
|
| + PageLoadTiming timing;
|
| + observer_.OnMessageReceived(PageLoadMetricsMsg_OnTimingUpdated(
|
| + observer_.routing_id(), timing), nullptr);
|
| +
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0);
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0);
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1);
|
| + histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout,
|
| + first_layout.InMilliseconds(), 1);
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsWebContentsObserverTest, MultipleMetrics) {
|
| + base::TimeDelta first_layout_1 = base::TimeDelta::FromMilliseconds(1);
|
| + base::TimeDelta first_layout_2 = base::TimeDelta::FromMilliseconds(20);
|
| + base::TimeDelta dom_content = base::TimeDelta::FromMilliseconds(40);
|
| + base::TimeDelta load = base::TimeDelta::FromMilliseconds(100);
|
| +
|
| + PageLoadTiming timing;
|
| + observer_.OnMessageReceived(PageLoadMetricsMsg_OnTimingUpdated(
|
| + observer_.routing_id(), timing), nullptr);
|
| +
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 2);
|
| + histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout,
|
| + first_layout_1.InMilliseconds(), 1);
|
| + histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout,
|
| + first_layout_2.InMilliseconds(), 1);
|
| +
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 1);
|
| + histogram_tester_.ExpectBucketCount(kHistogramNameDomContent,
|
| + dom_content.InMilliseconds(), 1);
|
| +
|
| + histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 1);
|
| + histogram_tester_.ExpectBucketCount(kHistogramNameLoad,
|
| + load.InMilliseconds(), 1);
|
| +}
|
| +
|
| +#endif
|
| +
|
| +} // namespace page_load_metrics
|
|
|