Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 device_orientation { | 19 namespace device_orientation { |
| 19 | 20 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 class DeviceOrientationBrowserTest : public content::ContentBrowserTest { | 47 class DeviceOrientationBrowserTest : public content::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)); |
| 51 } | 52 } |
| 52 }; | 53 }; |
| 53 | 54 |
| 55 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicMotionTest) { | |
| 56 scoped_refptr<Motion> test_motion(new Motion()); | |
| 57 test_motion->set_acceleration_x(1); | |
| 58 test_motion->set_acceleration_y(2); | |
| 59 test_motion->set_acceleration_z(3); | |
| 60 test_motion->set_acceleration_including_gravity_x(4); | |
| 61 test_motion->set_acceleration_including_gravity_y(5); | |
| 62 test_motion->set_acceleration_including_gravity_z(6); | |
| 63 test_motion->set_rotation_rate_alpha(7); | |
| 64 test_motion->set_rotation_rate_beta(8); | |
| 65 test_motion->set_rotation_rate_gamma(9); | |
| 66 test_motion->set_interval(10); | |
| 67 scoped_refptr<MockProvider> provider(new MockProvider( | |
| 68 test_motion, DeviceData::kTypeMotion)); | |
| 69 Provider::SetInstanceForTests(provider.get()); | |
| 70 | |
| 71 // The test page will register an event handler for motion events, | |
| 72 // expects to get an event with kTypeMotion device_data, | |
| 73 // then removes the event handler and navigates to #pass. | |
| 74 GURL test_url = content::GetTestUrl( | |
| 75 "device_orientation", "device_motion_test.html"); | |
| 76 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | |
| 77 | |
| 78 // Check that the page got the event it expected and that the provider | |
| 79 // saw requests for adding and removing an observer. | |
| 80 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref()); | |
| 81 EXPECT_TRUE(provider->added_observer_); | |
| 82 EXPECT_TRUE(provider->removed_observer_); | |
| 83 } | |
| 84 | |
| 54 // crbug.com/113952 | 85 // crbug.com/113952 |
|
hans
2012/08/13 13:35:19
this crbug.com comment is obsolete; feel free to r
aousterh
2012/08/16 15:23:49
Done.
| |
| 55 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { | 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 = content::GetTestUrl( | 99 GURL test_url = content::GetTestUrl( |
| 69 "device_orientation", "device_orientation_test.html"); | 100 "device_orientation", "device_orientation_test.html"); |
| 70 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 101 content::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 device_orientation | 110 } // namespace device_orientation |
| OLD | NEW |