| Index: content/browser/device_orientation/device_orientation_browsertest.cc
|
| diff --git a/content/browser/device_orientation/device_orientation_browsertest.cc b/content/browser/device_orientation/device_orientation_browsertest.cc
|
| index 9459ef93f26e5ea325d5e039caee27a2207e6c7e..303adb44e46d737b1df395a1714a6066794b993d 100644
|
| --- a/content/browser/device_orientation/device_orientation_browsertest.cc
|
| +++ b/content/browser/device_orientation/device_orientation_browsertest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "chrome/browser/ui/browser_tabstrip.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| +#include "content/browser/device_orientation/motion.h"
|
| #include "content/browser/device_orientation/orientation.h"
|
| #include "content/browser/device_orientation/provider.h"
|
| #include "content/public/browser/web_contents.h"
|
| @@ -18,22 +19,35 @@ namespace device_orientation {
|
|
|
| class MockProvider : public Provider {
|
| public:
|
| - explicit MockProvider(const Orientation& orientation)
|
| - : orientation_(orientation),
|
| - added_observer_(false),
|
| - removed_observer_(false) {}
|
| + explicit MockProvider(const Motion& motion, const Orientation& orientation)
|
| + : motion_(motion),
|
| + orientation_(orientation),
|
| + added_motion_observer_(false),
|
| + added_orientation_observer_(false),
|
| + removed_motion_observer_(false),
|
| + removed_orientation_observer_(false) {}
|
|
|
| - virtual void AddObserver(Observer* observer) {
|
| - added_observer_ = true;
|
| + virtual void AddMotionObserver(MotionObserver* observer) {
|
| + added_motion_observer_ = true;
|
| + observer->OnMotionUpdate(motion_);
|
| + }
|
| + virtual void AddOrientationObserver(OrientationObserver* observer) {
|
| + added_orientation_observer_ = true;
|
| observer->OnOrientationUpdate(orientation_);
|
| }
|
| - virtual void RemoveObserver(Observer* observer) {
|
| - removed_observer_ = true;
|
| + virtual void RemoveMotionObserver(MotionObserver* observer) {
|
| + removed_motion_observer_ = true;
|
| + }
|
| + virtual void RemoveOrientationObserver(OrientationObserver* observer) {
|
| + removed_orientation_observer_ = true;
|
| }
|
|
|
| + Motion motion_;
|
| Orientation orientation_;
|
| - bool added_observer_;
|
| - bool removed_observer_;
|
| + bool added_motion_observer_;
|
| + bool added_orientation_observer_;
|
| + bool removed_motion_observer_;
|
| + bool removed_orientation_observer_;
|
|
|
| private:
|
| virtual ~MockProvider() {}
|
| @@ -52,14 +66,47 @@ class DeviceOrientationBrowserTest : public InProcessBrowserTest {
|
| }
|
| };
|
|
|
| -// crbug.com/113952
|
| -IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
|
| - const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true);
|
| - scoped_refptr<MockProvider> provider(new MockProvider(kTestOrientation));
|
| +IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicMotionTest) {
|
| + const Orientation kTestOrientation;
|
| + Motion test_motion;
|
| + test_motion.set_acceleration_x(1);
|
| + test_motion.set_acceleration_y(2);
|
| + test_motion.set_acceleration_z(3);
|
| + test_motion.set_acceleration_including_gravity_x(4);
|
| + test_motion.set_acceleration_including_gravity_y(5);
|
| + test_motion.set_acceleration_including_gravity_z(6);
|
| + test_motion.set_rotation_rate_alpha(7);
|
| + test_motion.set_rotation_rate_beta(8);
|
| + test_motion.set_rotation_rate_gamma(9);
|
| + test_motion.set_interval(10);
|
| + scoped_refptr<MockProvider> provider(
|
| + new MockProvider(test_motion, kTestOrientation));
|
| + Provider::SetInstanceForTests(provider.get());
|
| +
|
| + // The test page will register an event handler for motion events,
|
| + // expects to get an event with test_motion motion,
|
| + // then removes the event handler and navigates to #pass.
|
| + GURL test_url = testUrl(FILE_PATH_LITERAL("device_motion_test.html"));
|
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
|
| + test_url,
|
| + 2);
|
| +
|
| + // Check that the page got the event it expected and that the provider
|
| + // saw requests for adding and removing an observer.
|
| + EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref());
|
| + EXPECT_TRUE(provider->added_motion_observer_);
|
| + EXPECT_TRUE(provider->removed_motion_observer_);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicOrientationTest) {
|
| + const Motion kMotion;
|
| + const Orientation test_orientation(true, 1, true, 2, true, 3, true, true);
|
| + scoped_refptr<MockProvider> provider(
|
| + new MockProvider(kMotion, test_orientation));
|
| Provider::SetInstanceForTests(provider.get());
|
|
|
| // The test page will register an event handler for orientation events,
|
| - // expects to get an event with kTestOrientation orientation,
|
| + // expects to get an event with test_orientation orientation,
|
| // then removes the event handler and navigates to #pass.
|
| GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html"));
|
| ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
|
| @@ -69,8 +116,8 @@ IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
|
| // Check that the page got the event it expected and that the provider
|
| // saw requests for adding and removing an observer.
|
| EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref());
|
| - EXPECT_TRUE(provider->added_observer_);
|
| - EXPECT_TRUE(provider->removed_observer_);
|
| + EXPECT_TRUE(provider->added_orientation_observer_);
|
| + EXPECT_TRUE(provider->removed_orientation_observer_);
|
| }
|
|
|
| } // namespace device_orientation
|
|
|