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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc

Issue 336153002: Revert of Properly route screen orientation IPC messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screen_lock_view
Patch Set: Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
6
7 #include "base/logging.h" 5 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
9 #include "content/browser/screen_orientation/screen_orientation_provider.h" 8 #include "content/browser/screen_orientation/screen_orientation_provider.h"
10 #include "content/common/screen_orientation_messages.h" 9 #include "content/common/screen_orientation_messages.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/test/mock_render_process_host.h"
12 #include "content/public/test/test_browser_context.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
12 #include "ipc/ipc_test_sink.h" 15 #include "ipc/ipc_test_sink.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 17
15 namespace content { 18 namespace content {
16 19
17 class MockScreenOrientationProvider : public ScreenOrientationProvider { 20 class MockScreenOrientationProvider : public ScreenOrientationProvider {
18 public: 21 public:
19 MockScreenOrientationProvider() 22 MockScreenOrientationProvider()
20 : orientation_(blink::WebScreenOrientationLockPortraitPrimary), 23 : orientation_(blink::WebScreenOrientationLockPortraitPrimary),
(...skipping 22 matching lines...) Expand all
43 blink::WebScreenOrientationLockType orientation_; 46 blink::WebScreenOrientationLockType orientation_;
44 bool unlock_called_; 47 bool unlock_called_;
45 48
46 DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider); 49 DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
47 }; 50 };
48 51
49 class ScreenOrientationDispatcherHostWithSink FINAL : 52 class ScreenOrientationDispatcherHostWithSink FINAL :
50 public ScreenOrientationDispatcherHost { 53 public ScreenOrientationDispatcherHost {
51 public: 54 public:
52 explicit ScreenOrientationDispatcherHostWithSink(IPC::TestSink* sink) 55 explicit ScreenOrientationDispatcherHostWithSink(IPC::TestSink* sink)
53 : ScreenOrientationDispatcherHost(NULL), sink_(sink) {} 56 : ScreenOrientationDispatcherHost() , sink_(sink) {}
54 57
55 virtual bool Send(IPC::Message* message) OVERRIDE { 58 virtual bool Send(IPC::Message* message) OVERRIDE {
56 return sink_->Send(message); 59 return sink_->Send(message);
57 } 60 }
58 61
59 private: 62 private:
60 virtual ~ScreenOrientationDispatcherHostWithSink() { } 63 virtual ~ScreenOrientationDispatcherHostWithSink() { }
61 64
62 IPC::TestSink* sink_; 65 IPC::TestSink* sink_;
63 }; 66 };
64 67
65 class ScreenOrientationDispatcherHostTest : public testing::Test { 68 class ScreenOrientationDispatcherHostTest : public testing::Test {
66 protected: 69 protected:
67 virtual ScreenOrientationDispatcherHost* CreateDispatcher() { 70 virtual ScreenOrientationDispatcherHost* CreateDispatcher() {
68 return new ScreenOrientationDispatcherHost(NULL); 71 return new ScreenOrientationDispatcherHost();
69 } 72 }
70 73
71 virtual void SetUp() OVERRIDE { 74 virtual void SetUp() OVERRIDE {
72 provider_ = new MockScreenOrientationProvider(); 75 provider_ = new MockScreenOrientationProvider();
73 76
74 dispatcher_.reset(CreateDispatcher()); 77 dispatcher_ = CreateDispatcher();
75 dispatcher_->SetProviderForTests(provider_); 78 dispatcher_->SetProviderForTests(provider_);
76 } 79 }
77 80
78 int routing_id() const {
79 // We return a fake routing_id() in the context of this test.
80 return 0;
81 }
82
83 // The dispatcher_ owns the provider_ but we still want to access it. 81 // The dispatcher_ owns the provider_ but we still want to access it.
84 MockScreenOrientationProvider* provider_; 82 MockScreenOrientationProvider* provider_;
85 scoped_ptr<ScreenOrientationDispatcherHost> dispatcher_; 83 scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
86 }; 84 };
87 85
88 class ScreenOrientationDispatcherHostWithSinkTest : 86 class ScreenOrientationDispatcherHostWithSinkTest :
89 public ScreenOrientationDispatcherHostTest { 87 public ScreenOrientationDispatcherHostTest {
90 protected: 88 protected:
91 virtual ScreenOrientationDispatcherHost* CreateDispatcher() OVERRIDE { 89 virtual ScreenOrientationDispatcherHost* CreateDispatcher() OVERRIDE {
92 return new ScreenOrientationDispatcherHostWithSink(&sink_); 90 return new ScreenOrientationDispatcherHostWithSink(&sink_);
93 } 91 }
94 92
95 const IPC::TestSink& sink() const { 93 const IPC::TestSink& sink() const {
(...skipping 22 matching lines...) Expand all
118 // Unfortunately, initializer list constructor for std::list is not yet 116 // Unfortunately, initializer list constructor for std::list is not yet
119 // something we can use. 117 // something we can use.
120 // Keep this in sync with |orientationsToTest|. 118 // Keep this in sync with |orientationsToTest|.
121 int orientationsToTestCount = 7; 119 int orientationsToTestCount = 7;
122 120
123 for (int i = 0; i < orientationsToTestCount; ++i) { 121 for (int i = 0; i < orientationsToTestCount; ++i) {
124 bool message_was_handled = false; 122 bool message_was_handled = false;
125 blink::WebScreenOrientationLockType orientation = orientationsToTest[i]; 123 blink::WebScreenOrientationLockType orientation = orientationsToTest[i];
126 124
127 message_was_handled = dispatcher_->OnMessageReceived( 125 message_was_handled = dispatcher_->OnMessageReceived(
128 ScreenOrientationHostMsg_LockRequest(routing_id(), orientation, 0), 126 ScreenOrientationHostMsg_LockRequest(orientation, 0));
129 NULL);
130 127
131 EXPECT_TRUE(message_was_handled); 128 EXPECT_TRUE(message_was_handled);
132 EXPECT_EQ(orientation, provider_->orientation()); 129 EXPECT_EQ(orientation, provider_->orientation());
133 } 130 }
134 } 131 }
135 132
136 // Test that when receiving an unlock message, it is correctly dispatched to the 133 // Test that when receiving an unlock message, it is correctly dispatched to the
137 // ScreenOrientationProvider. 134 // ScreenOrientationProvider.
138 TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) { 135 TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) {
139 bool message_was_handled = dispatcher_->OnMessageReceived( 136 bool message_was_handled = dispatcher_->OnMessageReceived(
140 ScreenOrientationHostMsg_Unlock(routing_id()), NULL); 137 ScreenOrientationHostMsg_Unlock());
141 138
142 EXPECT_TRUE(message_was_handled); 139 EXPECT_TRUE(message_was_handled);
143 EXPECT_TRUE(provider_->unlock_called()); 140 EXPECT_TRUE(provider_->unlock_called());
144 } 141 }
145 142
146 // Test that when there is no provider, a LockRequest fails with the appropriate 143 // Test that when there is no provider, a LockRequest fails with the appropriate
147 // ErrorType. 144 // ErrorType.
148 TEST_F(ScreenOrientationDispatcherHostWithSinkTest, NoProvider_LockError) { 145 TEST_F(ScreenOrientationDispatcherHostWithSinkTest, NoProvider_LockError) {
149 dispatcher_->SetProviderForTests(NULL); 146 dispatcher_->SetProviderForTests(NULL);
150 147
151 const int request_id = 3; 148 const int request_id = 3;
152 dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest( 149 dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest(
153 routing_id(), 150 blink::WebScreenOrientationLockPortraitPrimary, request_id));
154 blink::WebScreenOrientationLockPortraitPrimary,
155 request_id), NULL);
156 151
157 EXPECT_EQ(1u, sink().message_count()); 152 EXPECT_EQ(1u, sink().message_count());
158 153
159 const IPC::Message* msg = sink().GetFirstMessageMatching( 154 const IPC::Message* msg = sink().GetFirstMessageMatching(
160 ScreenOrientationMsg_LockError::ID); 155 ScreenOrientationMsg_LockError::ID);
161 EXPECT_TRUE(msg != NULL); 156 EXPECT_TRUE(msg != NULL);
162 157
163 Tuple2<int, blink::WebLockOrientationCallback::ErrorType> params; 158 Tuple2<int, blink::WebLockOrientationCallback::ErrorType> params;
164 ScreenOrientationMsg_LockError::Read(msg, &params); 159 ScreenOrientationMsg_LockError::Read(msg, &params);
165 EXPECT_EQ(request_id, params.a); 160 EXPECT_EQ(request_id, params.a);
166 EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeNotAvailable, params.b); 161 EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeNotAvailable, params.b);
167 } 162 }
168 163
169 // Test that when there is a provider, we always send a success response back to 164 // Test that when there is a provider, we always send a success response back to
170 // the renderer. 165 // the renderer.
171 // TODO(mlamouri): we currently do not test the content of the message because 166 // TODO(mlamouri): we currently do not test the content of the message because
172 // it currently contains dummy values. 167 // it currently contains dummy values.
173 TEST_F(ScreenOrientationDispatcherHostWithSinkTest, WithProvider_LockSuccess) { 168 TEST_F(ScreenOrientationDispatcherHostWithSinkTest, WithProvider_LockSuccess) {
174 const int request_id = 42; 169 const int request_id = 42;
175 dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest( 170 dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest(
176 routing_id(), 171 blink::WebScreenOrientationLockPortraitPrimary, request_id));
177 blink::WebScreenOrientationLockPortraitPrimary,
178 request_id), NULL);
179 172
180 EXPECT_EQ(1u, sink().message_count()); 173 EXPECT_EQ(1u, sink().message_count());
181 174
182 const IPC::Message* msg = sink().GetFirstMessageMatching( 175 const IPC::Message* msg = sink().GetFirstMessageMatching(
183 ScreenOrientationMsg_LockSuccess::ID); 176 ScreenOrientationMsg_LockSuccess::ID);
184 EXPECT_TRUE(msg != NULL); 177 EXPECT_TRUE(msg != NULL);
185 178
186 Tuple3<int, unsigned, blink::WebScreenOrientationType> params; 179 Tuple3<int, unsigned, blink::WebScreenOrientationType> params;
187 ScreenOrientationMsg_LockSuccess::Read(msg, &params); 180 ScreenOrientationMsg_LockSuccess::Read(msg, &params);
188 EXPECT_EQ(request_id, params.a); 181 EXPECT_EQ(request_id, params.a);
189 } 182 }
190 183
191 } // namespace content 184 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698