[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / browser / screen_orientation / screen_orientation_browsertest.cc
blob0e0a0851000a6191227c6c318cc4ddc1ffd28e7c
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.
5 #include <stdlib.h>
7 #include "base/command_line.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/common/view_messages.h"
10 #include "content/public/browser/render_widget_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test.h"
16 #include "content/public/test/content_browser_test_utils.h"
17 #include "content/public/test/test_navigation_observer.h"
18 #include "content/public/test/test_utils.h"
19 #include "content/shell/browser/shell.h"
20 #include "content/shell/common/shell_switches.h"
21 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
22 #include "ui/compositor/compositor_switches.h"
24 #if defined(OS_WIN)
25 #include "base/win/windows_version.h"
26 #endif // OS_WIN
28 namespace content {
30 class ScreenOrientationBrowserTest : public ContentBrowserTest {
31 public:
32 ScreenOrientationBrowserTest() {
35 protected:
36 void SendFakeScreenOrientation(unsigned angle, const std::string& strType) {
37 RenderWidgetHost* rwh = shell()->web_contents()->GetRenderWidgetHostView()
38 ->GetRenderWidgetHost();
39 blink::WebScreenInfo screen_info;
40 rwh->GetWebScreenInfo(&screen_info);
41 screen_info.orientationAngle = angle;
43 blink::WebScreenOrientationType type = blink::WebScreenOrientationUndefined;
44 if (strType == "portrait-primary") {
45 type = blink::WebScreenOrientationPortraitPrimary;
46 } else if (strType == "portrait-secondary") {
47 type = blink::WebScreenOrientationPortraitSecondary;
48 } else if (strType == "landscape-primary") {
49 type = blink::WebScreenOrientationLandscapePrimary;
50 } else if (strType == "landscape-secondary") {
51 type = blink::WebScreenOrientationLandscapeSecondary;
53 ASSERT_NE(blink::WebScreenOrientationUndefined, type);
54 screen_info.orientationType = type;
56 ViewMsg_Resize_Params params;
57 params.screen_info = screen_info;
58 params.new_size = gfx::Size(0, 0);
59 params.physical_backing_size = gfx::Size(300, 300);
60 params.top_controls_height = 0.f;
61 params.top_controls_shrink_blink_size = false;
62 params.resizer_rect = gfx::Rect();
63 params.is_fullscreen = false;
64 rwh->Send(new ViewMsg_Resize(rwh->GetRoutingID(), params));
67 int GetOrientationAngle() {
68 int angle;
69 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
70 "screen.orientation.angle")->GetAsInteger(&angle);
71 return angle;
74 std::string GetOrientationType() {
75 std::string type;
76 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
77 "screen.orientation.type")->GetAsString(&type);
78 return type;
81 bool ScreenOrientationSupported() {
82 bool support;
83 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
84 "'orientation' in screen")->GetAsBoolean(&support);
85 return support;
88 bool WindowOrientationSupported() {
89 bool support;
90 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
91 "'orientation' in window")->GetAsBoolean(&support);
92 return support;
95 int GetWindowOrientationAngle() {
96 int angle;
97 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
98 "window.orientation")->GetAsInteger(&angle);
99 return angle;
102 private:
103 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest);
106 // This test doesn't work on MacOS X but the reason is mostly because it is not
107 // used Aura. It could be set as !defined(OS_MACOSX) but the rule below will
108 // actually support MacOS X if and when it switches to Aura.
109 #if defined(USE_AURA) || defined(OS_ANDROID)
110 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, ScreenOrientationChange) {
111 std::string types[] = { "portrait-primary",
112 "portrait-secondary",
113 "landscape-primary",
114 "landscape-secondary" };
115 GURL test_url = GetTestUrl("screen_orientation",
116 "screen_orientation_screenorientationchange.html");
118 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
119 shell()->LoadURL(test_url);
120 navigation_observer.Wait();
121 #if USE_AURA
122 WaitForResizeComplete(shell()->web_contents());
123 #endif // USE_AURA
125 #if defined(OS_WIN)
126 // Screen Orientation is currently disabled on Windows 8.
127 // This test will break, requiring an update when the API will be enabled.
128 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8) {
129 EXPECT_EQ(false, ScreenOrientationSupported());
130 return;
132 #endif // defined(OS_WIN)
134 int angle = GetOrientationAngle();
136 for (int i = 0; i < 4; ++i) {
137 angle = (angle + 90) % 360;
138 SendFakeScreenOrientation(angle, types[i]);
140 TestNavigationObserver navigation_observer(shell()->web_contents());
141 navigation_observer.Wait();
142 EXPECT_EQ(angle, GetOrientationAngle());
143 EXPECT_EQ(types[i], GetOrientationType());
146 #endif // defined(USE_AURA) || defined(OS_ANDROID)
148 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, WindowOrientationChange) {
149 GURL test_url = GetTestUrl("screen_orientation",
150 "screen_orientation_windoworientationchange.html");
152 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
153 shell()->LoadURL(test_url);
154 navigation_observer.Wait();
155 #if USE_AURA
156 WaitForResizeComplete(shell()->web_contents());
157 #endif // USE_AURA
159 if (!WindowOrientationSupported())
160 return;
162 int angle = GetWindowOrientationAngle();
164 for (int i = 0; i < 4; ++i) {
165 angle = (angle + 90) % 360;
166 SendFakeScreenOrientation(angle, "portrait-primary");
168 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
169 navigation_observer.Wait();
170 EXPECT_EQ(angle == 270 ? -90 : angle, GetWindowOrientationAngle());
174 // LockSmoke test seems to have become flaky on all non-ChromeOS platforms.
175 // The cause is unfortunately unknown. See https://crbug.com/448876
176 // Chromium Android does not support fullscreen
177 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, DISABLED_LockSmoke) {
178 GURL test_url = GetTestUrl("screen_orientation",
179 "screen_orientation_lock_smoke.html");
181 TestNavigationObserver navigation_observer(shell()->web_contents(), 2);
182 shell()->LoadURL(test_url);
184 #if defined(OS_WIN)
185 // Screen Orientation is currently disabled on Windows 8.
186 // This test will break, requiring an update when the API will be enabled.
187 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8) {
188 EXPECT_EQ(false, ScreenOrientationSupported());
189 return;
191 #endif // defined(OS_WIN)
193 navigation_observer.Wait();
194 #if USE_AURA
195 WaitForResizeComplete(shell()->web_contents());
196 #endif // USE_AURA
198 std::string expected =
199 #if defined(OS_ANDROID)
200 "SecurityError"; // WebContents need to be fullscreen.
201 #else
202 "NotSupportedError"; // Locking isn't supported.
203 #endif
205 EXPECT_EQ(expected, shell()->web_contents()->GetLastCommittedURL().ref());
208 // Check that using screen orientation after a frame is detached doesn't crash
209 // the renderer process.
210 // This could be a LayoutTest if they were not using a mock screen orientation
211 // controller.
212 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, CrashTest_UseAfterDetach) {
213 GURL test_url = GetTestUrl("screen_orientation",
214 "screen_orientation_use_after_detach.html");
216 TestNavigationObserver navigation_observer(shell()->web_contents(), 2);
217 shell()->LoadURL(test_url);
219 #if defined(OS_WIN)
220 // Screen Orientation is currently disabled on Windows 8.
221 // When implemented, this test will break, requiring an update.
222 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8) {
223 EXPECT_EQ(false, ScreenOrientationSupported());
224 return;
226 #endif // defined(OS_WIN)
228 navigation_observer.Wait();
230 // This is a success if the renderer process did not crash, thus, we end up
231 // here.
234 } // namespace content