OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 widget.Minimize(); | 1118 widget.Minimize(); |
1119 EXPECT_EQ(0, frame_view->width()); | 1119 EXPECT_EQ(0, frame_view->width()); |
1120 } | 1120 } |
1121 | 1121 |
1122 // This class validates whether paints are received for a visible Widget. | 1122 // This class validates whether paints are received for a visible Widget. |
1123 // To achieve this it overrides the Show and Close methods on the Widget class | 1123 // To achieve this it overrides the Show and Close methods on the Widget class |
1124 // and sets state whether subsequent paints are expected. | 1124 // and sets state whether subsequent paints are expected. |
1125 class DesktopAuraTestValidPaintWidget : public views::Widget { | 1125 class DesktopAuraTestValidPaintWidget : public views::Widget { |
1126 public: | 1126 public: |
1127 DesktopAuraTestValidPaintWidget() | 1127 DesktopAuraTestValidPaintWidget() |
1128 : expect_paint_(true), | 1128 : received_paint_(false), |
1129 received_paint_while_hidden_(false) { | 1129 expect_paint_(true), |
1130 } | 1130 received_paint_while_hidden_(false) {} |
1131 | 1131 |
1132 virtual ~DesktopAuraTestValidPaintWidget() { | 1132 virtual ~DesktopAuraTestValidPaintWidget() {} |
1133 } | 1133 |
| 1134 void InitForTest(Widget::InitParams create_params); |
1134 | 1135 |
1135 virtual void Show() override { | 1136 virtual void Show() override { |
1136 expect_paint_ = true; | 1137 expect_paint_ = true; |
1137 views::Widget::Show(); | 1138 views::Widget::Show(); |
1138 } | 1139 } |
1139 | 1140 |
1140 virtual void Close() override { | 1141 virtual void Close() override { |
1141 expect_paint_ = false; | 1142 expect_paint_ = false; |
1142 views::Widget::Close(); | 1143 views::Widget::Close(); |
1143 } | 1144 } |
1144 | 1145 |
1145 void Hide() { | 1146 void Hide() { |
1146 expect_paint_ = false; | 1147 expect_paint_ = false; |
1147 views::Widget::Hide(); | 1148 views::Widget::Hide(); |
1148 } | 1149 } |
1149 | 1150 |
1150 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) override { | 1151 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) override { |
| 1152 received_paint_ = true; |
1151 EXPECT_TRUE(expect_paint_); | 1153 EXPECT_TRUE(expect_paint_); |
1152 if (!expect_paint_) | 1154 if (!expect_paint_) |
1153 received_paint_while_hidden_ = true; | 1155 received_paint_while_hidden_ = true; |
1154 views::Widget::OnNativeWidgetPaint(canvas); | 1156 views::Widget::OnNativeWidgetPaint(canvas); |
1155 } | 1157 } |
1156 | 1158 |
| 1159 bool ReadReceivedPaintAndReset() { |
| 1160 bool result = received_paint_; |
| 1161 received_paint_ = false; |
| 1162 return result; |
| 1163 } |
| 1164 |
1157 bool received_paint_while_hidden() const { | 1165 bool received_paint_while_hidden() const { |
1158 return received_paint_while_hidden_; | 1166 return received_paint_while_hidden_; |
1159 } | 1167 } |
1160 | 1168 |
1161 private: | 1169 private: |
| 1170 bool received_paint_; |
1162 bool expect_paint_; | 1171 bool expect_paint_; |
1163 bool received_paint_while_hidden_; | 1172 bool received_paint_while_hidden_; |
| 1173 |
| 1174 DISALLOW_COPY_AND_ASSIGN(DesktopAuraTestValidPaintWidget); |
1164 }; | 1175 }; |
1165 | 1176 |
1166 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterCloseTest) { | 1177 void DesktopAuraTestValidPaintWidget::InitForTest(InitParams init_params) { |
| 1178 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 1179 init_params.ownership = InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1180 init_params.native_widget = new PlatformDesktopNativeWidget(this); |
| 1181 Init(init_params); |
| 1182 |
1167 View* contents_view = new View; | 1183 View* contents_view = new View; |
1168 contents_view->SetFocusable(true); | 1184 contents_view->SetFocusable(true); |
| 1185 SetContentsView(contents_view); |
| 1186 |
| 1187 Show(); |
| 1188 Activate(); |
| 1189 } |
| 1190 |
| 1191 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterCloseTest) { |
1169 DesktopAuraTestValidPaintWidget widget; | 1192 DesktopAuraTestValidPaintWidget widget; |
1170 Widget::InitParams init_params = | 1193 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); |
1171 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
1172 init_params.bounds = gfx::Rect(0, 0, 200, 200); | |
1173 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
1174 init_params.native_widget = new PlatformDesktopNativeWidget(&widget); | |
1175 widget.Init(init_params); | |
1176 widget.SetContentsView(contents_view); | |
1177 widget.Show(); | |
1178 widget.Activate(); | |
1179 RunPendingMessages(); | 1194 RunPendingMessages(); |
1180 widget.SchedulePaintInRect(init_params.bounds); | 1195 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
| 1196 widget.SchedulePaintInRect(widget.GetRestoredBounds()); |
1181 widget.Close(); | 1197 widget.Close(); |
1182 RunPendingMessages(); | 1198 RunPendingMessages(); |
| 1199 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
1183 EXPECT_FALSE(widget.received_paint_while_hidden()); | 1200 EXPECT_FALSE(widget.received_paint_while_hidden()); |
1184 } | 1201 } |
1185 | 1202 |
1186 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterHideTest) { | 1203 TEST_F(WidgetTest, DesktopNativeWidgetNoPaintAfterHideTest) { |
1187 View* contents_view = new View; | |
1188 contents_view->SetFocusable(true); | |
1189 DesktopAuraTestValidPaintWidget widget; | 1204 DesktopAuraTestValidPaintWidget widget; |
1190 Widget::InitParams init_params = | 1205 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); |
1191 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
1192 init_params.bounds = gfx::Rect(0, 0, 200, 200); | |
1193 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
1194 init_params.native_widget = new PlatformDesktopNativeWidget(&widget); | |
1195 widget.Init(init_params); | |
1196 widget.SetContentsView(contents_view); | |
1197 widget.Show(); | |
1198 widget.Activate(); | |
1199 RunPendingMessages(); | 1206 RunPendingMessages(); |
1200 widget.SchedulePaintInRect(init_params.bounds); | 1207 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
| 1208 widget.SchedulePaintInRect(widget.GetRestoredBounds()); |
1201 widget.Hide(); | 1209 widget.Hide(); |
1202 RunPendingMessages(); | 1210 RunPendingMessages(); |
| 1211 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
1203 EXPECT_FALSE(widget.received_paint_while_hidden()); | 1212 EXPECT_FALSE(widget.received_paint_while_hidden()); |
1204 widget.Close(); | 1213 widget.Close(); |
1205 } | 1214 } |
1206 | 1215 |
1207 // Test to ensure that the aura Window's visiblity state is set to visible if | 1216 // Test to ensure that the aura Window's visiblity state is set to visible if |
1208 // the underlying widget is hidden and then shown. | 1217 // the underlying widget is hidden and then shown. |
1209 TEST_F(WidgetTest, TestWindowVisibilityAfterHide) { | 1218 TEST_F(WidgetTest, TestWindowVisibilityAfterHide) { |
1210 // Create a widget. | 1219 // Create a widget. |
1211 Widget widget; | 1220 Widget widget; |
1212 Widget::InitParams init_params = | 1221 Widget::InitParams init_params = |
1213 CreateParams(Widget::InitParams::TYPE_WINDOW); | 1222 CreateParams(Widget::InitParams::TYPE_WINDOW); |
1214 init_params.show_state = ui::SHOW_STATE_NORMAL; | 1223 init_params.show_state = ui::SHOW_STATE_NORMAL; |
1215 gfx::Rect initial_bounds(0, 0, 300, 400); | 1224 gfx::Rect initial_bounds(0, 0, 300, 400); |
1216 init_params.bounds = initial_bounds; | 1225 init_params.bounds = initial_bounds; |
1217 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1226 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1218 init_params.native_widget = new PlatformDesktopNativeWidget(&widget); | 1227 init_params.native_widget = new PlatformDesktopNativeWidget(&widget); |
1219 widget.Init(init_params); | 1228 widget.Init(init_params); |
1220 NonClientView* non_client_view = widget.non_client_view(); | 1229 NonClientView* non_client_view = widget.non_client_view(); |
1221 NonClientFrameView* frame_view = new MinimumSizeFrameView(&widget); | 1230 NonClientFrameView* frame_view = new MinimumSizeFrameView(&widget); |
1222 non_client_view->SetFrameView(frame_view); | 1231 non_client_view->SetFrameView(frame_view); |
1223 | 1232 |
| 1233 widget.Show(); |
| 1234 EXPECT_TRUE(IsNativeWindowVisible(widget.GetNativeWindow())); |
1224 widget.Hide(); | 1235 widget.Hide(); |
1225 EXPECT_FALSE(IsNativeWindowVisible(widget.GetNativeWindow())); | 1236 EXPECT_FALSE(IsNativeWindowVisible(widget.GetNativeWindow())); |
1226 widget.Show(); | 1237 widget.Show(); |
1227 EXPECT_TRUE(IsNativeWindowVisible(widget.GetNativeWindow())); | 1238 EXPECT_TRUE(IsNativeWindowVisible(widget.GetNativeWindow())); |
1228 } | 1239 } |
1229 | 1240 |
1230 // The following code verifies we can correctly destroy a Widget from a mouse | 1241 // The following code verifies we can correctly destroy a Widget from a mouse |
1231 // enter/exit. We could test move/drag/enter/exit but in general we don't run | 1242 // enter/exit. We could test move/drag/enter/exit but in general we don't run |
1232 // nested message loops from such events, nor has the code ever really dealt | 1243 // nested message loops from such events, nor has the code ever really dealt |
1233 // with this situation. | 1244 // with this situation. |
(...skipping 2125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3359 | 3370 |
3360 EXPECT_EQ(test_rect, root_view->bounds()); | 3371 EXPECT_EQ(test_rect, root_view->bounds()); |
3361 widget->ReorderNativeViews(); | 3372 widget->ReorderNativeViews(); |
3362 EXPECT_EQ(test_rect, root_view->bounds()); | 3373 EXPECT_EQ(test_rect, root_view->bounds()); |
3363 | 3374 |
3364 widget->CloseNow(); | 3375 widget->CloseNow(); |
3365 } | 3376 } |
3366 | 3377 |
3367 } // namespace test | 3378 } // namespace test |
3368 } // namespace views | 3379 } // namespace views |
OLD | NEW |