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

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

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Handles null device_data in observer Created 8 years, 5 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
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 "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 explicit MockProvider(const Orientation* orientation,
hans 2012/07/18 17:21:02 no need for explicit here
aousterh 2012/07/20 11:18:52 Done. Also changed orientation->device data so tha
22 : orientation_(orientation), 24 DeviceData::Type device_data_type)
25 : device_data_type_(device_data_type),
23 added_observer_(false), 26 added_observer_(false),
24 removed_observer_(false) {} 27 removed_observer_(false) {
28 orientation_.reset(orientation);
29 }
25 30
26 virtual void AddObserver(Observer* observer) { 31 virtual void AddObserver(Observer* observer) {
27 added_observer_ = true; 32 added_observer_ = true;
28 observer->OnOrientationUpdate(orientation_); 33 observer->OnDeviceDataUpdate(orientation_.get(), device_data_type_);
29 } 34 }
30 virtual void RemoveObserver(Observer* observer) { 35 virtual void RemoveObserver(Observer* observer) {
31 removed_observer_ = true; 36 removed_observer_ = true;
32 } 37 }
33 38
34 Orientation orientation_; 39 scoped_ptr<const Orientation> orientation_;
aousterh 2012/07/20 11:18:52 Changing this to device_data_ instead of orientati
40 DeviceData::Type device_data_type_;
35 bool added_observer_; 41 bool added_observer_;
36 bool removed_observer_; 42 bool removed_observer_;
37 43
38 private: 44 private:
39 virtual ~MockProvider() {} 45 virtual ~MockProvider() {}
40 }; 46 };
41 47
42 class DeviceOrientationBrowserTest : public InProcessBrowserTest { 48 class DeviceOrientationBrowserTest : public InProcessBrowserTest {
43 public: 49 public:
44 // From InProcessBrowserTest. 50 // From InProcessBrowserTest.
45 virtual void SetUpCommandLine(CommandLine* command_line) { 51 virtual void SetUpCommandLine(CommandLine* command_line) {
46 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); 52 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation));
47 } 53 }
48 54
49 GURL testUrl(const FilePath::CharType* filename) { 55 GURL testUrl(const FilePath::CharType* filename) {
50 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation")); 56 const FilePath kTestDir(FILE_PATH_LITERAL("device_orientation"));
51 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename)); 57 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
52 } 58 }
53 }; 59 };
54 60
55 // crbug.com/113952 61 // crbug.com/113952
56 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) { 62 IN_PROC_BROWSER_TEST_F(DeviceOrientationBrowserTest, BasicTest) {
57 Orientation test_orientation; 63 scoped_ptr<Orientation> test_orientation(new Orientation());
58 test_orientation.set_alpha(1); 64 test_orientation->set_alpha(1);
59 test_orientation.set_beta(2); 65 test_orientation->set_beta(2);
60 test_orientation.set_gamma(3); 66 test_orientation->set_gamma(3);
61 test_orientation.set_absolute(true); 67 test_orientation->set_absolute(true);
62 scoped_refptr<MockProvider> provider(new MockProvider(test_orientation)); 68 scoped_refptr<MockProvider> provider(new MockProvider(
69 test_orientation.release(), DeviceData::kTypeOrientation));
63 Provider::SetInstanceForTests(provider.get()); 70 Provider::SetInstanceForTests(provider.get());
64 71
65 // The test page will register an event handler for orientation events, 72 // The test page will register an event handler for orientation events,
66 // expects to get an event with kTestOrientation orientation, 73 // expects to get an event with kTestOrientation orientation,
67 // then removes the event handler and navigates to #pass. 74 // then removes the event handler and navigates to #pass.
68 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html")); 75 GURL test_url = testUrl(FILE_PATH_LITERAL("device_orientation_test.html"));
69 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 76 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
70 test_url, 77 test_url,
71 2); 78 2);
72 79
73 // Check that the page got the event it expected and that the provider 80 // Check that the page got the event it expected and that the provider
74 // saw requests for adding and removing an observer. 81 // saw requests for adding and removing an observer.
75 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); 82 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref());
76 EXPECT_TRUE(provider->added_observer_); 83 EXPECT_TRUE(provider->added_observer_);
77 EXPECT_TRUE(provider->removed_observer_); 84 EXPECT_TRUE(provider->removed_observer_);
78 } 85 }
79 86
80 } // namespace device_orientation 87 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698