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

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: Tests 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/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 (c) 2012 The Chromium Authors. All rights reserved.
flackr 2014/10/30 18:11:21 s/Copyright (c) 2012/Copyright 2014
jonross 2014/10/30 18:23:54 Oops
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 test::AshTestBase::SetUp();
97 screen_orientation_delegate_ =
98 Shell::GetInstance()->screen_orientation_delegate();
99 }
100
101 // Tests that a content::WebContents can lock rotation.
102 TEST_F(ScreenOrientationDelegateTest, LockOrientation) {
103 scoped_ptr<content::WebContents> content(CreateWebContents());
104 ASSERT_NE(nullptr, content->GetNativeView());
105 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
106 ASSERT_FALSE(RotationLocked());
107
108 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
109 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
110 EXPECT_TRUE(RotationLocked());
111 }
112
113 // Tests that a content::WebContents can unlock rotation.
114 TEST_F(ScreenOrientationDelegateTest, Unlock) {
115 scoped_ptr<content::WebContents> content(CreateWebContents());
116 ASSERT_NE(nullptr, content->GetNativeView());
117 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
118 ASSERT_FALSE(RotationLocked());
119
120 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
121 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
122 EXPECT_TRUE(RotationLocked());
123
124 delegate()->Unlock(content.get());
125 EXPECT_FALSE(RotationLocked());
126 }
127
128 // Tests that a content::WebContents is able to change the orientation of the
129 // display after having locked rotation.
130 TEST_F(ScreenOrientationDelegateTest, OrientationChanges) {
131 scoped_ptr<content::WebContents> content(CreateWebContents());
132 ASSERT_NE(nullptr, content->GetNativeView());
133 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
134 ASSERT_FALSE(RotationLocked());
135
136 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
137 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
138 EXPECT_TRUE(RotationLocked());
139
140 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
141 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
142 }
143
144 // Tests that a user initiated rotation lock supercedes requests from a
145 // content::WebContents.
146 TEST_F(ScreenOrientationDelegateTest, OrientationChangeRejectedByUserLock) {
147 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true);
148
149 scoped_ptr<content::WebContents> content(CreateWebContents());
150 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
151 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
152 }
153
154 // Tests that a user initiated rotation lock cannot be unlocked by a
155 // content::WebContents.
156 TEST_F(ScreenOrientationDelegateTest, UserLockRejectsUnlock) {
157 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true);
158
159 scoped_ptr<content::WebContents> content(CreateWebContents());
160 delegate()->Unlock(content.get());
161 EXPECT_TRUE(RotationLocked());
162 }
163
164 // Tests that orientation can only be set by the first content::WebContents that
165 // has set a rotation lock.
166 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotChangeOrientation) {
167 scoped_ptr<content::WebContents> content1(CreateWebContents());
168 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
169 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
170
171 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
flackr 2014/10/30 18:11:21 EXPECT_TRUE?
jonross 2014/10/30 18:23:54 Done.
172 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
flackr 2014/10/30 18:11:21 EXPECT_FALSE?
jonross 2014/10/30 18:23:54 Done.
173 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
174 }
175
176 // Tests that only the content::WebContents that set a rotation lock can perform
177 // an unlock.
178 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotUnlock) {
179 scoped_ptr<content::WebContents> content1(CreateWebContents());
180 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
181 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
182
183 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
184 delegate()->Unlock(content2.get());
185 EXPECT_TRUE(RotationLocked());
186 }
187
188 // Tests that alternate content::WebContents can set a rotation lock after a
189 // preexisting lock has been released.
190 TEST_F(ScreenOrientationDelegateTest, AfterUnlockSecondContentCanLock) {
191 scoped_ptr<content::WebContents> content1(CreateWebContents());
192 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
193 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
194
195 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
196 delegate()->Unlock(content1.get());
197 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
198 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
199 EXPECT_TRUE(RotationLocked());
200 }
201
flackr 2014/10/30 18:11:21 Nice tests!
202 } // namespace ash
OLDNEW
« no previous file with comments | « ash/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