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

Side by Side Diff: chrome/browser/metrics/ukm_browsertest.cc

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: Ilya comments addressed 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 "base/test/scoped_feature_list.h"
5 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
6 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 7 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
7 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
8 #include "chrome/browser/sync/profile_sync_service_factory.h" 9 #include "chrome/browser/sync/profile_sync_service_factory.h"
9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h" 11 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
12 #include "components/browser_sync/profile_sync_service.h" 13 #include "components/browser_sync/profile_sync_service.h"
13 #include "components/metrics_services_manager/metrics_services_manager.h" 14 #include "components/metrics_services_manager/metrics_services_manager.h"
14 #include "components/sync/test/fake_server/fake_server_network_resources.h" 15 #include "components/sync/test/fake_server/fake_server_network_resources.h"
15 #include "components/ukm/public/ukm_recorder.h" 16 #include "components/ukm/public/ukm_recorder.h"
16 #include "components/ukm/ukm_service.h" 17 #include "components/ukm/ukm_service.h"
17 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
18 19
19 namespace metrics { 20 namespace metrics {
20 21
21 // Test fixture that provides access to some UKM internals. 22 // Test fixture that provides access to some UKM internals.
22 class UkmBrowserTest : public SyncTest { 23 class UkmBrowserTest : public SyncTest {
23 public: 24 public:
24 UkmBrowserTest() : SyncTest(SINGLE_CLIENT) {} 25 UkmBrowserTest() : SyncTest(SINGLE_CLIENT) {}
25 26
26 void SetUpCommandLine(base::CommandLine* command_line) override { 27 void SetUp() override {
27 SyncTest::SetUpCommandLine(command_line); 28 scoped_feature_list_.InitAndEnableFeature(ukm::kUkmFeature);
28 command_line->AppendSwitchASCII(switches::kEnableFeatures, 29 SyncTest::SetUp();
29 ukm::kUkmFeature.name);
30 } 30 }
31 31
32 protected: 32 protected:
33 bool ukm_enabled() { 33 bool ukm_enabled() {
34 auto* service = ukm_service(); 34 auto* service = ukm_service();
35 return service ? service->recording_enabled_ : false; 35 return service ? service->recording_enabled_ : false;
36 } 36 }
37 uint64_t client_id() { 37 uint64_t client_id() {
38 auto* service = ukm_service(); 38 auto* service = ukm_service();
39 return service ? service->client_id_ : 0; 39 return service ? service->client_id_ : 0;
(...skipping 11 matching lines...) Expand all
51 ProfileSyncServiceHarness::Create( 51 ProfileSyncServiceHarness::Create(
52 profile, "user@gmail.com", "password", 52 profile, "user@gmail.com", "password",
53 ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN); 53 ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN);
54 54
55 harness->SetupSync(); 55 harness->SetupSync();
56 } 56 }
57 57
58 private: 58 private:
59 ukm::UkmService* ukm_service() { 59 ukm::UkmService* ukm_service() {
60 return static_cast<ukm::UkmService*>(ukm::UkmRecorder::Get()); 60 return static_cast<ukm::UkmService*>(ukm::UkmRecorder::Get());
61 } 61 }
Ilya Sherman 2017/06/28 19:56:05 nit: Please leave a blank line here.
chaopeng 2017/06/30 19:32:36 Done.
62 base::test::ScopedFeatureList scoped_feature_list_;
62 }; 63 };
63 64
64 // Make sure that UKM is disabled while an incognito window is open. 65 // Make sure that UKM is disabled while an incognito window is open.
65 IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoCheck) { 66 IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoCheck) {
66 // Enable metrics recording and update MetricsServicesManager. 67 // Enable metrics recording and update MetricsServicesManager.
67 bool metrics_enabled = true; 68 bool metrics_enabled = true;
68 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( 69 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
69 &metrics_enabled); 70 &metrics_enabled);
70 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions( 71 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(
71 false); 72 false);
(...skipping 12 matching lines...) Expand all
84 EXPECT_TRUE(ukm_enabled()); 85 EXPECT_TRUE(ukm_enabled());
85 // Client ID should not have been reset. 86 // Client ID should not have been reset.
86 EXPECT_EQ(original_client_id, client_id()); 87 EXPECT_EQ(original_client_id, client_id());
87 88
88 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr); 89 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
89 } 90 }
90 91
91 // TODO(holte): Add more tests to cover multi-profile cases. 92 // TODO(holte): Add more tests to cover multi-profile cases.
92 93
93 } // namespace metrics 94 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698