OLD | NEW |
---|---|
(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() { } | |
jochen (gone - plz use gerrit)
2014/02/24 14:08:26
no space inside {}
mlamouri (slow - plz ping)
2014/02/24 14:20:21
Done.
| |
22 | |
23 virtual void didChangeScreenOrientation(blink::WebScreenOrientation) OVERRIDE; | |
24 | |
25 bool did_change_screen_orientation_; | |
jochen (gone - plz use gerrit)
2014/02/24 14:08:26
members should be private. please use getters to a
mlamouri (slow - plz ping)
2014/02/24 14:20:21
Done.
| |
26 blink::WebScreenOrientation screen_orientation_; | |
27 }; | |
jochen (gone - plz use gerrit)
2014/02/24 14:08:26
disallow copy/assign
mlamouri (slow - plz ping)
2014/02/24 14:20:21
Done.
| |
28 | |
29 MockScreenOrientationListener::MockScreenOrientationListener() | |
30 : did_change_screen_orientation_(false), | |
31 screen_orientation_(blink::WebScreenOrientationPortraitPrimary) { | |
32 } | |
33 | |
34 void MockScreenOrientationListener::didChangeScreenOrientation( | |
35 blink::WebScreenOrientation orientation) { | |
36 did_change_screen_orientation_ = true; | |
37 screen_orientation_ = orientation; | |
38 } | |
39 | |
40 class ScreenOrientationDispatcherTest : public testing::Test { | |
41 protected: | |
42 virtual void SetUp() OVERRIDE { | |
43 render_thread_.reset(new MockRenderThread); | |
44 listener_.reset(new MockScreenOrientationListener); | |
45 dispatcher_.reset(new ScreenOrientationDispatcher(render_thread_.get())); | |
46 dispatcher_->setListener(listener_.get()); | |
47 } | |
48 | |
49 scoped_ptr<MockRenderThread> render_thread_; | |
50 scoped_ptr<MockScreenOrientationListener> listener_; | |
51 scoped_ptr<ScreenOrientationDispatcher> dispatcher_; | |
52 }; | |
53 | |
54 TEST_F(ScreenOrientationDispatcherTest, ListensToMessages) { | |
55 EXPECT_TRUE(render_thread_->observers().HasObserver(dispatcher_.get())); | |
56 | |
57 render_thread_->OnControlMessageReceived( | |
58 ScreenOrientationMsg_OrientationChange( | |
59 blink::WebScreenOrientationPortraitPrimary)); | |
60 | |
61 EXPECT_TRUE(listener_->did_change_screen_orientation_); | |
62 } | |
63 | |
64 TEST_F(ScreenOrientationDispatcherTest, NullListener) { | |
65 dispatcher_->setListener(NULL); | |
66 | |
67 render_thread_->OnControlMessageReceived( | |
68 ScreenOrientationMsg_OrientationChange( | |
69 blink::WebScreenOrientationPortraitPrimary)); | |
70 | |
71 EXPECT_FALSE(listener_->did_change_screen_orientation_); | |
72 } | |
73 | |
74 TEST_F(ScreenOrientationDispatcherTest, ValidValues) { | |
75 render_thread_->OnControlMessageReceived( | |
76 ScreenOrientationMsg_OrientationChange( | |
77 blink::WebScreenOrientationPortraitPrimary)); | |
78 EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary, | |
79 listener_->screen_orientation_); | |
80 | |
81 render_thread_->OnControlMessageReceived( | |
82 ScreenOrientationMsg_OrientationChange( | |
83 blink::WebScreenOrientationLandscapePrimary)); | |
84 EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary, | |
85 listener_->screen_orientation_); | |
86 | |
87 render_thread_->OnControlMessageReceived( | |
88 ScreenOrientationMsg_OrientationChange( | |
89 blink::WebScreenOrientationPortraitSecondary)); | |
90 EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary, | |
91 listener_->screen_orientation_); | |
92 | |
93 render_thread_->OnControlMessageReceived( | |
94 ScreenOrientationMsg_OrientationChange( | |
95 blink::WebScreenOrientationLandscapeSecondary)); | |
96 EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary, | |
97 listener_->screen_orientation_); | |
98 } | |
99 | |
100 } // namespace content | |
OLD | NEW |