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

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 compilation issue 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 "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
8 #include "content/browser/screen_orientation/screen_orientation_provider.h"
9 #include "content/common/screen_orientation_messages.h"
10 #include "content/public/test/test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace content {
14
15 class MockScreenOrientationProvider : public ScreenOrientationProvider {
16 public:
17 MockScreenOrientationProvider() : orientations_(0), unlock_called_(false) {}
18
19 virtual void LockOrientation(blink::WebScreenOrientations orientations)
20 OVERRIDE {
21 orientations_ = orientations;
22
23 }
24
25 virtual void UnlockOrientation() OVERRIDE {
26 unlock_called_ = true;
27 }
28
29 blink::WebScreenOrientations orientations() const {
30 return orientations_;
31 }
32
33 bool unlock_called() const {
34 return unlock_called_;
35 }
36
37 virtual ~MockScreenOrientationProvider() {}
38
39 private:
40 blink::WebScreenOrientations orientations_;
41 bool unlock_called_;
42
43 DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
44 };
45
46 class ScreenOrientationDispatcherHostTest : public testing::Test {
47 protected:
48 virtual void SetUp() OVERRIDE {
49 provider_ = new MockScreenOrientationProvider();
50
51 dispatcher_ = new ScreenOrientationDispatcherHost();
52 dispatcher_->SetProviderForTests(provider_);
53 }
54
55 // The dispatcher_ owns the provider_ but we still want to access it.
56 MockScreenOrientationProvider* provider_;
57 scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
58 };
59
60 // Test that a NULL provider is correctly handled.
61 TEST_F(ScreenOrientationDispatcherHostTest, NullProvider) {
62 dispatcher_->SetProviderForTests(NULL);
63
64 bool message_was_ok = false;
65 bool message_was_handled = dispatcher_->OnMessageReceived(
66 ScreenOrientationHostMsg_Lock(blink::WebScreenOrientationPortraitPrimary),
67 &message_was_ok);
68
69 EXPECT_TRUE(message_was_ok);
70 EXPECT_TRUE(message_was_handled);
71 }
72
73 // Test that when receiving a lock message, it is correctly dispatched to the
74 // ScreenOrientationProvider.
75 TEST_F(ScreenOrientationDispatcherHostTest, ProviderLock) {
76 // If we change this array, update |orientationsToTestCount| below.
77 blink::WebScreenOrientations orientationsToTest[] = {
78 // The basic types.
79 blink::WebScreenOrientationPortraitPrimary,
80 blink::WebScreenOrientationPortraitSecondary,
81 blink::WebScreenOrientationLandscapePrimary,
82 blink::WebScreenOrientationLandscapeSecondary,
83 // Some unions.
84 blink::WebScreenOrientationLandscapePrimary |
85 blink::WebScreenOrientationPortraitPrimary,
86 blink::WebScreenOrientationLandscapePrimary |
87 blink::WebScreenOrientationPortraitSecondary,
88 blink::WebScreenOrientationPortraitPrimary |
89 blink::WebScreenOrientationPortraitSecondary |
90 blink::WebScreenOrientationLandscapePrimary |
91 blink::WebScreenOrientationLandscapeSecondary,
92 // Garbage values.
93 0,
94 100,
95 42
96 };
97
98 // Unfortunately, initializer list constructor for std::list is not yet
99 // something we can use.
100 // Keep this in sync with |orientationsToTest|.
101 int orientationsToTestCount = 10;
102
103 for (int i = 0; i < orientationsToTestCount; ++i) {
104 bool message_was_ok = false;
105 bool message_was_handled = false;
106 blink::WebScreenOrientations orientations = orientationsToTest[i];
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