| OLD | NEW |
| 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/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/generic_sensor/platform_sensor.h" | 21 #include "device/generic_sensor/platform_sensor.h" |
| 21 #include "device/generic_sensor/platform_sensor_provider.h" | 22 #include "device/generic_sensor/platform_sensor_provider.h" |
| 22 #include "device/generic_sensor/sensor_provider_impl.h" | 23 #include "device/generic_sensor/sensor_provider_impl.h" |
| 24 #include "services/device/public/cpp/device_features.h" |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 class FakeAmbientLightSensor : public device::PlatformSensor { | 30 class FakeAmbientLightSensor : public device::PlatformSensor { |
| 29 public: | 31 public: |
| 30 FakeAmbientLightSensor(mojo::ScopedSharedBufferMapping mapping, | 32 FakeAmbientLightSensor(mojo::ScopedSharedBufferMapping mapping, |
| 31 device::PlatformSensorProvider* provider) | 33 device::PlatformSensorProvider* provider) |
| 32 : PlatformSensor(device::mojom::SensorType::AMBIENT_LIGHT, | 34 : PlatformSensor(device::mojom::SensorType::AMBIENT_LIGHT, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 callback.Run(nullptr); | 88 callback.Run(nullptr); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 class GenericSensorBrowserTest : public ContentBrowserTest { | 93 class GenericSensorBrowserTest : public ContentBrowserTest { |
| 92 public: | 94 public: |
| 93 GenericSensorBrowserTest() | 95 GenericSensorBrowserTest() |
| 94 : io_loop_finished_event_( | 96 : io_loop_finished_event_( |
| 95 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 97 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 96 base::WaitableEvent::InitialState::NOT_SIGNALED) { | 98 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 99 |
| 100 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 97 // TODO(darktears): remove when the GenericSensor feature goes stable. | 101 // TODO(darktears): remove when the GenericSensor feature goes stable. |
| 98 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 102 scoped_feature_list_.InitAndEnableFeature(features::kGenericSensor); |
| 99 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, "GenericSensor"); | |
| 100 } | 103 } |
| 101 | 104 |
| 102 void SetUpOnMainThread() override { | 105 void SetUpOnMainThread() override { |
| 103 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
| 104 BrowserThread::IO, FROM_HERE, | 107 BrowserThread::IO, FROM_HERE, |
| 105 base::Bind(&GenericSensorBrowserTest::SetUpOnIOThread, | 108 base::Bind(&GenericSensorBrowserTest::SetUpOnIOThread, |
| 106 base::Unretained(this))); | 109 base::Unretained(this))); |
| 107 io_loop_finished_event_.Wait(); | 110 io_loop_finished_event_.Wait(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void SetUpOnIOThread() { | 113 void SetUpOnIOThread() { |
| 111 device::PlatformSensorProvider::SetProviderForTesting( | 114 device::PlatformSensorProvider::SetProviderForTesting( |
| 112 FakeSensorProvider::GetInstance()); | 115 FakeSensorProvider::GetInstance()); |
| 113 io_loop_finished_event_.Signal(); | 116 io_loop_finished_event_.Signal(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void TearDown() override { | 119 void TearDown() override { |
| 117 device::PlatformSensorProvider::SetProviderForTesting(nullptr); | 120 device::PlatformSensorProvider::SetProviderForTesting(nullptr); |
| 118 } | 121 } |
| 119 | 122 |
| 120 public: | |
| 121 base::WaitableEvent io_loop_finished_event_; | 123 base::WaitableEvent io_loop_finished_event_; |
| 124 base::test::ScopedFeatureList scoped_feature_list_; |
| 122 }; | 125 }; |
| 123 | 126 |
| 124 IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) { | 127 IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) { |
| 125 // The test page will create an AmbientLightSensor object in Javascript, | 128 // The test page will create an AmbientLightSensor object in Javascript, |
| 126 // expects to get events with fake values then navigates to #pass. | 129 // expects to get events with fake values then navigates to #pass. |
| 127 GURL test_url = | 130 GURL test_url = |
| 128 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html"); | 131 GetTestUrl("generic_sensor", "ambient_light_sensor_test.html"); |
| 129 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 132 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 130 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 133 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 131 } | 134 } |
| 132 | 135 |
| 133 } // namespace | 136 } // namespace |
| 134 | 137 |
| 135 } // namespace content | 138 } // namespace content |
| OLD | NEW |