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

Side by Side Diff: content/renderer/screen_orientation/screen_orientation_dispatcher_unittest.cc

Issue 176963016: Chromium plumbing for Screen Orientation API orientationchange events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "screen_orientation_dispatcher.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "content/common/screen_orientation_messages.h"
10 #include "content/public/test/mock_render_thread.h"
11 #include "content/public/test/test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
14
15 namespace content {
16
17 class MockScreenOrientationListener :
18 public blink::WebScreenOrientationListener {
19 public:
20 MockScreenOrientationListener();
21 virtual ~MockScreenOrientationListener() {}
22
23 virtual void didChangeScreenOrientation(blink::WebScreenOrientation) OVERRIDE;
24
25 bool did_change_screen_orientation() const {
26 return did_change_screen_orientation_;
27 }
28
29 blink::WebScreenOrientation screen_orientation() const {
30 return screen_orientation_;
31 }
32
33 private:
34 bool did_change_screen_orientation_;
35 blink::WebScreenOrientation screen_orientation_;
36
37 DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationListener);
38 };
39
40 MockScreenOrientationListener::MockScreenOrientationListener()
41 : did_change_screen_orientation_(false),
42 screen_orientation_(blink::WebScreenOrientationPortraitPrimary) {
43 }
44
45 void MockScreenOrientationListener::didChangeScreenOrientation(
46 blink::WebScreenOrientation orientation) {
47 did_change_screen_orientation_ = true;
48 screen_orientation_ = orientation;
49 }
50
51 class ScreenOrientationDispatcherTest : public testing::Test {
52 protected:
53 virtual void SetUp() OVERRIDE {
54 render_thread_.reset(new MockRenderThread);
55 listener_.reset(new MockScreenOrientationListener);
56 dispatcher_.reset(new ScreenOrientationDispatcher(render_thread_.get()));
57 dispatcher_->setListener(listener_.get());
58 }
59
60 scoped_ptr<MockRenderThread> render_thread_;
61 scoped_ptr<MockScreenOrientationListener> listener_;
62 scoped_ptr<ScreenOrientationDispatcher> dispatcher_;
63 };
64
65 TEST_F(ScreenOrientationDispatcherTest, ListensToMessages) {
66 EXPECT_TRUE(render_thread_->observers().HasObserver(dispatcher_.get()));
67
68 render_thread_->OnControlMessageReceived(
69 ScreenOrientationMsg_OrientationChange(
70 blink::WebScreenOrientationPortraitPrimary));
71
72 EXPECT_TRUE(listener_->did_change_screen_orientation());
73 }
74
75 TEST_F(ScreenOrientationDispatcherTest, NullListener) {
76 dispatcher_->setListener(NULL);
77
78 render_thread_->OnControlMessageReceived(
79 ScreenOrientationMsg_OrientationChange(
80 blink::WebScreenOrientationPortraitPrimary));
81
82 EXPECT_FALSE(listener_->did_change_screen_orientation());
83 }
84
85 TEST_F(ScreenOrientationDispatcherTest, ValidValues) {
86 render_thread_->OnControlMessageReceived(
87 ScreenOrientationMsg_OrientationChange(
88 blink::WebScreenOrientationPortraitPrimary));
89 EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary,
90 listener_->screen_orientation());
91
92 render_thread_->OnControlMessageReceived(
93 ScreenOrientationMsg_OrientationChange(
94 blink::WebScreenOrientationLandscapePrimary));
95 EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary,
96 listener_->screen_orientation());
97
98 render_thread_->OnControlMessageReceived(
99 ScreenOrientationMsg_OrientationChange(
100 blink::WebScreenOrientationPortraitSecondary));
101 EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary,
102 listener_->screen_orientation());
103
104 render_thread_->OnControlMessageReceived(
105 ScreenOrientationMsg_OrientationChange(
106 blink::WebScreenOrientationLandscapeSecondary));
107 EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary,
108 listener_->screen_orientation());
109 }
110
111 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/screen_orientation/screen_orientation_dispatcher.cc ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698