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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 2695093005: Remove RWHV::SetBounds() from the public API, and make comments clearer.
Patch Set: Revert web_contents_sizer to its previous shenanigans (http://crbug.com/693953). Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms( 821 ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
822 debounce_interval_in_ms); 822 debounce_interval_in_ms);
823 823
824 RenderWidgetHostViewAuraTest::SetUp(); 824 RenderWidgetHostViewAuraTest::SetUp();
825 825
826 view_->SetOverscrollControllerEnabled(true); 826 view_->SetOverscrollControllerEnabled(true);
827 overscroll_delegate_.reset(new TestOverscrollDelegate(view_)); 827 overscroll_delegate_.reset(new TestOverscrollDelegate(view_));
828 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get()); 828 view_->overscroll_controller()->set_delegate(overscroll_delegate_.get());
829 829
830 view_->InitAsChild(nullptr); 830 view_->InitAsChild(nullptr);
831 view_->SetBounds(gfx::Rect(0, 0, 400, 200)); 831 view_->RequestTopLevelBoundsInScreen(gfx::Rect(0, 0, 400, 200));
832 view_->Show(); 832 view_->Show();
833 833
834 sink_->ClearMessages(); 834 sink_->ClearMessages();
835 } 835 }
836 836
837 // TODO(jdduke): Simulate ui::Events, injecting through the view. 837 // TODO(jdduke): Simulate ui::Events, injecting through the view.
838 void SimulateMouseEvent(WebInputEvent::Type type) { 838 void SimulateMouseEvent(WebInputEvent::Type type) {
839 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type)); 839 widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
840 } 840 }
841 841
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 EXPECT_TRUE(view_->ShouldActivate()); 1028 EXPECT_TRUE(view_->ShouldActivate());
1029 } 1029 }
1030 1030
1031 // Checks that a popup is positioned correctly relative to its parent using 1031 // Checks that a popup is positioned correctly relative to its parent using
1032 // screen coordinates. 1032 // screen coordinates.
1033 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { 1033 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
1034 1034
1035 aura::Window* window = parent_view_->GetNativeView(); 1035 aura::Window* window = parent_view_->GetNativeView();
1036 aura::Window* root = window->GetRootWindow(); 1036 aura::Window* root = window->GetRootWindow();
1037 1037
1038 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); 1038 parent_view_->RequestTopLevelBoundsInScreen(gfx::Rect(10, 10, 800, 600));
1039 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); 1039 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
1040 int horiz = bounds_in_screen.width() / 4; 1040 int horiz = bounds_in_screen.width() / 4;
1041 int vert = bounds_in_screen.height() / 4; 1041 int vert = bounds_in_screen.height() / 4;
1042 bounds_in_screen.Inset(horiz, vert); 1042 bounds_in_screen.Inset(horiz, vert);
1043 1043
1044 // Verify that when the popup is initialized for the first time, it correctly 1044 // Verify that when the popup is initialized for the first time, it correctly
1045 // treats the input bounds as screen coordinates. 1045 // treats the input bounds as screen coordinates.
1046 view_->InitAsPopup(parent_view_, bounds_in_screen); 1046 view_->InitAsPopup(parent_view_, bounds_in_screen);
1047 1047
1048 gfx::Rect final_bounds_in_screen = view_->GetViewBounds(); 1048 gfx::Rect final_bounds_in_screen = view_->GetViewBounds();
1049 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString()); 1049 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
1050 1050
1051 // Verify that directly setting the bounds via SetBounds() treats the input 1051 // Verify that directly setting the bounds via RequestTopLevelBoundsInScreen()
1052 // as screen coordinates. 1052 // treats the input as screen coordinates.
1053 bounds_in_screen = gfx::Rect(60, 60, 100, 100); 1053 bounds_in_screen = gfx::Rect(60, 60, 100, 100);
1054 view_->SetBounds(bounds_in_screen); 1054 view_->RequestTopLevelBoundsInScreen(bounds_in_screen);
1055 final_bounds_in_screen = view_->GetViewBounds(); 1055 final_bounds_in_screen = view_->GetViewBounds();
1056 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString()); 1056 EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
1057 1057
1058 // Verify that setting the size does not alter the origin. 1058 // Verify that setting the size does not alter the origin.
1059 gfx::Point original_origin = window->bounds().origin(); 1059 gfx::Point original_origin = window->bounds().origin();
1060 view_->SetSize(gfx::Size(120, 120)); 1060 view_->SetSize(gfx::Size(120, 120));
1061 gfx::Point new_origin = window->bounds().origin(); 1061 gfx::Point new_origin = window->bounds().origin();
1062 EXPECT_EQ(original_origin.ToString(), new_origin.ToString()); 1062 EXPECT_EQ(original_origin.ToString(), new_origin.ToString());
1063 1063
1064 aura::client::SetScreenPositionClient(root, nullptr); 1064 aura::client::SetScreenPositionClient(root, nullptr);
(...skipping 13 matching lines...) Expand all
1078 parent2->Init(ui::LAYER_TEXTURED); 1078 parent2->Init(ui::LAYER_TEXTURED);
1079 parent2->Show(); 1079 parent2->Show();
1080 1080
1081 root->AddChild(parent1.get()); 1081 root->AddChild(parent1.get());
1082 parent1->AddChild(parent2.get()); 1082 parent1->AddChild(parent2.get());
1083 parent2->AddChild(view_->GetNativeView()); 1083 parent2->AddChild(view_->GetNativeView());
1084 1084
1085 root->SetBounds(gfx::Rect(0, 0, 800, 600)); 1085 root->SetBounds(gfx::Rect(0, 0, 800, 600));
1086 parent1->SetBounds(gfx::Rect(1, 1, 300, 300)); 1086 parent1->SetBounds(gfx::Rect(1, 1, 300, 300));
1087 parent2->SetBounds(gfx::Rect(2, 2, 200, 200)); 1087 parent2->SetBounds(gfx::Rect(2, 2, 200, 200));
1088 view_->SetBounds(gfx::Rect(3, 3, 100, 100)); 1088 view_->RequestTopLevelBoundsInScreen(gfx::Rect(3, 3, 100, 100));
1089 // view_ will be destroyed when parent is destroyed. 1089 // view_ will be destroyed when parent is destroyed.
1090 view_ = nullptr; 1090 view_ = nullptr;
1091 1091
1092 // Flush the state after initial setup is done. 1092 // Flush the state after initial setup is done.
1093 widget_host_->OnMessageReceived( 1093 widget_host_->OnMessageReceived(
1094 ViewHostMsg_UpdateScreenRects_ACK(widget_host_->GetRoutingID())); 1094 ViewHostMsg_UpdateScreenRects_ACK(widget_host_->GetRoutingID()));
1095 widget_host_->OnMessageReceived( 1095 widget_host_->OnMessageReceived(
1096 ViewHostMsg_UpdateScreenRects_ACK(widget_host_->GetRoutingID())); 1096 ViewHostMsg_UpdateScreenRects_ACK(widget_host_->GetRoutingID()));
1097 sink_->ClearMessages(); 1097 sink_->ClearMessages();
1098 1098
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 ASSERT_TRUE(observer.destroyed()); 1145 ASSERT_TRUE(observer.destroyed());
1146 1146
1147 widget_host_ = nullptr; 1147 widget_host_ = nullptr;
1148 view_ = nullptr; 1148 view_ = nullptr;
1149 } 1149 }
1150 1150
1151 // Checks that a popup view is destroyed when a user clicks outside of the popup 1151 // Checks that a popup view is destroyed when a user clicks outside of the popup
1152 // view and focus does not change. This is the case when the user clicks on the 1152 // view and focus does not change. This is the case when the user clicks on the
1153 // desktop background on Chrome OS. 1153 // desktop background on Chrome OS.
1154 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupClickOutsidePopup) { 1154 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupClickOutsidePopup) {
1155 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400)); 1155 parent_view_->RequestTopLevelBoundsInScreen(gfx::Rect(10, 10, 400, 400));
1156 parent_view_->Focus(); 1156 parent_view_->Focus();
1157 EXPECT_TRUE(parent_view_->HasFocus()); 1157 EXPECT_TRUE(parent_view_->HasFocus());
1158 1158
1159 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100)); 1159 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
1160 aura::Window* window = view_->GetNativeView(); 1160 aura::Window* window = view_->GetNativeView();
1161 ASSERT_TRUE(window != nullptr); 1161 ASSERT_TRUE(window != nullptr);
1162 1162
1163 gfx::Point click_point; 1163 gfx::Point click_point;
1164 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(click_point)); 1164 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(click_point));
1165 aura::Window* parent_window = parent_view_->GetNativeView(); 1165 aura::Window* parent_window = parent_view_->GetNativeView();
1166 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(click_point)); 1166 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(click_point));
1167 1167
1168 TestWindowObserver observer(window); 1168 TestWindowObserver observer(window);
1169 ui::test::EventGenerator generator(window->GetRootWindow(), click_point); 1169 ui::test::EventGenerator generator(window->GetRootWindow(), click_point);
1170 generator.ClickLeftButton(); 1170 generator.ClickLeftButton();
1171 ASSERT_TRUE(parent_view_->HasFocus()); 1171 ASSERT_TRUE(parent_view_->HasFocus());
1172 ASSERT_TRUE(observer.destroyed()); 1172 ASSERT_TRUE(observer.destroyed());
1173 1173
1174 widget_host_ = nullptr; 1174 widget_host_ = nullptr;
1175 view_ = nullptr; 1175 view_ = nullptr;
1176 } 1176 }
1177 1177
1178 // Checks that a popup view is destroyed when a user taps outside of the popup 1178 // Checks that a popup view is destroyed when a user taps outside of the popup
1179 // view and focus does not change. This is the case when the user taps the 1179 // view and focus does not change. This is the case when the user taps the
1180 // desktop background on Chrome OS. 1180 // desktop background on Chrome OS.
1181 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupTapOutsidePopup) { 1181 TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupTapOutsidePopup) {
1182 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400)); 1182 parent_view_->RequestTopLevelBoundsInScreen(gfx::Rect(10, 10, 400, 400));
1183 parent_view_->Focus(); 1183 parent_view_->Focus();
1184 EXPECT_TRUE(parent_view_->HasFocus()); 1184 EXPECT_TRUE(parent_view_->HasFocus());
1185 1185
1186 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100)); 1186 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
1187 aura::Window* window = view_->GetNativeView(); 1187 aura::Window* window = view_->GetNativeView();
1188 ASSERT_TRUE(window != nullptr); 1188 ASSERT_TRUE(window != nullptr);
1189 1189
1190 gfx::Point tap_point; 1190 gfx::Point tap_point;
1191 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(tap_point)); 1191 EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(tap_point));
1192 aura::Window* parent_window = parent_view_->GetNativeView(); 1192 aura::Window* parent_window = parent_view_->GetNativeView();
1193 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(tap_point)); 1193 EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(tap_point));
1194 1194
1195 TestWindowObserver observer(window); 1195 TestWindowObserver observer(window);
1196 ui::test::EventGenerator generator(window->GetRootWindow(), tap_point); 1196 ui::test::EventGenerator generator(window->GetRootWindow(), tap_point);
1197 generator.GestureTapAt(tap_point); 1197 generator.GestureTapAt(tap_point);
1198 ASSERT_TRUE(parent_view_->HasFocus()); 1198 ASSERT_TRUE(parent_view_->HasFocus());
1199 ASSERT_TRUE(observer.destroyed()); 1199 ASSERT_TRUE(observer.destroyed());
1200 1200
1201 widget_host_ = nullptr; 1201 widget_host_ = nullptr;
1202 view_ = nullptr; 1202 view_ = nullptr;
1203 } 1203 }
1204 1204
1205 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1205 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1206 1206
1207 // On Desktop Linux, select boxes need mouse capture in order to work. Test that 1207 // On Desktop Linux, select boxes need mouse capture in order to work. Test that
1208 // when a select box is opened via a mouse press that it retains mouse capture 1208 // when a select box is opened via a mouse press that it retains mouse capture
1209 // after the mouse is released. 1209 // after the mouse is released.
1210 TEST_F(RenderWidgetHostViewAuraTest, PopupRetainsCaptureAfterMouseRelease) { 1210 TEST_F(RenderWidgetHostViewAuraTest, PopupRetainsCaptureAfterMouseRelease) {
1211 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400)); 1211 parent_view_->RequestTopLevelBoundsInScreen(gfx::Rect(10, 10, 400, 400));
1212 parent_view_->Focus(); 1212 parent_view_->Focus();
1213 EXPECT_TRUE(parent_view_->HasFocus()); 1213 EXPECT_TRUE(parent_view_->HasFocus());
1214 1214
1215 ui::test::EventGenerator generator( 1215 ui::test::EventGenerator generator(
1216 parent_view_->GetNativeView()->GetRootWindow(), gfx::Point(300, 300)); 1216 parent_view_->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
1217 generator.PressLeftButton(); 1217 generator.PressLeftButton();
1218 1218
1219 view_->SetPopupType(blink::WebPopupTypePage); 1219 view_->SetPopupType(blink::WebPopupTypePage);
1220 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100)); 1220 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
1221 ASSERT_TRUE(view_->NeedsMouseCapture()); 1221 ASSERT_TRUE(view_->NeedsMouseCapture());
1222 aura::Window* window = view_->GetNativeView(); 1222 aura::Window* window = view_->GetNativeView();
1223 EXPECT_TRUE(window->HasCapture()); 1223 EXPECT_TRUE(window->HasCapture());
1224 1224
1225 generator.ReleaseLeftButton(); 1225 generator.ReleaseLeftButton();
1226 EXPECT_TRUE(window->HasCapture()); 1226 EXPECT_TRUE(window->HasCapture());
1227 } 1227 }
1228 #endif 1228 #endif
1229 1229
1230 // Test that select boxes close when their parent window loses focus (e.g. due 1230 // Test that select boxes close when their parent window loses focus (e.g. due
1231 // to an alert or system modal dialog). 1231 // to an alert or system modal dialog).
1232 TEST_F(RenderWidgetHostViewAuraTest, PopupClosesWhenParentLosesFocus) { 1232 TEST_F(RenderWidgetHostViewAuraTest, PopupClosesWhenParentLosesFocus) {
1233 parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400)); 1233 parent_view_->RequestTopLevelBoundsInScreen(gfx::Rect(10, 10, 400, 400));
1234 parent_view_->Focus(); 1234 parent_view_->Focus();
1235 EXPECT_TRUE(parent_view_->HasFocus()); 1235 EXPECT_TRUE(parent_view_->HasFocus());
1236 1236
1237 view_->SetPopupType(blink::WebPopupTypePage); 1237 view_->SetPopupType(blink::WebPopupTypePage);
1238 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100)); 1238 view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
1239 1239
1240 aura::Window* popup_window = view_->GetNativeView(); 1240 aura::Window* popup_window = view_->GetNativeView();
1241 TestWindowObserver observer(popup_window); 1241 TestWindowObserver observer(popup_window);
1242 1242
1243 aura::test::TestWindowDelegate delegate; 1243 aura::test::TestWindowDelegate delegate;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 } 1693 }
1694 1694
1695 TEST_F(RenderWidgetHostViewAuraTest, UpdateCursorIfOverSelf) { 1695 TEST_F(RenderWidgetHostViewAuraTest, UpdateCursorIfOverSelf) {
1696 view_->InitAsChild(nullptr); 1696 view_->InitAsChild(nullptr);
1697 aura::client::ParentWindowWithContext( 1697 aura::client::ParentWindowWithContext(
1698 view_->GetNativeView(), 1698 view_->GetNativeView(),
1699 parent_view_->GetNativeView()->GetRootWindow(), 1699 parent_view_->GetNativeView()->GetRootWindow(),
1700 gfx::Rect()); 1700 gfx::Rect());
1701 1701
1702 // Note that all coordinates in this test are screen coordinates. 1702 // Note that all coordinates in this test are screen coordinates.
1703 view_->SetBounds(gfx::Rect(60, 60, 100, 100)); 1703 view_->RequestTopLevelBoundsInScreen(gfx::Rect(60, 60, 100, 100));
1704 view_->Show(); 1704 view_->Show();
1705 1705
1706 aura::test::TestCursorClient cursor_client( 1706 aura::test::TestCursorClient cursor_client(
1707 parent_view_->GetNativeView()->GetRootWindow()); 1707 parent_view_->GetNativeView()->GetRootWindow());
1708 1708
1709 // Cursor is in the middle of the window. 1709 // Cursor is in the middle of the window.
1710 cursor_client.reset_calls_to_set_cursor(); 1710 cursor_client.reset_calls_to_set_cursor();
1711 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110)); 1711 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
1712 view_->UpdateCursorIfOverSelf(); 1712 view_->UpdateCursorIfOverSelf();
1713 EXPECT_EQ(1, cursor_client.calls_to_set_cursor()); 1713 EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
(...skipping 3053 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 // There is no composition in the beginning. 4767 // There is no composition in the beginning.
4768 EXPECT_FALSE(has_composition_text()); 4768 EXPECT_FALSE(has_composition_text());
4769 SetHasCompositionTextToTrue(); 4769 SetHasCompositionTextToTrue();
4770 view->ImeCancelComposition(); 4770 view->ImeCancelComposition();
4771 // The composition must have been canceled. 4771 // The composition must have been canceled.
4772 EXPECT_FALSE(has_composition_text()); 4772 EXPECT_FALSE(has_composition_text());
4773 } 4773 }
4774 } 4774 }
4775 4775
4776 } // namespace content 4776 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698