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

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

Issue 810033010: Remove TransparentActivateWindowButton from Overview Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 5 years, 11 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/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 6
7 #include "ash/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/drag_drop/drag_drop_controller.h" 8 #include "ash/drag_drop/drag_drop_controller.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shelf/shelf.h" 11 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/shelf_test_api.h" 16 #include "ash/test/shelf_test_api.h"
17 #include "ash/test/shelf_view_test_api.h" 17 #include "ash/test/shelf_view_test_api.h"
18 #include "ash/test/shell_test_api.h" 18 #include "ash/test/shell_test_api.h"
19 #include "ash/test/test_shelf_delegate.h" 19 #include "ash/test/test_shelf_delegate.h"
20 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 20 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
21 #include "ash/wm/mru_window_tracker.h" 21 #include "ash/wm/mru_window_tracker.h"
22 #include "ash/wm/overview/overview_window_button.h"
22 #include "ash/wm/overview/window_grid.h" 23 #include "ash/wm/overview/window_grid.h"
23 #include "ash/wm/overview/window_selector.h" 24 #include "ash/wm/overview/window_selector.h"
24 #include "ash/wm/overview/window_selector_controller.h" 25 #include "ash/wm/overview/window_selector_controller.h"
25 #include "ash/wm/overview/window_selector_item.h" 26 #include "ash/wm/overview/window_selector_item.h"
26 #include "ash/wm/panels/panel_layout_manager.h" 27 #include "ash/wm/panels/panel_layout_manager.h"
27 #include "ash/wm/window_state.h" 28 #include "ash/wm/window_state.h"
28 #include "ash/wm/window_util.h" 29 #include "ash/wm/window_util.h"
29 #include "ash/wm/wm_event.h" 30 #include "ash/wm/wm_event.h"
30 #include "base/basictypes.h" 31 #include "base/basictypes.h"
31 #include "base/compiler_specific.h" 32 #include "base/compiler_specific.h"
32 #include "base/memory/scoped_vector.h" 33 #include "base/memory/scoped_vector.h"
33 #include "base/run_loop.h" 34 #include "base/run_loop.h"
34 #include "base/strings/string_piece.h" 35 #include "base/strings/string_piece.h"
35 #include "base/strings/utf_string_conversions.h" 36 #include "base/strings/utf_string_conversions.h"
36 #include "ui/aura/client/aura_constants.h" 37 #include "ui/aura/client/aura_constants.h"
37 #include "ui/aura/client/cursor_client.h" 38 #include "ui/aura/client/cursor_client.h"
38 #include "ui/aura/client/focus_client.h" 39 #include "ui/aura/client/focus_client.h"
39 #include "ui/aura/test/test_window_delegate.h" 40 #include "ui/aura/test/test_window_delegate.h"
40 #include "ui/aura/test/test_windows.h" 41 #include "ui/aura/test/test_windows.h"
41 #include "ui/aura/window.h" 42 #include "ui/aura/window.h"
42 #include "ui/aura/window_event_dispatcher.h" 43 #include "ui/aura/window_event_dispatcher.h"
43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 44 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
44 #include "ui/events/test/event_generator.h" 45 #include "ui/events/test/event_generator.h"
45 #include "ui/gfx/geometry/point_conversions.h" 46 #include "ui/gfx/geometry/point_conversions.h"
46 #include "ui/gfx/geometry/rect_conversions.h" 47 #include "ui/gfx/geometry/rect_conversions.h"
47 #include "ui/gfx/transform.h" 48 #include "ui/gfx/transform.h"
48 #include "ui/gfx/transform_util.h" 49 #include "ui/gfx/transform_util.h"
49 #include "ui/views/controls/label.h" 50 #include "ui/views/controls/button/label_button.h"
50 #include "ui/views/widget/native_widget_aura.h" 51 #include "ui/views/widget/native_widget_aura.h"
51 #include "ui/views/widget/widget_delegate.h" 52 #include "ui/views/widget/widget_delegate.h"
52 #include "ui/wm/core/window_util.h" 53 #include "ui/wm/core/window_util.h"
53 #include "ui/wm/public/activation_delegate.h" 54 #include "ui/wm/public/activation_delegate.h"
54 55
55 namespace ash { 56 namespace ash {
56 namespace { 57 namespace {
57 58
58 class NonActivatableActivationDelegate 59 class NonActivatableActivationDelegate
59 : public aura::client::ActivationDelegate { 60 : public aura::client::ActivationDelegate {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 WindowSelector* ws = ash::Shell::GetInstance()-> 208 WindowSelector* ws = ash::Shell::GetInstance()->
208 window_selector_controller()->window_selector_.get(); 209 window_selector_controller()->window_selector_.get();
209 return ws->text_filter_widget_->GetNativeWindow()->layer()-> 210 return ws->text_filter_widget_->GetNativeWindow()->layer()->
210 GetTargetTransform().IsIdentity(); 211 GetTargetTransform().IsIdentity();
211 } 212 }
212 213
213 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { 214 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) {
214 return &(window->close_button_widget_); 215 return &(window->close_button_widget_);
215 } 216 }
216 217
217 views::Label* GetLabelView(ash::WindowSelectorItem* window) { 218 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) {
218 return window->window_label_view_; 219 return static_cast<views::LabelButton*>(
220 window->overview_window_button_->window_label_->GetContentsView());
219 } 221 }
220 222
221 // Tests that a window is contained within a given WindowSelectorItem, and 223 // Tests that a window is contained within a given WindowSelectorItem, and
222 // that both the window and its matching close button are within the same 224 // that both the window and its matching close button are within the same
223 // screen. 225 // screen.
224 void IsWindowAndCloseButtonInScreen(aura::Window* window, 226 void IsWindowAndCloseButtonInScreen(aura::Window* window,
225 WindowSelectorItem* window_item) { 227 WindowSelectorItem* window_item) {
226 aura::Window* root_window = window_item->root_window(); 228 aura::Window* root_window = window_item->root_window();
227 EXPECT_TRUE(window_item->Contains(window)); 229 EXPECT_TRUE(window_item->Contains(window));
228 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( 230 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains(
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 gfx::Rect bounds = 341 gfx::Rect bounds =
340 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get())); 342 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get()));
341 ui::test::EventGenerator event_generator(window->GetRootWindow(), 343 ui::test::EventGenerator event_generator(window->GetRootWindow(),
342 bounds.CenterPoint()); 344 bounds.CenterPoint());
343 345
344 // Press down on the window. 346 // Press down on the window.
345 const int kTouchId = 19; 347 const int kTouchId = 19;
346 event_generator.PressTouchId(kTouchId); 348 event_generator.PressTouchId(kTouchId);
347 349
348 // Tap on the desktop, which should not cause a crash. Overview mode should 350 // Tap on the desktop, which should not cause a crash. Overview mode should
349 // remain engaged because the transparent widget over the window has capture. 351 // be disengaged.
350 event_generator.GestureTapAt(gfx::Point(0, 0)); 352 event_generator.GestureTapAt(gfx::Point(0, 0));
351 EXPECT_TRUE(IsSelecting()); 353 EXPECT_FALSE(IsSelecting());
352 354
353 event_generator.ReleaseTouchId(kTouchId); 355 event_generator.ReleaseTouchId(kTouchId);
354 } 356 }
355 357
356 // Tests that we do not crash and a window is selected when appropriate when 358 // Tests that we do not crash and a window is selected when appropriate when
357 // we click on a window during touch. 359 // we click on a window during touch.
358 TEST_F(WindowSelectorTest, ClickOnWindowDuringTouch) { 360 TEST_F(WindowSelectorTest, ClickOnWindowDuringTouch) {
359 gfx::Rect bounds(0, 0, 400, 400); 361 gfx::Rect bounds(0, 0, 400, 400);
360 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 362 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
361 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); 363 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
362 wm::ActivateWindow(window2.get()); 364 wm::ActivateWindow(window2.get());
363 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); 365 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
364 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); 366 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
365 367
366 ToggleOverview(); 368 ToggleOverview();
367 369
368 gfx::Rect window1_bounds = 370 gfx::Rect window1_bounds =
369 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window1.get())); 371 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window1.get()));
370 ui::test::EventGenerator event_generator(window1->GetRootWindow(), 372 ui::test::EventGenerator event_generator(window1->GetRootWindow(),
371 window1_bounds.CenterPoint()); 373 window1_bounds.CenterPoint());
372 374
373 // Clicking on |window2| while touching on |window1| should not cause a 375 // Clicking on |window2| while touching on |window1| should not cause a
374 // crash, and overview mode should remain engaged because |window1| 376 // crash, and |window2| should be selected.
375 // has capture.
376 const int kTouchId = 19; 377 const int kTouchId = 19;
377 event_generator.PressTouchId(kTouchId); 378 event_generator.PressTouchId(kTouchId);
378 event_generator.MoveMouseToCenterOf(window2.get()); 379 event_generator.MoveMouseToCenterOf(window2.get());
379 event_generator.ClickLeftButton(); 380 event_generator.ClickLeftButton();
380 EXPECT_TRUE(IsSelecting()); 381 EXPECT_FALSE(IsSelecting());
381 event_generator.ReleaseTouchId(kTouchId); 382 event_generator.ReleaseTouchId(kTouchId);
382 383
384 ToggleOverview();
385
383 // Clicking on |window1| while touching on |window1| should not cause 386 // Clicking on |window1| while touching on |window1| should not cause
384 // a crash, overview mode should be disengaged, and |window1| should 387 // a crash, overview mode should be disengaged, and |window1| should
385 // be active. 388 // be active.
386 event_generator.MoveMouseToCenterOf(window1.get()); 389 event_generator.MoveMouseToCenterOf(window1.get());
387 event_generator.PressTouchId(kTouchId); 390 event_generator.PressTouchId(kTouchId);
388 event_generator.ClickLeftButton(); 391 event_generator.ClickLeftButton();
389 EXPECT_FALSE(IsSelecting()); 392 EXPECT_FALSE(IsSelecting());
390 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); 393 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
391 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); 394 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
392 event_generator.ReleaseTouchId(kTouchId); 395 event_generator.ReleaseTouchId(kTouchId);
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 RunAllPendingInMessageLoop(); 906 RunAllPendingInMessageLoop();
904 } 907 }
905 908
906 // Test that a label is created under the window on entering overview mode. 909 // Test that a label is created under the window on entering overview mode.
907 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { 910 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) {
908 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); 911 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100)));
909 base::string16 window_title = base::UTF8ToUTF16("My window"); 912 base::string16 window_title = base::UTF8ToUTF16("My window");
910 window->SetTitle(window_title); 913 window->SetTitle(window_title);
911 ToggleOverview(); 914 ToggleOverview();
912 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); 915 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
913 views::Label* label = GetLabelView(window_item); 916 views::LabelButton* label = GetLabelButtonView(window_item);
914 // Has the label view been created? 917 // Has the label view been created?
915 ASSERT_TRUE(label); 918 ASSERT_TRUE(label);
916 919
917 // Verify the label matches the window title. 920 // Verify the label matches the window title.
918 EXPECT_EQ(label->text(), window_title); 921 EXPECT_EQ(label->GetText(), window_title);
919 922
920 // Update the window title and check that the label is updated, too. 923 // Update the window title and check that the label is updated, too.
921 base::string16 updated_title = base::UTF8ToUTF16("Updated title"); 924 base::string16 updated_title = base::UTF8ToUTF16("Updated title");
922 window->SetTitle(updated_title); 925 window->SetTitle(updated_title);
923 EXPECT_EQ(label->text(), updated_title); 926 EXPECT_EQ(label->GetText(), updated_title);
924 927
925 // Labels are located based on target_bounds, not the actual window item 928 // Labels are located based on target_bounds, not the actual window item
926 // bounds. 929 // bounds.
927 gfx::Rect target_bounds(window_item->target_bounds()); 930 gfx::Rect target_bounds(window_item->target_bounds());
928 gfx::Rect expected_label_bounds(target_bounds.x(), 931 gfx::Rect expected_label_bounds(target_bounds.x(),
929 target_bounds.bottom() - label-> 932 target_bounds.bottom() - label->
930 GetPreferredSize().height(), 933 GetPreferredSize().height(),
931 target_bounds.width(), 934 target_bounds.width(),
932 label->GetPreferredSize().height()); 935 label->GetPreferredSize().height());
933 gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds(); 936 gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds();
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 // Switch to overview mode. 1247 // Switch to overview mode.
1245 ToggleOverview(); 1248 ToggleOverview();
1246 ASSERT_TRUE(IsSelecting()); 1249 ASSERT_TRUE(IsSelecting());
1247 1250
1248 // Tap should now exit overview mode. 1251 // Tap should now exit overview mode.
1249 generator.GestureTapAt(point_in_background_page); 1252 generator.GestureTapAt(point_in_background_page);
1250 EXPECT_FALSE(IsSelecting()); 1253 EXPECT_FALSE(IsSelecting());
1251 } 1254 }
1252 1255
1253 } // namespace ash 1256 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector_item.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698