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

Side by Side Diff: content/browser/device_orientation/device_orientation_browsertest.cc

Issue 10827415: Chromium-side implementation of DeviceMotion. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test should set the kEnableDeviceMotion flag Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "content/browser/device_orientation/device_data.h" 9 #include "content/browser/device_orientation/device_data.h"
10 #include "content/browser/device_orientation/motion.h"
10 #include "content/browser/device_orientation/orientation.h" 11 #include "content/browser/device_orientation/orientation.h"
11 #include "content/browser/device_orientation/provider.h" 12 #include "content/browser/device_orientation/provider.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/shell/shell.h" 15 #include "content/shell/shell.h"
15 #include "content/test/content_browser_test.h" 16 #include "content/test/content_browser_test.h"
16 #include "content/test/content_browser_test_utils.h" 17 #include "content/test/content_browser_test_utils.h"
17 18
18 namespace content { 19 namespace content {
19 20
(...skipping 21 matching lines...) Expand all
41 42
42 private: 43 private:
43 virtual ~MockProvider() {} 44 virtual ~MockProvider() {}
44 }; 45 };
45 46
46 class DeviceOrientationBrowserTest : public ContentBrowserTest { 47 class DeviceOrientationBrowserTest : public ContentBrowserTest {
47 public: 48 public:
48 // From ContentBrowserTest. 49 // From ContentBrowserTest.
49 virtual void SetUpCommandLine(CommandLine* command_line) { 50 virtual void SetUpCommandLine(CommandLine* command_line) {
50 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); 51 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation));
52 command_line->AppendSwitch(switches::kEnableDeviceMotion);
51 } 53 }
52 }; 54 };
53 55
54 // crbug.com/113952 56 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicMotionTest) {
55 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { 57 scoped_refptr<Motion> test_motion(new Motion());
58 test_motion->set_acceleration_x(1);
59 test_motion->set_acceleration_y(2);
60 test_motion->set_acceleration_z(3);
61 test_motion->set_acceleration_including_gravity_x(4);
62 test_motion->set_acceleration_including_gravity_y(5);
63 test_motion->set_acceleration_including_gravity_z(6);
64 test_motion->set_rotation_rate_alpha(7);
65 test_motion->set_rotation_rate_beta(8);
66 test_motion->set_rotation_rate_gamma(9);
67 test_motion->set_interval(10);
68 scoped_refptr<MockProvider> provider(new MockProvider(
69 test_motion, DeviceData::kTypeMotion));
70 Provider::SetInstanceForTests(provider.get());
71
72 // The test page will register an event handler for motion events,
73 // expects to get an event with kTypeMotion device_data,
74 // then removes the event handler and navigates to #pass.
75 GURL test_url = content::GetTestUrl(
76 "device_orientation", "device_motion_test.html");
77 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
78
79 // Check that the page got the event it expected and that the provider
80 // saw requests for adding and removing an observer.
81 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref());
82 EXPECT_TRUE(provider->added_observer_);
83 EXPECT_TRUE(provider->removed_observer_);
84 }
85
86 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicOrientationTest) {
56 scoped_refptr<Orientation> test_orientation(new Orientation()); 87 scoped_refptr<Orientation> test_orientation(new Orientation());
57 test_orientation->set_alpha(1); 88 test_orientation->set_alpha(1);
58 test_orientation->set_beta(2); 89 test_orientation->set_beta(2);
59 test_orientation->set_gamma(3); 90 test_orientation->set_gamma(3);
60 test_orientation->set_absolute(true); 91 test_orientation->set_absolute(true);
61 scoped_refptr<MockProvider> provider(new MockProvider( 92 scoped_refptr<MockProvider> provider(new MockProvider(
62 test_orientation, DeviceData::kTypeOrientation)); 93 test_orientation, DeviceData::kTypeOrientation));
63 Provider::SetInstanceForTests(provider.get()); 94 Provider::SetInstanceForTests(provider.get());
64 95
65 // The test page will register an event handler for orientation events, 96 // The test page will register an event handler for orientation events,
66 // expects to get an event with kTestOrientation orientation, 97 // expects to get an event with kTypeOrientation device_data,
67 // then removes the event handler and navigates to #pass. 98 // then removes the event handler and navigates to #pass.
68 GURL test_url = GetTestUrl( 99 GURL test_url = GetTestUrl(
69 "device_orientation", "device_orientation_test.html"); 100 "device_orientation", "device_orientation_test.html");
70 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 101 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
71 102
72 // Check that the page got the event it expected and that the provider 103 // Check that the page got the event it expected and that the provider
73 // saw requests for adding and removing an observer. 104 // saw requests for adding and removing an observer.
74 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref()); 105 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref());
75 EXPECT_TRUE(provider->added_observer_); 106 EXPECT_TRUE(provider->added_observer_);
76 EXPECT_TRUE(provider->removed_observer_); 107 EXPECT_TRUE(provider->removed_observer_);
77 } 108 }
78 109
79 } // namespace content 110 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698