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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_browsertest.cc

Issue 2832093003: Implement screen orientation for out-of-process iframes. (Closed)
Patch Set: fix dcheck Created 3 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 12 #include "content/browser/renderer_host/render_widget_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/common/page_messages.h"
11 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_widget_host.h" 16 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/render_widget_host_view.h" 17 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
16 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
17 #include "content/public/test/content_browser_test.h" 21 #include "content/public/test/content_browser_test.h"
18 #include "content/public/test/content_browser_test_utils.h" 22 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/public/test/test_navigation_observer.h" 23 #include "content/public/test/test_navigation_observer.h"
20 #include "content/public/test/test_utils.h" 24 #include "content/public/test/test_utils.h"
21 #include "content/shell/browser/shell.h" 25 #include "content/shell/browser/shell.h"
22 #include "content/shell/common/shell_switches.h" 26 #include "content/shell/common/shell_switches.h"
27 #include "net/dns/mock_host_resolver.h"
23 #include "ui/compositor/compositor_switches.h" 28 #include "ui/compositor/compositor_switches.h"
29 #include "ui/display/screen.h"
24 30
25 namespace content { 31 namespace content {
26 32
27 class ScreenOrientationBrowserTest : public ContentBrowserTest { 33 class ScreenOrientationBrowserTest : public ContentBrowserTest {
28 public: 34 public:
29 ScreenOrientationBrowserTest() { 35 ScreenOrientationBrowserTest() {
30 } 36 }
31 37
38 WebContentsImpl* web_contents() {
39 return static_cast<WebContentsImpl*>(shell()->web_contents());
40 }
41
32 protected: 42 protected:
33 void SendFakeScreenOrientation(unsigned angle, const std::string& strType) { 43 void SendFakeScreenOrientation(unsigned angle, const std::string& strType) {
34 RenderWidgetHost* rwh = shell()->web_contents()->GetRenderWidgetHostView() 44 RenderWidgetHost* main_frame_rwh =
35 ->GetRenderWidgetHost(); 45 web_contents()->GetMainFrame()->GetRenderWidgetHost();
36 ScreenInfo screen_info; 46 ScreenInfo screen_info;
37 rwh->GetScreenInfo(&screen_info); 47 main_frame_rwh->GetScreenInfo(&screen_info);
38 screen_info.orientation_angle = angle; 48 screen_info.orientation_angle = angle;
39 49
40 ScreenOrientationValues type = SCREEN_ORIENTATION_VALUES_DEFAULT; 50 ScreenOrientationValues type = SCREEN_ORIENTATION_VALUES_DEFAULT;
41 if (strType == "portrait-primary") { 51 if (strType == "portrait-primary") {
42 type = SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY; 52 type = SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY;
43 } else if (strType == "portrait-secondary") { 53 } else if (strType == "portrait-secondary") {
44 type = SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY; 54 type = SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
45 } else if (strType == "landscape-primary") { 55 } else if (strType == "landscape-primary") {
46 type = SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; 56 type = SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
47 } else if (strType == "landscape-secondary") { 57 } else if (strType == "landscape-secondary") {
48 type = SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY; 58 type = SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
49 } 59 }
50 ASSERT_NE(SCREEN_ORIENTATION_VALUES_DEFAULT, type); 60 ASSERT_NE(SCREEN_ORIENTATION_VALUES_DEFAULT, type);
51 screen_info.orientation_type = type; 61 screen_info.orientation_type = type;
52 62
53 ResizeParams params; 63 ResizeParams params;
54 params.screen_info = screen_info; 64 params.screen_info = screen_info;
55 params.new_size = gfx::Size(0, 0); 65 params.new_size = gfx::Size(0, 0);
56 params.physical_backing_size = gfx::Size(300, 300); 66 params.physical_backing_size = gfx::Size(300, 300);
57 params.top_controls_height = 0.f; 67 params.top_controls_height = 0.f;
58 params.browser_controls_shrink_blink_size = false; 68 params.browser_controls_shrink_blink_size = false;
59 params.is_fullscreen_granted = false; 69 params.is_fullscreen_granted = false;
60 rwh->Send(new ViewMsg_Resize(rwh->GetRoutingID(), params)); 70
71 std::set<RenderWidgetHost*> rwhs;
72 for (RenderFrameHost* rfh : web_contents()->GetAllFrames()) {
73 if (rfh == web_contents()->GetMainFrame())
74 continue;
75
76 rwhs.insert(static_cast<RenderFrameHostImpl*>(rfh)
77 ->frame_tree_node()
78 ->render_manager()
79 ->GetRenderWidgetHostView()
80 ->GetRenderWidgetHost());
81 }
82
83 main_frame_rwh->Send(
84 new ViewMsg_Resize(main_frame_rwh->GetRoutingID(), params));
85 web_contents()->GetFrameTree()->root()->render_manager()->SendPageMessage(
86 new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info), nullptr);
87 for (auto* rwh : rwhs)
88 rwh->Send(new ViewMsg_Resize(rwh->GetRoutingID(), params));
nasko 2017/04/25 19:59:08 Do we actually iterate through RWHs in real code w
lfg 2017/04/25 20:08:18 Not exactly like this, the test is faking it. What
61 } 89 }
62 90
63 int GetOrientationAngle() { 91 int GetOrientationAngle() {
64 int angle; 92 int angle;
65 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), 93 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
66 "screen.orientation.angle")->GetAsInteger(&angle); 94 "screen.orientation.angle")->GetAsInteger(&angle);
67 return angle; 95 return angle;
68 } 96 }
69 97
70 std::string GetOrientationType() { 98 std::string GetOrientationType() {
(...skipping 21 matching lines...) Expand all
92 int angle; 120 int angle;
93 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), 121 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(),
94 "window.orientation")->GetAsInteger(&angle); 122 "window.orientation")->GetAsInteger(&angle);
95 return angle; 123 return angle;
96 } 124 }
97 125
98 private: 126 private:
99 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest); 127 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest);
100 }; 128 };
101 129
130 class ScreenOrientationOOPIFBrowserTest : public ScreenOrientationBrowserTest {
131 public:
132 ScreenOrientationOOPIFBrowserTest() {}
133
134 void SetUpCommandLine(base::CommandLine* command_line) override {
135 IsolateAllSitesForTesting(command_line);
136 }
137
138 void SetUpOnMainThread() override {
139 host_resolver()->AddRule("*", "127.0.0.1");
140 SetupCrossSiteRedirector(embedded_test_server());
141 ASSERT_TRUE(embedded_test_server()->Start());
142 }
143
144 private:
145 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationOOPIFBrowserTest);
146 };
147
102 // This test doesn't work on MacOS X but the reason is mostly because it is not 148 // This test doesn't work on MacOS X but the reason is mostly because it is not
103 // used Aura. It could be set as !defined(OS_MACOSX) but the rule below will 149 // used Aura. It could be set as !defined(OS_MACOSX) but the rule below will
104 // actually support MacOS X if and when it switches to Aura. 150 // actually support MacOS X if and when it switches to Aura.
105 #if defined(USE_AURA) || defined(OS_ANDROID) 151 #if defined(USE_AURA) || defined(OS_ANDROID)
106 // Flaky on Chrome OS: http://crbug.com/468259 152 // Flaky on Chrome OS: http://crbug.com/468259
107 #if defined(OS_CHROMEOS) 153 #if defined(OS_CHROMEOS)
108 #define MAYBE_ScreenOrientationChange DISABLED_ScreenOrientationChange 154 #define MAYBE_ScreenOrientationChange DISABLED_ScreenOrientationChange
109 #else 155 #else
110 #define MAYBE_ScreenOrientationChange ScreenOrientationChange 156 #define MAYBE_ScreenOrientationChange ScreenOrientationChange
111 #endif 157 #endif
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ASSERT_TRUE(ExecuteScript(shell(), "run();")); 284 ASSERT_TRUE(ExecuteScript(shell(), "run();"));
239 285
240 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 286 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
241 navigation_observer.Wait(); 287 navigation_observer.Wait();
242 EXPECT_EQ("NotSupportedError", 288 EXPECT_EQ("NotSupportedError",
243 shell()->web_contents()->GetLastCommittedURL().ref()); 289 shell()->web_contents()->GetLastCommittedURL().ref());
244 } 290 }
245 } 291 }
246 #endif // defined(OS_ANDROID) 292 #endif // defined(OS_ANDROID)
247 293
294 IN_PROC_BROWSER_TEST_F(ScreenOrientationOOPIFBrowserTest, ScreenOrientation) {
295 GURL main_url(embedded_test_server()->GetURL(
296 "a.com", "/cross_site_iframe_factory.html?a(b)"));
297 EXPECT_TRUE(NavigateToURL(shell(), main_url));
298 #if USE_AURA || defined(OS_ANDROID)
299 WaitForResizeComplete(shell()->web_contents());
300 #endif // USE_AURA || defined(OS_ANDROID)
301
302 std::string types[] = {"portrait-primary", "portrait-secondary",
303 "landscape-primary", "landscape-secondary"};
304
305 int angle = GetOrientationAngle();
306
307 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
308 FrameTreeNode* child = root->child_at(0);
309 MainThreadFrameObserver root_observer(
310 root->current_frame_host()->GetRenderWidgetHost());
311 MainThreadFrameObserver child_observer(
312 child->current_frame_host()->GetRenderWidgetHost());
313 for (int i = 0; i < 4; ++i) {
314 angle = (angle + 90) % 360;
315 SendFakeScreenOrientation(angle, types[i]);
316
317 root_observer.Wait();
318 child_observer.Wait();
319
320 int orientation_angle;
321 std::string orientation_type;
322
323 EXPECT_TRUE(ExecuteScriptAndExtractInt(
324 root->current_frame_host(),
325 "window.domAutomationController.send(screen.orientation.angle)",
326 &orientation_angle));
327 EXPECT_EQ(angle, orientation_angle);
328 EXPECT_TRUE(ExecuteScriptAndExtractInt(
329 child->current_frame_host(),
330 "window.domAutomationController.send(screen.orientation.angle)",
331 &orientation_angle));
332 EXPECT_EQ(angle, orientation_angle);
333
334 EXPECT_TRUE(ExecuteScriptAndExtractString(
335 root->current_frame_host(),
336 "window.domAutomationController.send(screen.orientation.type)",
337 &orientation_type));
338 EXPECT_EQ(types[i], orientation_type);
339 EXPECT_TRUE(ExecuteScriptAndExtractString(
340 child->current_frame_host(),
341 "window.domAutomationController.send(screen.orientation.type)",
342 &orientation_type));
343 EXPECT_EQ(types[i], orientation_type);
344 }
345 }
346
248 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl.cc » ('j') | content/renderer/render_view_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698