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

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

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: Move SFL calls to constructor 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/ukm_service.h" 16 #include "components/ukm/ukm_service.h"
16 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
17 #include "services/metrics/public/cpp/ukm_recorder.h" 18 #include "services/metrics/public/cpp/ukm_recorder.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 scoped_feature_list_.InitAndEnableFeature(ukm::kUkmFeature);
26 void SetUpCommandLine(base::CommandLine* command_line) override {
27 SyncTest::SetUpCommandLine(command_line);
28 command_line->AppendSwitchASCII(switches::kEnableFeatures,
29 ukm::kUkmFeature.name);
30 } 27 }
31 28
32 protected: 29 protected:
33 bool ukm_enabled() { 30 bool ukm_enabled() {
34 auto* service = ukm_service(); 31 auto* service = ukm_service();
35 return service ? service->recording_enabled_ : false; 32 return service ? service->recording_enabled_ : false;
36 } 33 }
37 uint64_t client_id() { 34 uint64_t client_id() {
38 auto* service = ukm_service(); 35 auto* service = ukm_service();
39 return service ? service->client_id_ : 0; 36 return service ? service->client_id_ : 0;
(...skipping 14 matching lines...) Expand all
54 ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN); 51 ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN);
55 52
56 EXPECT_TRUE(harness->SetupSync()); 53 EXPECT_TRUE(harness->SetupSync());
57 return harness; 54 return harness;
58 } 55 }
59 56
60 private: 57 private:
61 ukm::UkmService* ukm_service() { 58 ukm::UkmService* ukm_service() {
62 return static_cast<ukm::UkmService*>(ukm::UkmRecorder::Get()); 59 return static_cast<ukm::UkmService*>(ukm::UkmRecorder::Get());
63 } 60 }
61
62 base::test::ScopedFeatureList scoped_feature_list_;
64 }; 63 };
65 64
66 // 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.
67 IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoCheck) { 66 IN_PROC_BROWSER_TEST_F(UkmBrowserTest, IncognitoCheck) {
68 // Enable metrics recording and update MetricsServicesManager. 67 // Enable metrics recording and update MetricsServicesManager.
69 bool metrics_enabled = true; 68 bool metrics_enabled = true;
70 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( 69 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
71 &metrics_enabled); 70 &metrics_enabled);
72 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions( 71 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(
73 false); 72 false);
(...skipping 15 matching lines...) Expand all
89 EXPECT_EQ(original_client_id, client_id()); 88 EXPECT_EQ(original_client_id, client_id());
90 89
91 harness->service()->RequestStop(browser_sync::ProfileSyncService::CLEAR_DATA); 90 harness->service()->RequestStop(browser_sync::ProfileSyncService::CLEAR_DATA);
92 CloseBrowserSynchronously(sync_browser); 91 CloseBrowserSynchronously(sync_browser);
93 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr); 92 ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
94 } 93 }
95 94
96 // TODO(holte): Add more tests to cover multi-profile cases. 95 // TODO(holte): Add more tests to cover multi-profile cases.
97 96
98 } // namespace metrics 97 } // namespace metrics
OLDNEW
« no previous file with comments | « chrome/browser/media/encrypted_media_supported_types_browsertest.cc ('k') | chrome/browser/net/predictor_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698