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

Unified Diff: content/browser/device_orientation/device_orientation_browsertest.cc

Issue 10698046: Implements part of Device Motion in the Renderer (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
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 6eabd93c37ab71b24f92fed224d84f972701d198..f6f7febd45ea998d00eec123094b69c8aee1f8c8 100644
--- a/content/browser/device_orientation/device_orientation_browsertest.cc
+++ b/content/browser/device_orientation/device_orientation_browsertest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/ui/browser.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"
@@ -17,22 +18,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)
bulach 2012/07/02 12:47:56 nit: "explicit" is no longer needed..
aousterh 2012/07/04 13:31:55 Done.
+ : 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() {}
@@ -51,10 +65,43 @@ class DeviceOrientationBrowserTest : public InProcessBrowserTest {
}
};
-// crbug.com/113952
-IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
+IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicMotionTest) {
+ Motion kTestMotion;
bulach 2012/07/02 12:47:56 nit: "k" is used for constants, in this case just
aousterh 2012/07/04 13:31:55 Done.
+ Orientation kTestOrientation;
+ kTestMotion.setAccelerationX(1);
+ kTestMotion.setAccelerationY(2);
+ kTestMotion.setAccelerationZ(3);
+ kTestMotion.setAccelerationIncludingGravityX(4);
+ kTestMotion.setAccelerationIncludingGravityY(5);
+ kTestMotion.setAccelerationIncludingGravityZ(6);
+ kTestMotion.setRotationRateAlpha(7);
+ kTestMotion.setRotationRateBeta(8);
+ kTestMotion.setRotationRateGamma(9);
+ kTestMotion.setInterval(10);
+ scoped_refptr<MockProvider> provider(
+ new MockProvider(kTestMotion, kTestOrientation));
+ Provider::SetInstanceForTests(provider.get());
+
+ // The test page will register an event handler for motion events,
+ // expects to get an event with kTestMotion 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", browser()->GetActiveWebContents()->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 kTestOrientation(true, 1, true, 2, true, 3, true, true);
- scoped_refptr<MockProvider> provider(new MockProvider(kTestOrientation));
+ scoped_refptr<MockProvider> provider(
+ new MockProvider(kMotion, kTestOrientation));
Provider::SetInstanceForTests(provider.get());
// The test page will register an event handler for orientation events,
@@ -68,8 +115,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", browser()->GetActiveWebContents()->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

Powered by Google App Engine
This is Rietveld 408576698