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