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