OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "base/test/scoped_feature_list.h" | |
11 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser ver.h" | |
Ilya Sherman
2017/06/28 19:56:05
nit: Is this #include needed as part of this CL?
chaopeng
2017/06/30 19:32:36
Done.
| |
12 #include "chrome/common/chrome_features.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
12 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
13 #include "content/public/test/browser_test.h" | 16 #include "content/public/test/browser_test.h" |
14 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
15 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "url/gurl.h" | 20 #include "url/gurl.h" |
18 | 21 |
19 const char kAdsMetricsFeature[] = "AdsMetrics"; | |
20 | |
21 class AdsPageLoadMetricsObserverBrowserTest : public InProcessBrowserTest { | 22 class AdsPageLoadMetricsObserverBrowserTest : public InProcessBrowserTest { |
22 public: | 23 public: |
23 AdsPageLoadMetricsObserverBrowserTest() { | 24 AdsPageLoadMetricsObserverBrowserTest() {} |
24 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 25 |
25 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, kAdsMetricsFeature); | 26 ~AdsPageLoadMetricsObserverBrowserTest() override {} |
27 | |
28 void SetUp() override { | |
29 scoped_feature_list_.InitAndEnableFeature(features::kAdsFeature); | |
30 InProcessBrowserTest::SetUp(); | |
26 } | 31 } |
27 ~AdsPageLoadMetricsObserverBrowserTest() override {} | |
28 | 32 |
29 void SetUpOnMainThread() override { | 33 void SetUpOnMainThread() override { |
30 ASSERT_TRUE(embedded_test_server()->Start()); | 34 ASSERT_TRUE(embedded_test_server()->Start()); |
31 } | 35 } |
32 | 36 |
33 private: | 37 private: |
38 base::test::ScopedFeatureList scoped_feature_list_; | |
34 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); | 39 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); |
35 }; | 40 }; |
36 | 41 |
37 // Test that a subframe that aborts (due to doc.write) doesn't cause a crash | 42 // Test that a subframe that aborts (due to doc.write) doesn't cause a crash |
38 // if it continues to load resources. | 43 // if it continues to load resources. |
39 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, | 44 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, |
40 DocOverwritesNavigation) { | 45 DocOverwritesNavigation) { |
41 content::DOMMessageQueue msg_queue; | 46 content::DOMMessageQueue msg_queue; |
42 | 47 |
43 base::HistogramTester histogram_tester; | 48 base::HistogramTester histogram_tester; |
44 | 49 |
45 ui_test_utils::NavigateToURL( | 50 ui_test_utils::NavigateToURL( |
46 browser(), embedded_test_server()->GetURL( | 51 browser(), embedded_test_server()->GetURL( |
47 "/ads_observer/docwrite_provisional_frame.html")); | 52 "/ads_observer/docwrite_provisional_frame.html")); |
48 std::string status; | 53 std::string status; |
49 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); | 54 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); |
50 EXPECT_EQ("\"loaded\"", status); | 55 EXPECT_EQ("\"loaded\"", status); |
51 | 56 |
52 // Navigate away to force the histogram recording. | 57 // Navigate away to force the histogram recording. |
53 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 58 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
54 | 59 |
55 histogram_tester.ExpectUniqueSample( | 60 histogram_tester.ExpectUniqueSample( |
56 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); | 61 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); |
57 histogram_tester.ExpectUniqueSample( | 62 histogram_tester.ExpectUniqueSample( |
58 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", | 63 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", |
59 0 /* < 1 KB */, 1); | 64 0 /* < 1 KB */, 1); |
60 } | 65 } |
OLD | NEW |