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

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

Issue 723633003: Reland ScreenOrientationDelegate on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ChromeOS build error 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
« no previous file with comments | « ash/content/display/screen_orientation_delegate_chromeos.cc ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/ash_switches.h"
6 #include "ash/content/display/screen_orientation_delegate_chromeos.h"
7 #include "ash/display/display_info.h"
8 #include "ash/display/display_manager.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 cannot be unlocked by a
147 // content::WebContents.
148 TEST_F(ScreenOrientationDelegateTest, UserLockRejectsUnlock) {
149 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true);
150
151 scoped_ptr<content::WebContents> content(CreateWebContents());
152 delegate()->Unlock(content.get());
153 EXPECT_TRUE(RotationLocked());
154 }
155
156 // Tests that orientation can only be set by the first content::WebContents that
157 // has set a rotation lock.
158 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotChangeOrientation) {
159 scoped_ptr<content::WebContents> content1(CreateWebContents());
160 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
161 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
162
163 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
164 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
165 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
166 }
167
168 // Tests that only the content::WebContents that set a rotation lock can perform
169 // an unlock.
170 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotUnlock) {
171 scoped_ptr<content::WebContents> content1(CreateWebContents());
172 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
173 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
174
175 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
176 delegate()->Unlock(content2.get());
177 EXPECT_TRUE(RotationLocked());
178 }
179
180 // Tests that alternate content::WebContents can set a rotation lock after a
181 // preexisting lock has been released.
182 TEST_F(ScreenOrientationDelegateTest, AfterUnlockSecondContentCanLock) {
183 scoped_ptr<content::WebContents> content1(CreateWebContents());
184 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
185 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
186
187 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
188 delegate()->Unlock(content1.get());
189 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
190 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
191 EXPECT_TRUE(RotationLocked());
192 }
193
194 } // namespace ash
OLDNEW
« no previous file with comments | « ash/content/display/screen_orientation_delegate_chromeos.cc ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698