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" |
| 9 #include "content/browser/device_orientation/device_data.h" |
8 #include "content/browser/device_orientation/orientation.h" | 10 #include "content/browser/device_orientation/orientation.h" |
9 #include "content/browser/device_orientation/provider.h" | 11 #include "content/browser/device_orientation/provider.h" |
10 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
11 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
12 #include "content/shell/shell.h" | 14 #include "content/shell/shell.h" |
13 #include "content/test/content_browser_test.h" | 15 #include "content/test/content_browser_test.h" |
14 #include "content/test/content_browser_test_utils.h" | 16 #include "content/test/content_browser_test_utils.h" |
15 | 17 |
16 namespace device_orientation { | 18 namespace device_orientation { |
17 | 19 |
18 class MockProvider : public Provider { | 20 class MockProvider : public Provider { |
19 public: | 21 public: |
20 explicit MockProvider(const Orientation& orientation) | 22 MockProvider(const DeviceData* device_data, DeviceData::Type type) |
21 : orientation_(orientation), | 23 : device_data_(device_data), |
| 24 device_data_type_(type), |
22 added_observer_(false), | 25 added_observer_(false), |
23 removed_observer_(false) {} | 26 removed_observer_(false) { |
| 27 } |
24 | 28 |
25 virtual void AddObserver(Observer* observer) { | 29 virtual void AddObserver(Observer* observer) { |
26 added_observer_ = true; | 30 added_observer_ = true; |
27 observer->OnOrientationUpdate(orientation_); | 31 observer->OnDeviceDataUpdate(device_data_.get(), device_data_type_); |
28 } | 32 } |
29 virtual void RemoveObserver(Observer* observer) { | 33 virtual void RemoveObserver(Observer* observer) { |
30 removed_observer_ = true; | 34 removed_observer_ = true; |
31 } | 35 } |
32 | 36 |
33 Orientation orientation_; | 37 scoped_refptr<const DeviceData> device_data_; |
| 38 DeviceData::Type device_data_type_; |
34 bool added_observer_; | 39 bool added_observer_; |
35 bool removed_observer_; | 40 bool removed_observer_; |
36 | 41 |
37 private: | 42 private: |
38 virtual ~MockProvider() {} | 43 virtual ~MockProvider() {} |
39 }; | 44 }; |
40 | 45 |
41 class DeviceOrientationBrowserTest : public content::ContentBrowserTest { | 46 class DeviceOrientationBrowserTest : public content::ContentBrowserTest { |
42 public: | 47 public: |
43 // From ContentBrowserTest. | 48 // From ContentBrowserTest. |
44 virtual void SetUpCommandLine(CommandLine* command_line) { | 49 virtual void SetUpCommandLine(CommandLine* command_line) { |
45 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); | 50 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); |
46 } | 51 } |
47 }; | 52 }; |
48 | 53 |
49 // crbug.com/113952 | 54 // crbug.com/113952 |
50 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { | 55 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { |
51 Orientation test_orientation; | 56 scoped_refptr<Orientation> test_orientation(new Orientation()); |
52 test_orientation.set_alpha(1); | 57 test_orientation->set_alpha(1); |
53 test_orientation.set_beta(2); | 58 test_orientation->set_beta(2); |
54 test_orientation.set_gamma(3); | 59 test_orientation->set_gamma(3); |
55 test_orientation.set_absolute(true); | 60 test_orientation->set_absolute(true); |
56 scoped_refptr<MockProvider> provider(new MockProvider(test_orientation)); | 61 scoped_refptr<MockProvider> provider(new MockProvider( |
| 62 test_orientation, DeviceData::kTypeOrientation)); |
57 Provider::SetInstanceForTests(provider.get()); | 63 Provider::SetInstanceForTests(provider.get()); |
58 | 64 |
59 // The test page will register an event handler for orientation events, | 65 // The test page will register an event handler for orientation events, |
60 // expects to get an event with kTestOrientation orientation, | 66 // expects to get an event with kTestOrientation orientation, |
61 // then removes the event handler and navigates to #pass. | 67 // then removes the event handler and navigates to #pass. |
62 GURL test_url = content::GetTestUrl( | 68 GURL test_url = content::GetTestUrl( |
63 "device_orientation", "device_orientation_test.html"); | 69 "device_orientation", "device_orientation_test.html"); |
64 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 70 content::NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
65 | 71 |
66 // Check that the page got the event it expected and that the provider | 72 // Check that the page got the event it expected and that the provider |
67 // saw requests for adding and removing an observer. | 73 // saw requests for adding and removing an observer. |
68 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref()); | 74 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref()); |
69 EXPECT_TRUE(provider->added_observer_); | 75 EXPECT_TRUE(provider->added_observer_); |
70 EXPECT_TRUE(provider->removed_observer_); | 76 EXPECT_TRUE(provider->removed_observer_); |
71 } | 77 } |
72 | 78 |
73 } // namespace device_orientation | 79 } // namespace device_orientation |
OLD | NEW |