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

Side by Side Diff: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer_browsertest.cc

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: comments addressed and updated Created 3 years, 5 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 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
Ilya Sherman 2017/07/03 21:21:59 nit: Please omit this blank line.
chaopeng 2017/07/14 18:43:50 Done.
25 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, kAdsMetricsFeature); 25 ~AdsPageLoadMetricsObserverBrowserTest() override {}
26
27 void SetUp() override {
28 scoped_feature_list_.InitAndEnableFeature(features::kAdsFeature);
Ilya Sherman 2017/07/03 21:21:59 Hmm, if this runs before InProcessBrowserTest::Set
chaopeng 2017/07/14 18:43:50 Move all calls to constructor.
29 InProcessBrowserTest::SetUp();
26 } 30 }
27 ~AdsPageLoadMetricsObserverBrowserTest() override {}
28 31
29 void SetUpOnMainThread() override { 32 void SetUpOnMainThread() override {
30 ASSERT_TRUE(embedded_test_server()->Start()); 33 ASSERT_TRUE(embedded_test_server()->Start());
31 } 34 }
32 35
33 private: 36 private:
37 base::test::ScopedFeatureList scoped_feature_list_;
34 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); 38 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest);
35 }; 39 };
36 40
37 // 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
38 // if it continues to load resources. 42 // if it continues to load resources.
39 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, 43 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest,
40 DocOverwritesNavigation) { 44 DocOverwritesNavigation) {
41 content::DOMMessageQueue msg_queue; 45 content::DOMMessageQueue msg_queue;
42 46
43 base::HistogramTester histogram_tester; 47 base::HistogramTester histogram_tester;
44 48
45 ui_test_utils::NavigateToURL( 49 ui_test_utils::NavigateToURL(
46 browser(), embedded_test_server()->GetURL( 50 browser(), embedded_test_server()->GetURL(
47 "/ads_observer/docwrite_provisional_frame.html")); 51 "/ads_observer/docwrite_provisional_frame.html"));
48 std::string status; 52 std::string status;
49 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); 53 EXPECT_TRUE(msg_queue.WaitForMessage(&status));
50 EXPECT_EQ("\"loaded\"", status); 54 EXPECT_EQ("\"loaded\"", status);
51 55
52 // Navigate away to force the histogram recording. 56 // Navigate away to force the histogram recording.
53 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 57 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
54 58
55 histogram_tester.ExpectUniqueSample( 59 histogram_tester.ExpectUniqueSample(
56 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); 60 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1);
57 histogram_tester.ExpectUniqueSample( 61 histogram_tester.ExpectUniqueSample(
58 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 62 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total",
59 0 /* < 1 KB */, 1); 63 0 /* < 1 KB */, 1);
60 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698