| 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 "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | 9 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "content/browser/device_orientation/orientation.h" | 12 #include "content/browser/device_orientation/orientation.h" |
| 13 #include "content/browser/device_orientation/provider.h" | 13 #include "content/browser/device_orientation/provider.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 | 16 |
| 17 namespace device_orientation { | 17 namespace device_orientation { |
| 18 | 18 |
| 19 class MockProvider : public Provider { | 19 class MockProvider : public Provider { |
| 20 public: | 20 public: |
| 21 explicit MockProvider(const Orientation& orientation) | 21 explicit MockProvider(const Orientation& orientation) |
| 22 : orientation_(orientation), | 22 : orientation_(orientation), |
| 23 added_observer_(false), | 23 added_orientation_observer_(false), |
| 24 removed_observer_(false) {} | 24 removed_orientation_observer_(false) {} |
| 25 | 25 |
| 26 virtual void AddObserver(Observer* observer) { | 26 virtual void AddOrientationObserver(OrientationObserver* observer) { |
| 27 added_observer_ = true; | 27 added_orientation_observer_ = true; |
| 28 observer->OnOrientationUpdate(orientation_); | 28 observer->OnOrientationUpdate(orientation_); |
| 29 } | 29 } |
| 30 virtual void RemoveObserver(Observer* observer) { | 30 virtual void RemoveOrientationObserver(OrientationObserver* observer) { |
| 31 removed_observer_ = true; | 31 removed_orientation_observer_ = true; |
| 32 } | 32 } |
| 33 | 33 |
| 34 Orientation orientation_; | 34 Orientation orientation_; |
| 35 bool added_observer_; | 35 bool added_orientation_observer_; |
| 36 bool removed_observer_; | 36 bool removed_orientation_observer_; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 virtual ~MockProvider() {} | 39 virtual ~MockProvider() {} |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class DeviceOrientationBrowserTest : public InProcessBrowserTest { | 42 class DeviceOrientationBrowserTest : public InProcessBrowserTest { |
| 43 public: | 43 public: |
| 44 // From InProcessBrowserTest. | 44 // From InProcessBrowserTest. |
| 45 virtual void SetUpCommandLine(CommandLine* command_line) { | 45 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 46 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); | 46 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 // expects to get an event with kTestOrientation orientation, | 62 // expects to get an event with kTestOrientation orientation, |
| 63 // then removes the event handler and navigates to #pass. | 63 // then removes the event handler and navigates to #pass. |
| 64 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html")); | 64 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html")); |
| 65 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 65 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
| 66 test_url, | 66 test_url, |
| 67 2); | 67 2); |
| 68 | 68 |
| 69 // Check that the page got the event it expected and that the provider | 69 // Check that the page got the event it expected and that the provider |
| 70 // saw requests for adding and removing an observer. | 70 // saw requests for adding and removing an observer. |
| 71 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); | 71 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); |
| 72 EXPECT_TRUE(provider->added_observer_); | 72 EXPECT_TRUE(provider->added_orientation_observer_); |
| 73 EXPECT_TRUE(provider->removed_observer_); | 73 EXPECT_TRUE(provider->removed_orientation_observer_); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace device_orientation | 76 } // namespace device_orientation |
| OLD | NEW |