OLD | NEW |
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 // This simulates what the browser process does when the screen orientation |
| 84 // is changed: |
| 85 // 1. The top-level frame is resized and a ViweMsg_Resize is sent to the |
| 86 // top-level frame. |
| 87 main_frame_rwh->Send( |
| 88 new ViewMsg_Resize(main_frame_rwh->GetRoutingID(), params)); |
| 89 |
| 90 // 2. The WebContents sends a PageMsg_UpdateScreenInfo to all the renderers |
| 91 // involved in the FrameTree. |
| 92 web_contents()->GetFrameTree()->root()->render_manager()->SendPageMessage( |
| 93 new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info), nullptr); |
| 94 |
| 95 // 3. When the top-level frame gets the ViewMsg_Resize, it'll dispatch a |
| 96 // FrameHostMsg_FrameRectsChanged IPC that causes the remote subframes to |
| 97 // receive the ViewMsg_Resize from the browser. |
| 98 for (auto* rwh : rwhs) |
| 99 rwh->Send(new ViewMsg_Resize(rwh->GetRoutingID(), params)); |
61 } | 100 } |
62 | 101 |
63 int GetOrientationAngle() { | 102 int GetOrientationAngle() { |
64 int angle; | 103 int angle; |
65 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), | 104 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), |
66 "screen.orientation.angle")->GetAsInteger(&angle); | 105 "screen.orientation.angle")->GetAsInteger(&angle); |
67 return angle; | 106 return angle; |
68 } | 107 } |
69 | 108 |
70 std::string GetOrientationType() { | 109 std::string GetOrientationType() { |
(...skipping 21 matching lines...) Expand all Loading... |
92 int angle; | 131 int angle; |
93 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), | 132 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), |
94 "window.orientation")->GetAsInteger(&angle); | 133 "window.orientation")->GetAsInteger(&angle); |
95 return angle; | 134 return angle; |
96 } | 135 } |
97 | 136 |
98 private: | 137 private: |
99 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest); | 138 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest); |
100 }; | 139 }; |
101 | 140 |
| 141 class ScreenOrientationOOPIFBrowserTest : public ScreenOrientationBrowserTest { |
| 142 public: |
| 143 ScreenOrientationOOPIFBrowserTest() {} |
| 144 |
| 145 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 146 IsolateAllSitesForTesting(command_line); |
| 147 } |
| 148 |
| 149 void SetUpOnMainThread() override { |
| 150 host_resolver()->AddRule("*", "127.0.0.1"); |
| 151 SetupCrossSiteRedirector(embedded_test_server()); |
| 152 ASSERT_TRUE(embedded_test_server()->Start()); |
| 153 } |
| 154 |
| 155 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationOOPIFBrowserTest); |
| 157 }; |
| 158 |
102 // This test doesn't work on MacOS X but the reason is mostly because it is not | 159 // 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 | 160 // 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. | 161 // actually support MacOS X if and when it switches to Aura. |
105 #if defined(USE_AURA) || defined(OS_ANDROID) | 162 #if defined(USE_AURA) || defined(OS_ANDROID) |
106 // Flaky on Chrome OS: http://crbug.com/468259 | 163 // Flaky on Chrome OS: http://crbug.com/468259 |
107 #if defined(OS_CHROMEOS) | 164 #if defined(OS_CHROMEOS) |
108 #define MAYBE_ScreenOrientationChange DISABLED_ScreenOrientationChange | 165 #define MAYBE_ScreenOrientationChange DISABLED_ScreenOrientationChange |
109 #else | 166 #else |
110 #define MAYBE_ScreenOrientationChange ScreenOrientationChange | 167 #define MAYBE_ScreenOrientationChange ScreenOrientationChange |
111 #endif | 168 #endif |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 ASSERT_TRUE(ExecuteScript(shell(), "run();")); | 295 ASSERT_TRUE(ExecuteScript(shell(), "run();")); |
239 | 296 |
240 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 297 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
241 navigation_observer.Wait(); | 298 navigation_observer.Wait(); |
242 EXPECT_EQ("NotSupportedError", | 299 EXPECT_EQ("NotSupportedError", |
243 shell()->web_contents()->GetLastCommittedURL().ref()); | 300 shell()->web_contents()->GetLastCommittedURL().ref()); |
244 } | 301 } |
245 } | 302 } |
246 #endif // defined(OS_ANDROID) | 303 #endif // defined(OS_ANDROID) |
247 | 304 |
| 305 IN_PROC_BROWSER_TEST_F(ScreenOrientationOOPIFBrowserTest, ScreenOrientation) { |
| 306 GURL main_url(embedded_test_server()->GetURL( |
| 307 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 308 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 309 #if USE_AURA || defined(OS_ANDROID) |
| 310 WaitForResizeComplete(shell()->web_contents()); |
| 311 #endif // USE_AURA || defined(OS_ANDROID) |
| 312 |
| 313 std::string types[] = {"portrait-primary", "portrait-secondary", |
| 314 "landscape-primary", "landscape-secondary"}; |
| 315 |
| 316 int angle = GetOrientationAngle(); |
| 317 |
| 318 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 319 FrameTreeNode* child = root->child_at(0); |
| 320 MainThreadFrameObserver root_observer( |
| 321 root->current_frame_host()->GetRenderWidgetHost()); |
| 322 MainThreadFrameObserver child_observer( |
| 323 child->current_frame_host()->GetRenderWidgetHost()); |
| 324 for (int i = 0; i < 4; ++i) { |
| 325 angle = (angle + 90) % 360; |
| 326 SendFakeScreenOrientation(angle, types[i]); |
| 327 |
| 328 root_observer.Wait(); |
| 329 child_observer.Wait(); |
| 330 |
| 331 int orientation_angle; |
| 332 std::string orientation_type; |
| 333 |
| 334 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 335 root->current_frame_host(), |
| 336 "window.domAutomationController.send(screen.orientation.angle)", |
| 337 &orientation_angle)); |
| 338 EXPECT_EQ(angle, orientation_angle); |
| 339 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 340 child->current_frame_host(), |
| 341 "window.domAutomationController.send(screen.orientation.angle)", |
| 342 &orientation_angle)); |
| 343 EXPECT_EQ(angle, orientation_angle); |
| 344 |
| 345 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 346 root->current_frame_host(), |
| 347 "window.domAutomationController.send(screen.orientation.type)", |
| 348 &orientation_type)); |
| 349 EXPECT_EQ(types[i], orientation_type); |
| 350 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 351 child->current_frame_host(), |
| 352 "window.domAutomationController.send(screen.orientation.type)", |
| 353 &orientation_type)); |
| 354 EXPECT_EQ(types[i], orientation_type); |
| 355 } |
| 356 } |
| 357 |
248 } // namespace content | 358 } // namespace content |
OLD | NEW |