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

Side by Side Diff: content/browser/generic_sensor_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/test/scoped_feature_list.h"
9 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
14 #include "content/public/test/content_browser_test.h" 15 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 16 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h" 17 #include "content/public/test/test_navigation_observer.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
19 #include "content/shell/browser/shell_javascript_dialog_manager.h" 20 #include "content/shell/browser/shell_javascript_dialog_manager.h"
20 #include "device/base/synchronization/one_writer_seqlock.h" 21 #include "device/base/synchronization/one_writer_seqlock.h"
21 #include "device/generic_sensor/public/cpp/platform_sensor_configuration.h" 22 #include "device/generic_sensor/public/cpp/platform_sensor_configuration.h"
22 #include "device/generic_sensor/public/cpp/sensor_reading.h" 23 #include "device/generic_sensor/public/cpp/sensor_reading.h"
23 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" 24 #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
24 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" 25 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h"
25 #include "mojo/public/cpp/bindings/binding.h" 26 #include "mojo/public/cpp/bindings/binding.h"
26 #include "mojo/public/cpp/bindings/strong_binding.h" 27 #include "mojo/public/cpp/bindings/strong_binding.h"
27 #include "mojo/public/cpp/system/buffer.h" 28 #include "mojo/public/cpp/system/buffer.h"
29 #include "services/device/public/cpp/device_features.h"
28 #include "services/device/public/interfaces/constants.mojom.h" 30 #include "services/device/public/interfaces/constants.mojom.h"
29 #include "services/service_manager/public/cpp/service_context.h" 31 #include "services/service_manager/public/cpp/service_context.h"
30 32
31 namespace content { 33 namespace content {
32 34
33 namespace { 35 namespace {
34 36
35 class FakeAmbientLightSensor : public device::mojom::Sensor { 37 class FakeAmbientLightSensor : public device::mojom::Sensor {
36 public: 38 public:
37 FakeAmbientLightSensor() { 39 FakeAmbientLightSensor() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 mojo::Binding<device::mojom::SensorProvider> binding_; 163 mojo::Binding<device::mojom::SensorProvider> binding_;
162 164
163 DISALLOW_COPY_AND_ASSIGN(FakeSensorProvider); 165 DISALLOW_COPY_AND_ASSIGN(FakeSensorProvider);
164 }; 166 };
165 167
166 class GenericSensorBrowserTest : public ContentBrowserTest { 168 class GenericSensorBrowserTest : public ContentBrowserTest {
167 public: 169 public:
168 GenericSensorBrowserTest() 170 GenericSensorBrowserTest()
169 : io_loop_finished_event_( 171 : io_loop_finished_event_(
170 base::WaitableEvent::ResetPolicy::AUTOMATIC, 172 base::WaitableEvent::ResetPolicy::AUTOMATIC,
171 base::WaitableEvent::InitialState::NOT_SIGNALED) { 173 base::WaitableEvent::InitialState::NOT_SIGNALED) {}
172 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 174
173 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, "GenericSensor"); 175 void SetUp() override {
176 scoped_feature_list_.InitAndEnableFeature(features::kGenericSensor);
177 ContentBrowserTest::SetUp();
174 } 178 }
175 179
176 void SetUpOnMainThread() override { 180 void SetUpOnMainThread() override {
177 fake_sensor_provider_ = base::MakeUnique<FakeSensorProvider>(); 181 fake_sensor_provider_ = base::MakeUnique<FakeSensorProvider>();
178 BrowserThread::PostTask( 182 BrowserThread::PostTask(
179 BrowserThread::IO, FROM_HERE, 183 BrowserThread::IO, FROM_HERE,
180 base::Bind(&GenericSensorBrowserTest::SetBinderOnIOThread, 184 base::Bind(&GenericSensorBrowserTest::SetBinderOnIOThread,
181 base::Unretained(this))); 185 base::Unretained(this)));
182 186
183 io_loop_finished_event_.Wait(); 187 io_loop_finished_event_.Wait();
184 } 188 }
185 189
186 void SetBinderOnIOThread() { 190 void SetBinderOnIOThread() {
187 // Because Device Service also runs in this process(browser process), here 191 // Because Device Service also runs in this process(browser process), here
188 // we can directly set our binder to intercept interface requests against 192 // we can directly set our binder to intercept interface requests against
189 // it. 193 // it.
190 service_manager::ServiceContext::SetGlobalBinderForTesting( 194 service_manager::ServiceContext::SetGlobalBinderForTesting(
191 device::mojom::kServiceName, device::mojom::SensorProvider::Name_, 195 device::mojom::kServiceName, device::mojom::SensorProvider::Name_,
192 base::Bind(&FakeSensorProvider::Bind, 196 base::Bind(&FakeSensorProvider::Bind,
193 base::Unretained(fake_sensor_provider_.get()))); 197 base::Unretained(fake_sensor_provider_.get())));
194 198
195 io_loop_finished_event_.Signal(); 199 io_loop_finished_event_.Signal();
196 } 200 }
197 201
198 private: 202 private:
199 base::WaitableEvent io_loop_finished_event_; 203 base::WaitableEvent io_loop_finished_event_;
200 std::unique_ptr<FakeSensorProvider> fake_sensor_provider_; 204 std::unique_ptr<FakeSensorProvider> fake_sensor_provider_;
205 base::test::ScopedFeatureList scoped_feature_list_;
201 206
202 DISALLOW_COPY_AND_ASSIGN(GenericSensorBrowserTest); 207 DISALLOW_COPY_AND_ASSIGN(GenericSensorBrowserTest);
203 }; 208 };
204 209
205 IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) { 210 IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) {
206 // The test page will create an AmbientLightSensor object in Javascript, 211 // The test page will create an AmbientLightSensor object in Javascript,
207 // expects to get events with fake values then navigates to #pass. 212 // expects to get events with fake values then navigates to #pass.
208 GURL test_url = 213 GURL test_url =
209 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html"); 214 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html");
210 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 215 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
211 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 216 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
212 } 217 }
213 218
214 } // namespace 219 } // namespace
215 220
216 } // namespace content 221 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698