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

Side by Side Diff: ash/wm/overview/window_selector_unittest.cc

Issue 2337383003: [ash-md] Corrects a crash when a window is destroyed after leaving overview (Closed)
Patch Set: [ash-md] Corrects a crash when a window is destroyed after leaving overview Created 4 years, 3 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
« no previous file with comments | « ash/common/wm/overview/window_selector_item.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <vector> 6 #include <vector>
7 7
8 #include "ash/aura/wm_window_aura.h" 8 #include "ash/aura/wm_window_aura.h"
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/accessibility_types.h" 10 #include "ash/common/accessibility_types.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "ui/aura/client/cursor_client.h" 53 #include "ui/aura/client/cursor_client.h"
54 #include "ui/aura/client/focus_client.h" 54 #include "ui/aura/client/focus_client.h"
55 #include "ui/aura/test/test_window_delegate.h" 55 #include "ui/aura/test/test_window_delegate.h"
56 #include "ui/aura/test/test_windows.h" 56 #include "ui/aura/test/test_windows.h"
57 #include "ui/aura/window.h" 57 #include "ui/aura/window.h"
58 #include "ui/aura/window_event_dispatcher.h" 58 #include "ui/aura/window_event_dispatcher.h"
59 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 59 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
60 #include "ui/display/manager/display_layout.h" 60 #include "ui/display/manager/display_layout.h"
61 #include "ui/events/event_utils.h" 61 #include "ui/events/event_utils.h"
62 #include "ui/events/test/event_generator.h" 62 #include "ui/events/test/event_generator.h"
63 #include "ui/gfx/animation/slide_animation.h"
63 #include "ui/gfx/geometry/point_conversions.h" 64 #include "ui/gfx/geometry/point_conversions.h"
64 #include "ui/gfx/geometry/rect_conversions.h" 65 #include "ui/gfx/geometry/rect_conversions.h"
65 #include "ui/gfx/geometry/safe_integer_conversions.h" 66 #include "ui/gfx/geometry/safe_integer_conversions.h"
66 #include "ui/gfx/transform.h" 67 #include "ui/gfx/transform.h"
67 #include "ui/gfx/transform_util.h" 68 #include "ui/gfx/transform_util.h"
68 #include "ui/views/controls/button/image_button.h" 69 #include "ui/views/controls/button/image_button.h"
69 #include "ui/views/controls/button/label_button.h" 70 #include "ui/views/controls/button/label_button.h"
70 #include "ui/views/widget/native_widget_aura.h" 71 #include "ui/views/widget/native_widget_aura.h"
71 #include "ui/views/widget/widget_delegate.h" 72 #include "ui/views/widget/widget_delegate.h"
72 #include "ui/wm/core/window_util.h" 73 #include "ui/wm/core/window_util.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 GetWindowItemsForRoot(grid_index); 267 GetWindowItemsForRoot(grid_index);
267 auto iter = std::find_if(windows.cbegin(), windows.cend(), 268 auto iter = std::find_if(windows.cbegin(), windows.cend(),
268 [window](const WindowSelectorItem* item) { 269 [window](const WindowSelectorItem* item) {
269 return item->Contains(WmWindowAura::Get(window)); 270 return item->Contains(WmWindowAura::Get(window));
270 }); 271 });
271 if (iter == windows.end()) 272 if (iter == windows.end())
272 return nullptr; 273 return nullptr;
273 return *iter; 274 return *iter;
274 } 275 }
275 276
277 gfx::SlideAnimation* GetBackgroundViewAnimationForWindow(
278 int grid_index,
279 aura::Window* window) {
280 return GetWindowItemForWindow(grid_index, window)
281 ->GetBackgroundViewAnimation();
282 }
283
276 // Selects |window| in the active overview session by cycling through all 284 // Selects |window| in the active overview session by cycling through all
277 // windows in overview until it is found. Returns true if |window| was found, 285 // windows in overview until it is found. Returns true if |window| was found,
278 // false otherwise. 286 // false otherwise.
279 bool SelectWindow(const aura::Window* window) { 287 bool SelectWindow(const aura::Window* window) {
280 if (GetSelectedWindow() == nullptr) 288 if (GetSelectedWindow() == nullptr)
281 SendKey(ui::VKEY_TAB); 289 SendKey(ui::VKEY_TAB);
282 const aura::Window* start_window = GetSelectedWindow(); 290 const aura::Window* start_window = GetSelectedWindow();
283 if (start_window == window) 291 if (start_window == window)
284 return true; 292 return true;
285 do { 293 do {
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 } 1287 }
1280 { 1288 {
1281 ui::ScopedAnimationDurationScaleMode test_duration_mode( 1289 ui::ScopedAnimationDurationScaleMode test_duration_mode(
1282 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); 1290 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1283 ToggleOverview(); 1291 ToggleOverview();
1284 EXPECT_FALSE(window1->IsVisible()); 1292 EXPECT_FALSE(window1->IsVisible());
1285 EXPECT_FALSE(window1->layer()->GetTargetVisibility()); 1293 EXPECT_FALSE(window1->layer()->GetTargetVisibility());
1286 } 1294 }
1287 } 1295 }
1288 1296
1297 // Tests that it is safe to destroy a window while the overview header animation
1298 // is still active. See http://crbug.com/646350.
1299 TEST_P(WindowSelectorTest, SafeToDestroyWindowDuringAnimation) {
1300 gfx::Rect bounds(0, 0, 400, 400);
1301 {
1302 // Quickly enter and exit overview mode to activate header animations.
1303 std::unique_ptr<aura::Window> window(CreateWindow(bounds));
1304 ui::ScopedAnimationDurationScaleMode test_duration_mode(
1305 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1306 ToggleOverview();
1307 EXPECT_TRUE(IsSelecting());
1308
1309 gfx::SlideAnimation* animation =
1310 GetBackgroundViewAnimationForWindow(0, window.get());
1311 if (ash::MaterialDesignController::IsOverviewMaterial())
1312 ASSERT_TRUE(!!animation);
sky 2016/09/15 03:01:00 Double negatives are hard to read. ASSERT_NE(nullp
varkha 2016/09/15 03:54:18 Done.
1313 ToggleOverview();
1314 EXPECT_FALSE(IsSelecting());
1315 if (animation)
1316 EXPECT_TRUE(animation->is_animating());
1317
1318 // Close the window while the overview header animation is active.
1319 window.reset();
1320
1321 // Progress animation to the end - should not crash.
1322 if (animation) {
1323 animation->SetCurrentValue(1.0);
1324 animation->Reset(1.0);
1325 }
1326 }
1327 }
1328
1289 // Tests that a bounds change during overview is corrected for. 1329 // Tests that a bounds change during overview is corrected for.
1290 TEST_P(WindowSelectorTest, BoundsChangeDuringOverview) { 1330 TEST_P(WindowSelectorTest, BoundsChangeDuringOverview) {
1291 std::unique_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 400, 400))); 1331 std::unique_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 400, 400)));
1292 // Use overview headers above the window in this test. 1332 // Use overview headers above the window in this test.
1293 window->SetProperty(aura::client::kTopViewInset, 0); 1333 window->SetProperty(aura::client::kTopViewInset, 0);
1294 ToggleOverview(); 1334 ToggleOverview();
1295 gfx::Rect overview_bounds = 1335 gfx::Rect overview_bounds =
1296 ToEnclosingRect(GetTransformedTargetBounds(window.get())); 1336 ToEnclosingRect(GetTransformedTargetBounds(window.get()));
1297 window->SetBounds(gfx::Rect(200, 0, 200, 200)); 1337 window->SetBounds(gfx::Rect(200, 0, 200, 200));
1298 gfx::Rect new_overview_bounds = 1338 gfx::Rect new_overview_bounds =
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 bounds.y()); 2186 bounds.y());
2147 EXPECT_LE(transformed_rect.bottom(), bounds.bottom()); 2187 EXPECT_LE(transformed_rect.bottom(), bounds.bottom());
2148 EXPECT_NEAR(transformed_rect.x() - bounds.x(), 2188 EXPECT_NEAR(transformed_rect.x() - bounds.x(),
2149 bounds.right() - transformed_rect.right(), 1); 2189 bounds.right() - transformed_rect.right(), 1);
2150 EXPECT_NEAR( 2190 EXPECT_NEAR(
2151 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(), 2191 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(),
2152 bounds.bottom() - transformed_rect.bottom(), 1); 2192 bounds.bottom() - transformed_rect.bottom(), 1);
2153 } 2193 }
2154 2194
2155 } // namespace ash 2195 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector_item.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698