| Index: chrome/browser/generic_sensor_browsertest.cc
|
| diff --git a/content/browser/generic_sensor_browsertest.cc b/chrome/browser/generic_sensor_browsertest.cc
|
| similarity index 76%
|
| rename from content/browser/generic_sensor_browsertest.cc
|
| rename to chrome/browser/generic_sensor_browsertest.cc
|
| index 745cbfea7469294a45f4c1170a4ab7bc0c6f4490..0a26add98eebe9f321ea9237630b0411c3296fdc 100644
|
| --- a/content/browser/generic_sensor_browsertest.cc
|
| +++ b/chrome/browser/generic_sensor_browsertest.cc
|
| @@ -7,22 +7,13 @@
|
| #include "base/memory/singleton.h"
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/threading/platform_thread.h"
|
| -#include "build/build_config.h"
|
| +#include "chrome/browser/permissions/permissions_browsertest.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/web_contents.h"
|
| #include "content/public/common/content_switches.h"
|
| -#include "content/public/test/content_browser_test.h"
|
| -#include "content/public/test/content_browser_test_utils.h"
|
| -#include "content/public/test/test_navigation_observer.h"
|
| -#include "content/public/test/test_utils.h"
|
| -#include "content/shell/browser/shell.h"
|
| -#include "content/shell/browser/shell_javascript_dialog_manager.h"
|
| #include "device/generic_sensor/platform_sensor.h"
|
| #include "device/generic_sensor/platform_sensor_provider.h"
|
| #include "device/generic_sensor/sensor_provider_impl.h"
|
|
|
| -namespace content {
|
| -
|
| namespace {
|
|
|
| class FakeAmbientLightSensor : public device::PlatformSensor {
|
| @@ -89,10 +80,12 @@ class FakeSensorProvider : public device::PlatformSensorProvider {
|
| }
|
| };
|
|
|
| -class GenericSensorBrowserTest : public ContentBrowserTest {
|
| +class GenericSensorBrowserTest : public PermissionsBrowserTest {
|
| public:
|
| GenericSensorBrowserTest()
|
| - : io_loop_finished_event_(
|
| + : PermissionsBrowserTest(
|
| + "/generic_sensor/ambient_light_sensor_test.html"),
|
| + io_loop_finished_event_(
|
| base::WaitableEvent::ResetPolicy::AUTOMATIC,
|
| base::WaitableEvent::InitialState::NOT_SIGNALED) {
|
| // TODO(darktears): remove when the GenericSensor feature goes stable.
|
| @@ -101,36 +94,51 @@ class GenericSensorBrowserTest : public ContentBrowserTest {
|
| }
|
|
|
| void SetUpOnMainThread() override {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO, FROM_HERE,
|
| + PermissionsBrowserTest::SetUpOnMainThread();
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::IO, FROM_HERE,
|
| base::Bind(&GenericSensorBrowserTest::SetUpOnIOThread,
|
| base::Unretained(this)));
|
| io_loop_finished_event_.Wait();
|
| }
|
|
|
| + void TriggerPrompt() override {
|
| + EXPECT_TRUE(RunScriptReturnBool("triggerSensorStart();"));
|
| + }
|
| +
|
| + bool FeatureUsageSucceeds() override {
|
| + return GetWebContents()->GetLastCommittedURL().ref() == "pass";
|
| + }
|
| +
|
| void SetUpOnIOThread() {
|
| device::PlatformSensorProvider::SetProviderForTesting(
|
| FakeSensorProvider::GetInstance());
|
| io_loop_finished_event_.Signal();
|
| }
|
|
|
| - void TearDown() override {
|
| + void TearDownOnMainThread() override {
|
| device::PlatformSensorProvider::SetProviderForTesting(nullptr);
|
| + PermissionsBrowserTest::TearDownOnMainThread();
|
| }
|
|
|
| public:
|
| base::WaitableEvent io_loop_finished_event_;
|
| };
|
|
|
| -IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) {
|
| - // The test page will create an AmbientLightSensor object in Javascript,
|
| - // expects to get events with fake values then navigates to #pass.
|
| - GURL test_url =
|
| - GetTestUrl("generic_sensor", "ambient_light_sensor_test.html");
|
| - NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
|
| - EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
|
| +IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, SensorSucceedsIfAllowed) {
|
| + CommonSucceedsIfAllowed();
|
| }
|
|
|
| -} // namespace
|
| +IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, SensorFailsIfBlocked) {
|
| + CommonFailsIfBlocked();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, SensorFailsIfDismissed) {
|
| + CommonFailsIfDismissed();
|
| +}
|
|
|
| -} // namespace content
|
| +IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, SensorFailsBeforeRequesting) {
|
| + CommonFailsBeforeRequesting();
|
| +}
|
| +
|
| +} // namespace
|
|
|