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" | |
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 |
25 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, kAdsMetricsFeature); | 25 ~AdsPageLoadMetricsObserverBrowserTest() override {} |
26 | |
27 void SetUpCommandLine(base::CommandLine* command_line) override { | |
28 scoped_feature_list_.InitAndEnableFeature(features::kAdsFeature); | |
Ilya Sherman
2017/06/12 21:50:29
Why are you doing this during SetUpCommandLine, ra
chaopeng
2017/06/28 19:21:24
Moved to SetUp.
| |
26 } | 29 } |
27 ~AdsPageLoadMetricsObserverBrowserTest() override {} | |
28 | 30 |
29 void SetUpOnMainThread() override { | 31 void SetUpOnMainThread() override { |
30 ASSERT_TRUE(embedded_test_server()->Start()); | 32 ASSERT_TRUE(embedded_test_server()->Start()); |
31 InProcessBrowserTest::SetUpOnMainThread(); | 33 InProcessBrowserTest::SetUpOnMainThread(); |
32 } | 34 } |
33 | 35 |
34 private: | 36 private: |
37 base::test::ScopedFeatureList scoped_feature_list_; | |
35 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); | 38 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); |
36 }; | 39 }; |
37 | 40 |
38 // Test that a subframe that aborts (due to doc.write) doesn't cause a crash | 41 // Test that a subframe that aborts (due to doc.write) doesn't cause a crash |
39 // if it continues to load resources. | 42 // if it continues to load resources. |
40 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, | 43 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, |
41 DocOverwritesNavigation) { | 44 DocOverwritesNavigation) { |
42 content::DOMMessageQueue msg_queue; | 45 content::DOMMessageQueue msg_queue; |
43 | 46 |
44 base::HistogramTester histogram_tester; | 47 base::HistogramTester histogram_tester; |
45 | 48 |
46 ui_test_utils::NavigateToURL( | 49 ui_test_utils::NavigateToURL( |
47 browser(), embedded_test_server()->GetURL( | 50 browser(), embedded_test_server()->GetURL( |
48 "/ads_observer/docwrite_provisional_frame.html")); | 51 "/ads_observer/docwrite_provisional_frame.html")); |
49 std::string status; | 52 std::string status; |
50 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); | 53 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); |
51 EXPECT_EQ("\"loaded\"", status); | 54 EXPECT_EQ("\"loaded\"", status); |
52 | 55 |
53 // Navigate away to force the histogram recording. | 56 // Navigate away to force the histogram recording. |
54 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 57 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
55 | 58 |
56 histogram_tester.ExpectUniqueSample( | 59 histogram_tester.ExpectUniqueSample( |
57 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); | 60 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); |
58 histogram_tester.ExpectUniqueSample( | 61 histogram_tester.ExpectUniqueSample( |
59 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", | 62 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", |
60 0 /* < 1 KB */, 1); | 63 0 /* < 1 KB */, 1); |
61 } | 64 } |
OLD | NEW |