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 "content/browser/renderer_host/render_widget_host_impl.h" | 8 #include "content/browser/renderer_host/render_widget_host_impl.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/public/browser/render_widget_host.h" | 10 #include "content/public/browser/render_widget_host.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return angle; | 78 return angle; |
79 } | 79 } |
80 | 80 |
81 std::string GetOrientationType() { | 81 std::string GetOrientationType() { |
82 std::string type; | 82 std::string type; |
83 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), | 83 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), |
84 "screen.orientation.type")->GetAsString(&type); | 84 "screen.orientation.type")->GetAsString(&type); |
85 return type; | 85 return type; |
86 } | 86 } |
87 | 87 |
| 88 bool WindowOrientationSupported() { |
| 89 bool support; |
| 90 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), |
| 91 "'orientation' in window")->GetAsBoolean(&support); |
| 92 return support; |
| 93 } |
| 94 |
| 95 int GetWindowOrientationAngle() { |
| 96 int angle; |
| 97 ExecuteScriptAndGetValue(shell()->web_contents()->GetMainFrame(), |
| 98 "window.orientation")->GetAsInteger(&angle); |
| 99 return angle; |
| 100 } |
| 101 |
88 private: | 102 private: |
89 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest); | 103 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationBrowserTest); |
90 }; | 104 }; |
91 | 105 |
92 // This test doesn't work on MacOS X but the reason is mostly because it is not | 106 // This test doesn't work on MacOS X but the reason is mostly because it is not |
93 // used Aura. It could be set as !defined(OS_MACOSX) but the rule below will | 107 // used Aura. It could be set as !defined(OS_MACOSX) but the rule below will |
94 // actually support MacOS X if and when it switches to Aura. | 108 // actually support MacOS X if and when it switches to Aura. |
95 #if defined(USE_AURA) || defined(OS_ANDROID) | 109 #if defined(USE_AURA) || defined(OS_ANDROID) |
96 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, ScreenOrientationChange) { | 110 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, ScreenOrientationChange) { |
97 std::string types[] = { "portrait-primary", | 111 std::string types[] = { "portrait-primary", |
98 "portrait-secondary", | 112 "portrait-secondary", |
99 "landscape-primary", | 113 "landscape-primary", |
100 "landscape-secondary" }; | 114 "landscape-secondary" }; |
101 GURL test_url = GetTestUrl("screen_orientation", | 115 GURL test_url = GetTestUrl("screen_orientation", |
102 "screen_orientation_orientationchange.html"); | 116 "screen_orientation_screenorientationchange.html"); |
103 | 117 |
104 TestNavigationObserver navigation_observer( | 118 TestNavigationObserver navigation_observer( |
105 shell()->web_contents(), 1 | 119 shell()->web_contents(), 1 |
106 // Android doesn't paint (ie. UseSoftwareCompositing() has no effect) so we | 120 // Android doesn't paint (ie. UseSoftwareCompositing() has no effect) so we |
107 // shouldn't wait for the first paint. | 121 // shouldn't wait for the first paint. |
108 #if !defined(OS_ANDROID) | 122 #if !defined(OS_ANDROID) |
109 , TestNavigationObserver::FirstPaintRequired | 123 , TestNavigationObserver::FirstPaintRequired |
110 #endif | 124 #endif |
111 ); | 125 ); |
112 shell()->LoadURL(test_url); | 126 shell()->LoadURL(test_url); |
113 navigation_observer.Wait(); | 127 navigation_observer.Wait(); |
114 | 128 |
115 int angle = GetOrientationAngle(); | 129 int angle = GetOrientationAngle(); |
116 | 130 |
117 for (int i = 0; i < 4; ++i) { | 131 for (int i = 0; i < 4; ++i) { |
118 angle = (angle + 90) % 360; | 132 angle = (angle + 90) % 360; |
119 SendFakeScreenOrientation(angle, types[i]); | 133 SendFakeScreenOrientation(angle, types[i]); |
120 | 134 |
121 TestNavigationObserver navigation_observer(shell()->web_contents()); | 135 TestNavigationObserver navigation_observer(shell()->web_contents()); |
122 navigation_observer.Wait(); | 136 navigation_observer.Wait(); |
123 EXPECT_EQ(angle, GetOrientationAngle()); | 137 EXPECT_EQ(angle, GetOrientationAngle()); |
124 EXPECT_EQ(types[i], GetOrientationType()); | 138 EXPECT_EQ(types[i], GetOrientationType()); |
125 } | 139 } |
126 } | 140 } |
127 #endif // defined(USE_AURA) || defined(OS_ANDROID) | 141 #endif // defined(USE_AURA) || defined(OS_ANDROID) |
128 | 142 |
| 143 IN_PROC_BROWSER_TEST_F(ScreenOrientationBrowserTest, WindowOrientationChange) { |
| 144 GURL test_url = GetTestUrl("screen_orientation", |
| 145 "screen_orientation_windoworientationchange.html"); |
| 146 |
| 147 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 148 shell()->LoadURL(test_url); |
| 149 navigation_observer.Wait(); |
| 150 |
| 151 if (!WindowOrientationSupported()) |
| 152 return; |
| 153 |
| 154 int angle = GetWindowOrientationAngle(); |
| 155 |
| 156 for (int i = 0; i < 4; ++i) { |
| 157 angle = (angle + 90) % 360; |
| 158 SendFakeScreenOrientation(angle, "portrait-primary"); |
| 159 |
| 160 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 161 navigation_observer.Wait(); |
| 162 EXPECT_EQ(angle == 270 ? -90 : angle, GetWindowOrientationAngle()); |
| 163 } |
| 164 } |
| 165 |
129 } // namespace content | 166 } // namespace content |
OLD | NEW |