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

Side by Side Diff: content/browser/generic_sensor_browsertest.cc

Issue 2921493002: Cleanup generic sensor browsertests (Closed)
Patch Set: cleanup generic sensor browsertests Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h" 16 #include "content/public/test/test_navigation_observer.h"
17 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
18 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
19 #include "content/shell/browser/shell_javascript_dialog_manager.h" 19 #include "content/shell/browser/shell_javascript_dialog_manager.h"
20 #include "device/generic_sensor/platform_sensor.h" 20 #include "device/generic_sensor/platform_sensor.h"
21 #include "device/generic_sensor/platform_sensor_provider.h" 21 #include "device/generic_sensor/platform_sensor_provider.h"
22 #include "device/generic_sensor/sensor_provider_impl.h" 22 #include "device/generic_sensor/sensor_provider_impl.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 namespace { 26 namespace {
27 27
28 class FakeAmbientLightSensor : public device::PlatformSensor { 28 class FakeAmbientLightSensor : public device::PlatformSensor {
29 public: 29 public:
30 FakeAmbientLightSensor(device::mojom::SensorType type, 30 FakeAmbientLightSensor(mojo::ScopedSharedBufferMapping mapping,
31 mojo::ScopedSharedBufferMapping mapping,
32 device::PlatformSensorProvider* provider) 31 device::PlatformSensorProvider* provider)
33 : PlatformSensor(type, std::move(mapping), provider) {} 32 : PlatformSensor(device::mojom::SensorType::AMBIENT_LIGHT,
33 std::move(mapping),
34 provider) {}
34 35
35 device::mojom::ReportingMode GetReportingMode() override { 36 device::mojom::ReportingMode GetReportingMode() override {
36 return device::mojom::ReportingMode::ON_CHANGE; 37 return device::mojom::ReportingMode::ON_CHANGE;
37 } 38 }
38 39
39 bool StartSensor( 40 bool StartSensor(
40 const device::PlatformSensorConfiguration& configuration) override { 41 const device::PlatformSensorConfiguration& configuration) override {
41 device::SensorReading reading; 42 device::SensorReading reading;
42 reading.timestamp = 43 reading.timestamp =
43 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 44 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
44 reading.values[0] = 50; 45 reading.values[0] = 50;
45 UpdateSensorReading(reading, true); 46 UpdateSensorReading(reading, true);
46 return true; 47 return true;
47 } 48 }
48 49
49 void StopSensor() override{}; 50 void StopSensor() override {};
50 51
51 protected: 52 protected:
52 ~FakeAmbientLightSensor() override = default; 53 ~FakeAmbientLightSensor() override = default;
53 bool CheckSensorConfiguration( 54 bool CheckSensorConfiguration(
54 const device::PlatformSensorConfiguration& configuration) override { 55 const device::PlatformSensorConfiguration& configuration) override {
55 return true; 56 return true;
56 } 57 }
57 device::PlatformSensorConfiguration GetDefaultConfiguration() override { 58 device::PlatformSensorConfiguration GetDefaultConfiguration() override {
58 device::PlatformSensorConfiguration default_configuration; 59 return device::PlatformSensorConfiguration(60 /* frequency */);
59 default_configuration.set_frequency(60);
60 return default_configuration;
61 } 60 }
62 }; 61 };
63 62
64 class FakeSensorProvider : public device::PlatformSensorProvider { 63 class FakeSensorProvider : public device::PlatformSensorProvider {
65 public: 64 public:
66 static FakeSensorProvider* GetInstance() { 65 static FakeSensorProvider* GetInstance() {
67 return base::Singleton<FakeSensorProvider, base::LeakySingletonTraits< 66 return base::Singleton<FakeSensorProvider, base::LeakySingletonTraits<
68 FakeSensorProvider>>::get(); 67 FakeSensorProvider>>::get();
69 } 68 }
70 FakeSensorProvider() = default; 69 FakeSensorProvider() = default;
71 ~FakeSensorProvider() override = default; 70 ~FakeSensorProvider() override = default;
72 71
73 protected: 72 protected:
74 void CreateSensorInternal(device::mojom::SensorType type, 73 void CreateSensorInternal(device::mojom::SensorType type,
75 mojo::ScopedSharedBufferMapping mapping, 74 mojo::ScopedSharedBufferMapping mapping,
76 const CreateSensorCallback& callback) override { 75 const CreateSensorCallback& callback) override {
77 // Create Sensors here. 76 // Create Sensors here.
78 switch (type) { 77 switch (type) {
79 case device::mojom::SensorType::AMBIENT_LIGHT: { 78 case device::mojom::SensorType::AMBIENT_LIGHT: {
80 scoped_refptr<device::PlatformSensor> sensor = 79 scoped_refptr<device::PlatformSensor> sensor =
81 new FakeAmbientLightSensor(type, std::move(mapping), this); 80 new FakeAmbientLightSensor(std::move(mapping), this);
82 callback.Run(std::move(sensor)); 81 callback.Run(std::move(sensor));
83 break; 82 break;
84 } 83 }
85 default: 84 default:
86 NOTIMPLEMENTED(); 85 NOTIMPLEMENTED();
87 callback.Run(nullptr); 86 callback.Run(nullptr);
88 } 87 }
89 } 88 }
90 }; 89 };
91 90
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // expects to get events with fake values then navigates to #pass. 126 // expects to get events with fake values then navigates to #pass.
128 GURL test_url = 127 GURL test_url =
129 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html"); 128 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html");
130 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 129 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
131 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 130 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
132 } 131 }
133 132
134 } // namespace 133 } // namespace
135 134
136 } // namespace content 135 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698