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

Side by Side Diff: ash/display/screen_orientation_delegate_chromeos_unittest.cc

Issue 648733003: Implement ScreenOrientationDelegate on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shift experimental feature to ash Created 6 years, 1 month 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 (c) 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 "ash/ash_switches.h"
6 #include "ash/display/display_info.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/display/screen_orientation_delegate_chromeos.h"
9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/ash_test_helper.h"
12 #include "ash/test/test_shell_delegate.h"
13 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
14 #include "base/command_line.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_browser_context.h"
19 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
20 #include "ui/gfx/display.h"
21 #include "ui/views/test/webview_test_helper.h"
22 #include "ui/views/view.h"
23 #include "ui/views/views_delegate.h"
24
25 namespace ash {
26
27 namespace {
28
29 gfx::Display::Rotation Rotation() {
30 return Shell::GetInstance()
31 ->display_manager()
32 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
33 .rotation();
34 }
35
36 bool RotationLocked() {
37 return Shell::GetInstance()->maximize_mode_controller()->rotation_locked();
38 }
39
40 } // namespace
41
42 class ScreenOrientationDelegateTest : public test::AshTestBase {
43 public:
44 ScreenOrientationDelegateTest();
45 virtual ~ScreenOrientationDelegateTest();
46
47 ScreenOrientationDelegate* delegate() { return screen_orientation_delegate_; }
48
49 // Creates and initializes and empty content::WebContents that is backed by a
50 // content::BrowserContext and that has an aura::Window.
51 content::WebContents* CreateWebContents();
52
53 // Creates a secondary content::WebContents, with a separate
54 // content::BrowserContext.
55 content::WebContents* CreateSecondaryWebContents();
56
57 // test::AshTestBase:
58 void SetUp() override;
59
60 private:
61 ScreenOrientationDelegate* screen_orientation_delegate_;
62
63 // Optional content::BrowserContext used for two window tests.
64 scoped_ptr<content::BrowserContext> secondary_browser_context_;
65
66 // Setups underlying content layer so that content::WebContents can be
67 // generated.
68 scoped_ptr<views::WebViewTestHelper> webview_test_helper_;
69
70 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegateTest);
71 };
72
73 ScreenOrientationDelegateTest::ScreenOrientationDelegateTest() {
74 webview_test_helper_.reset(new views::WebViewTestHelper());
75 }
76
77 ScreenOrientationDelegateTest::~ScreenOrientationDelegateTest() {
78 }
79
80 content::WebContents* ScreenOrientationDelegateTest::CreateWebContents() {
81 return views::ViewsDelegate::views_delegate->CreateWebContents(
82 ash_test_helper()->test_shell_delegate()->GetActiveBrowserContext(),
83 nullptr);
84 }
85
86 content::WebContents*
87 ScreenOrientationDelegateTest::CreateSecondaryWebContents() {
88 secondary_browser_context_.reset(new content::TestBrowserContext());
89 return views::ViewsDelegate::views_delegate->CreateWebContents(
90 secondary_browser_context_.get(), nullptr);
91 }
92
93 void ScreenOrientationDelegateTest::SetUp() {
94 base::CommandLine::ForCurrentProcess()->AppendSwitch(
95 switches::kAshUseFirstDisplayAsInternal);
96 base::CommandLine::ForCurrentProcess()->AppendSwitch(
97 switches::kAshEnableTouchViewTesting);
98 test::AshTestBase::SetUp();
99 screen_orientation_delegate_ =
100 Shell::GetInstance()->screen_orientation_delegate();
101 }
102
103 // Tests that a content::WebContents can lock rotation.
104 TEST_F(ScreenOrientationDelegateTest, LockOrientation) {
105 scoped_ptr<content::WebContents> content(CreateWebContents());
106 ASSERT_NE(nullptr, content->GetNativeView());
107 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
108 ASSERT_FALSE(RotationLocked());
109
110 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
111 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
112 EXPECT_TRUE(RotationLocked());
113 }
114
115 // Tests that a content::WebContents can unlock rotation.
116 TEST_F(ScreenOrientationDelegateTest, Unlock) {
117 scoped_ptr<content::WebContents> content(CreateWebContents());
118 ASSERT_NE(nullptr, content->GetNativeView());
119 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
120 ASSERT_FALSE(RotationLocked());
121
122 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
123 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
124 EXPECT_TRUE(RotationLocked());
125
126 delegate()->Unlock(content.get());
127 EXPECT_FALSE(RotationLocked());
128 }
129
130 // Tests that a content::WebContents is able to change the orientation of the
131 // display after having locked rotation.
132 TEST_F(ScreenOrientationDelegateTest, OrientationChanges) {
133 scoped_ptr<content::WebContents> content(CreateWebContents());
134 ASSERT_NE(nullptr, content->GetNativeView());
135 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
136 ASSERT_FALSE(RotationLocked());
137
138 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
139 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
140 EXPECT_TRUE(RotationLocked());
141
142 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
143 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
144 }
145
146 // Tests that a user initiated rotation lock supercedes requests from a
147 // content::WebContents.
148 TEST_F(ScreenOrientationDelegateTest, OrientationChangeRejectedByUserLock) {
149 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true);
150
151 scoped_ptr<content::WebContents> content(CreateWebContents());
152 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
153 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
154 }
155
156 // Tests that a user initiated rotation lock cannot be unlocked by a
157 // content::WebContents.
158 TEST_F(ScreenOrientationDelegateTest, UserLockRejectsUnlock) {
159 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true);
160
161 scoped_ptr<content::WebContents> content(CreateWebContents());
162 delegate()->Unlock(content.get());
163 EXPECT_TRUE(RotationLocked());
164 }
165
166 // Tests that orientation can only be set by the first content::WebContents that
167 // has set a rotation lock.
168 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotChangeOrientation) {
169 scoped_ptr<content::WebContents> content1(CreateWebContents());
170 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
171 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
172
173 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
174 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
175 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
176 }
177
178 // Tests that only the content::WebContents that set a rotation lock can perform
179 // an unlock.
180 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotUnlock) {
181 scoped_ptr<content::WebContents> content1(CreateWebContents());
182 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
183 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
184
185 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
186 delegate()->Unlock(content2.get());
187 EXPECT_TRUE(RotationLocked());
188 }
189
190 // Tests that alternate content::WebContents can set a rotation lock after a
191 // preexisting lock has been released.
192 TEST_F(ScreenOrientationDelegateTest, AfterUnlockSecondContentCanLock) {
193 scoped_ptr<content::WebContents> content1(CreateWebContents());
194 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
195 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
196
197 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
198 delegate()->Unlock(content1.get());
199 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
200 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
201 EXPECT_TRUE(RotationLocked());
202 }
203
204 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698