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

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

Issue 177793003: Chromium plumbing for Screen Orientation API lock/unlock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chromium_plumbing_screen_orientation
Patch Set: fix IPC messages names Created 6 years, 10 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 <list>
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
10 #include "content/browser/screen_orientation/screen_orientation_provider.h"
11 #include "content/common/screen_orientation_messages.h"
12 #include "content/public/test/test_utils.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace content {
16
17 class MockScreenOrientationProvider : public ScreenOrientationProvider {
18 public:
19 MockScreenOrientationProvider()
20 : orientations_(0) ,
21 unlock_called_(false)
22 {}
jochen (gone - plz use gerrit) 2014/02/25 16:23:06 please clang-format your code
mlamouri (slow - plz ping) 2014/02/28 11:53:30 I did some changes based on clang-format.
23
24 virtual void LockOrientation(
25 blink::WebScreenOrientations orientations) OVERRIDE {
26 orientations_ = orientations;
27
28 }
29
30 virtual void UnlockOrientation() OVERRIDE {
31 unlock_called_ = true;
32 }
33
34 blink::WebScreenOrientations orientations() const {
35 return orientations_;
36 }
37
38 bool unlock_called() const {
39 return unlock_called_;
40 }
41
42 virtual ~MockScreenOrientationProvider() {}
43
44 private:
45 blink::WebScreenOrientations orientations_;
46 bool unlock_called_;
47
48 DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
49 };
50
51 class ScreenOrientationDispatcherHostTest : public testing::Test {
52 protected:
53 virtual void SetUp() OVERRIDE {
54 provider_ = new MockScreenOrientationProvider();
55
56 dispatcher_ = new ScreenOrientationDispatcherHost();
57 dispatcher_->SetProviderForTests(provider_);
58 }
59
60 // The dispatcher_ owns the provider_ but we still want to access it.
61 MockScreenOrientationProvider* provider_;
62 scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
63 };
64
65 // Test that a NULL provider is correctly handled.
66 TEST_F(ScreenOrientationDispatcherHostTest, NullProvider) {
67 dispatcher_->SetProviderForTests(NULL);
68
69 bool message_was_ok = false;
70 bool message_was_handled = dispatcher_->OnMessageReceived(
71 ScreenOrientationHostMsg_Lock(blink::WebScreenOrientationPortraitPrimary),
72 &message_was_ok);
73
74 EXPECT_TRUE(message_was_ok);
75 EXPECT_TRUE(message_was_handled);
76 }
77
78 // Test that when receiving a lock message, it is correctly dispatched to the
79 // ScreenOrientationProvider.
80 TEST_F(ScreenOrientationDispatcherHostTest, ProviderLock) {
81 std::list<blink::WebScreenOrientations> orientationsToTest = {
82 // The basic types.
83 blink::WebScreenOrientationPortraitPrimary,
84 blink::WebScreenOrientationPortraitSecondary,
85 blink::WebScreenOrientationLandscapePrimary,
86 blink::WebScreenOrientationLandscapeSecondary,
87 // Some unions.
88 blink::WebScreenOrientationLandscapePrimary |
89 blink::WebScreenOrientationPortraitPrimary,
90 blink::WebScreenOrientationLandscapePrimary |
91 blink::WebScreenOrientationPortraitSecondary,
92 blink::WebScreenOrientationPortraitPrimary |
93 blink::WebScreenOrientationPortraitSecondary |
94 blink::WebScreenOrientationLandscapePrimary |
95 blink::WebScreenOrientationLandscapeSecondary,
96 // Garbage values.
97 0,
98 100,
99 42
100 };
101
102 for (std::list<blink::WebScreenOrientations>::const_iterator it =
103 orientationsToTest.begin(); it != orientationsToTest.end(); ++it) {
104 bool message_was_ok = false;
105 bool message_was_handled = false;
106 blink::WebScreenOrientations orientations = *it;
107
108 message_was_handled = dispatcher_->OnMessageReceived(
109 ScreenOrientationHostMsg_Lock(orientations), &message_was_ok);
110
111 EXPECT_TRUE(message_was_ok);
112 EXPECT_TRUE(message_was_handled);
113 EXPECT_EQ(orientations, provider_->orientations());
114 }
115 }
116
117 // Test that when receiving an unlock message, it is correctly dispatched to the
118 // ScreenOrientationProvider.
119 TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) {
120 bool message_was_ok = false;
121 bool message_was_handled = dispatcher_->OnMessageReceived(
122 ScreenOrientationHostMsg_Unlock(), &message_was_ok);
123
124 EXPECT_TRUE(message_was_ok);
125 EXPECT_TRUE(message_was_handled);
126 EXPECT_TRUE(provider_->unlock_called());
127 }
128
129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698