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

Side by Side 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, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_path.h" 6 #include "base/file_path.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/device_orientation/motion.h"
11 #include "content/browser/device_orientation/orientation.h" 12 #include "content/browser/device_orientation/orientation.h"
12 #include "content/browser/device_orientation/provider.h" 13 #include "content/browser/device_orientation/provider.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
15 16
16 namespace device_orientation { 17 namespace device_orientation {
17 18
18 class MockProvider : public Provider { 19 class MockProvider : public Provider {
19 public: 20 public:
20 explicit MockProvider(const Orientation& orientation) 21 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.
21 : orientation_(orientation), 22 : motion_(motion),
22 added_observer_(false), 23 orientation_(orientation),
23 removed_observer_(false) {} 24 added_motion_observer_(false),
25 added_orientation_observer_(false),
26 removed_motion_observer_(false),
27 removed_orientation_observer_(false) {}
24 28
25 virtual void AddObserver(Observer* observer) { 29 virtual void AddMotionObserver(MotionObserver* observer) {
26 added_observer_ = true; 30 added_motion_observer_ = true;
31 observer->OnMotionUpdate(motion_);
32 }
33 virtual void AddOrientationObserver(OrientationObserver* observer) {
34 added_orientation_observer_ = true;
27 observer->OnOrientationUpdate(orientation_); 35 observer->OnOrientationUpdate(orientation_);
28 } 36 }
29 virtual void RemoveObserver(Observer* observer) { 37 virtual void RemoveMotionObserver(MotionObserver* observer) {
30 removed_observer_ = true; 38 removed_motion_observer_ = true;
39 }
40 virtual void RemoveOrientationObserver(OrientationObserver* observer) {
41 removed_orientation_observer_ = true;
31 } 42 }
32 43
44 Motion motion_;
33 Orientation orientation_; 45 Orientation orientation_;
34 bool added_observer_; 46 bool added_motion_observer_;
35 bool removed_observer_; 47 bool added_orientation_observer_;
48 bool removed_motion_observer_;
49 bool removed_orientation_observer_;
36 50
37 private: 51 private:
38 virtual ~MockProvider() {} 52 virtual ~MockProvider() {}
39 }; 53 };
40 54
41 class DeviceOrientationBrowserTest : public InProcessBrowserTest { 55 class DeviceOrientationBrowserTest : public InProcessBrowserTest {
42 public: 56 public:
43 // From InProcessBrowserTest. 57 // From InProcessBrowserTest.
44 virtual void SetUpCommandLine(CommandLine* command_line) { 58 virtual void SetUpCommandLine(CommandLine* command_line) {
45 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); 59 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation));
46 } 60 }
47 61
48 GURL testUrl(const FilePath::CharType* filename) { 62 GURL testUrl(const FilePath::CharType* filename) {
49 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation")); 63 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation"));
50 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename)); 64 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
51 } 65 }
52 }; 66 };
53 67
54 // crbug.com/113952 68 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicMotionTest) {
55 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { 69 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.
70 Orientation kTestOrientation;
71 kTestMotion.setAccelerationX(1);
72 kTestMotion.setAccelerationY(2);
73 kTestMotion.setAccelerationZ(3);
74 kTestMotion.setAccelerationIncludingGravityX(4);
75 kTestMotion.setAccelerationIncludingGravityY(5);
76 kTestMotion.setAccelerationIncludingGravityZ(6);
77 kTestMotion.setRotationRateAlpha(7);
78 kTestMotion.setRotationRateBeta(8);
79 kTestMotion.setRotationRateGamma(9);
80 kTestMotion.setInterval(10);
81 scoped_refptr<MockProvider> provider(
82 new MockProvider(kTestMotion, kTestOrientation));
83 Provider::SetInstanceForTests(provider.get());
84
85 // The test page will register an event handler for motion events,
86 // expects to get an event with kTestMotion motion,
87 // then removes the event handler and navigates to #pass.
88 GURL test_url = testUrl(FILE_PATH_LITERAL("device_motion_test.html"));
89 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
90 test_url,
91 2);
92
93 // Check that the page got the event it expected and that the provider
94 // saw requests for adding and removing an observer.
95 EXPECT_EQ("pass", browser()->GetActiveWebContents()->GetURL().ref());
96 EXPECT_TRUE(provider->added_motion_observer_);
97 EXPECT_TRUE(provider->removed_motion_observer_);
98 }
99
100 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicOrientationTest) {
101 const Motion kMotion;
56 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); 102 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true);
57 scoped_refptr<MockProvider> provider(new MockProvider(kTestOrientation)); 103 scoped_refptr<MockProvider> provider(
104 new MockProvider(kMotion, kTestOrientation));
58 Provider::SetInstanceForTests(provider.get()); 105 Provider::SetInstanceForTests(provider.get());
59 106
60 // The test page will register an event handler for orientation events, 107 // The test page will register an event handler for orientation events,
61 // expects to get an event with kTestOrientation orientation, 108 // expects to get an event with kTestOrientation orientation,
62 // then removes the event handler and navigates to #pass. 109 // then removes the event handler and navigates to #pass.
63 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html")); 110 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html"));
64 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 111 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
65 test_url, 112 test_url,
66 2); 113 2);
67 114
68 // Check that the page got the event it expected and that the provider 115 // Check that the page got the event it expected and that the provider
69 // saw requests for adding and removing an observer. 116 // saw requests for adding and removing an observer.
70 EXPECT_EQ("pass", browser()->GetActiveWebContents()->GetURL().ref()); 117 EXPECT_EQ("pass", browser()->GetActiveWebContents()->GetURL().ref());
71 EXPECT_TRUE(provider->added_observer_); 118 EXPECT_TRUE(provider->added_orientation_observer_);
72 EXPECT_TRUE(provider->removed_observer_); 119 EXPECT_TRUE(provider->removed_orientation_observer_);
73 } 120 }
74 121
75 } // namespace device_orientation 122 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698