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

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

Issue 358553004: Added text filtering to Overview Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thanks chrome team for helping me fix the previous patch Created 6 years, 5 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 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"
(...skipping 12 matching lines...) Expand all
23 #include "ash/wm/overview/window_selector_controller.h" 23 #include "ash/wm/overview/window_selector_controller.h"
24 #include "ash/wm/overview/window_selector_item.h" 24 #include "ash/wm/overview/window_selector_item.h"
25 #include "ash/wm/panels/panel_layout_manager.h" 25 #include "ash/wm/panels/panel_layout_manager.h"
26 #include "ash/wm/window_state.h" 26 #include "ash/wm/window_state.h"
27 #include "ash/wm/window_util.h" 27 #include "ash/wm/window_util.h"
28 #include "ash/wm/wm_event.h" 28 #include "ash/wm/wm_event.h"
29 #include "base/basictypes.h" 29 #include "base/basictypes.h"
30 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
31 #include "base/memory/scoped_vector.h" 31 #include "base/memory/scoped_vector.h"
32 #include "base/run_loop.h" 32 #include "base/run_loop.h"
33 #include "base/strings/string_piece.h"
33 #include "base/strings/utf_string_conversions.h" 34 #include "base/strings/utf_string_conversions.h"
34 #include "ui/aura/client/aura_constants.h" 35 #include "ui/aura/client/aura_constants.h"
35 #include "ui/aura/client/cursor_client.h" 36 #include "ui/aura/client/cursor_client.h"
36 #include "ui/aura/client/focus_client.h" 37 #include "ui/aura/client/focus_client.h"
37 #include "ui/aura/test/event_generator.h" 38 #include "ui/aura/test/event_generator.h"
38 #include "ui/aura/test/test_window_delegate.h" 39 #include "ui/aura/test/test_window_delegate.h"
39 #include "ui/aura/test/test_windows.h" 40 #include "ui/aura/test/test_windows.h"
40 #include "ui/aura/window.h" 41 #include "ui/aura/window.h"
41 #include "ui/aura/window_event_dispatcher.h" 42 #include "ui/aura/window_event_dispatcher.h"
42 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 43 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 WindowSelectorItem* window_item) { 218 WindowSelectorItem* window_item) {
218 aura::Window* root_window = window_item->GetRootWindow(); 219 aura::Window* root_window = window_item->GetRootWindow();
219 EXPECT_TRUE(window_item->Contains(window)); 220 EXPECT_TRUE(window_item->Contains(window));
220 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( 221 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains(
221 ToEnclosingRect(GetTransformedTargetBounds(window)))); 222 ToEnclosingRect(GetTransformedTargetBounds(window))));
222 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( 223 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains(
223 ToEnclosingRect(GetTransformedTargetBounds( 224 ToEnclosingRect(GetTransformedTargetBounds(
224 GetCloseButton(window_item)->GetNativeView())))); 225 GetCloseButton(window_item)->GetNativeView()))));
225 } 226 }
226 227
228 void FilterItems(const base::StringPiece& pattern) {
229 ash::Shell::GetInstance()->
230 window_selector_controller()->window_selector_.get()->
231 ContentsChanged(NULL, base::UTF8ToUTF16(pattern));
232 }
233
227 test::ShelfViewTestAPI* shelf_view_test() { 234 test::ShelfViewTestAPI* shelf_view_test() {
228 return shelf_view_test_.get(); 235 return shelf_view_test_.get();
229 } 236 }
230 237
238 views::Widget* text_filter_widget() {
239 return ash::Shell::GetInstance()->
240 window_selector_controller()->window_selector_.get()->
241 text_filter_widget_.get();
242 }
243
231 private: 244 private:
232 aura::test::TestWindowDelegate delegate_; 245 aura::test::TestWindowDelegate delegate_;
233 NonActivatableActivationDelegate non_activatable_activation_delegate_; 246 NonActivatableActivationDelegate non_activatable_activation_delegate_;
234 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; 247 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
235 248
236 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); 249 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
237 }; 250 };
238 251
239 // Tests that an a11y alert is sent on entering overview mode. 252 // Tests that an a11y alert is sent on entering overview mode.
240 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) { 253 TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) {
(...skipping 18 matching lines...) Expand all
259 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); 272 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds));
260 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); 273 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
261 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); 274 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
262 wm::ActivateWindow(window2.get()); 275 wm::ActivateWindow(window2.get());
263 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); 276 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
264 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); 277 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
265 EXPECT_EQ(window2.get(), GetFocusedWindow()); 278 EXPECT_EQ(window2.get(), GetFocusedWindow());
266 // Hide the cursor before entering overview to test that it will be shown. 279 // Hide the cursor before entering overview to test that it will be shown.
267 aura::client::GetCursorClient(root_window)->HideCursor(); 280 aura::client::GetCursorClient(root_window)->HideCursor();
268 281
269 // In overview mode the windows should no longer overlap and focus should 282 // In overview mode the windows should no longer overlap and the text filter
270 // be removed from the window. 283 // widget should be focused.
271 ToggleOverview(); 284 ToggleOverview();
272 EXPECT_EQ(NULL, GetFocusedWindow()); 285 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
273 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); 286 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
274 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get())); 287 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get()));
275 // Panels 1 and 2 should still be overlapping being in a single selector 288 // Panels 1 and 2 should still be overlapping being in a single selector
276 // item. 289 // item.
277 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); 290 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get()));
278 291
279 // Clicking window 1 should activate it. 292 // Clicking window 1 should activate it.
280 ClickWindow(window1.get()); 293 ClickWindow(window1.get());
281 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); 294 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
282 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); 295 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
283 EXPECT_EQ(window1.get(), GetFocusedWindow()); 296 EXPECT_EQ(window1.get(), GetFocusedWindow());
284 297
285 // Cursor should have been unlocked. 298 // Cursor should have been unlocked.
286 EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked()); 299 EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked());
287 } 300 }
288 301
289 // Tests selecting a window by tapping on it. 302 // Tests selecting a window by tapping on it.
290 TEST_F(WindowSelectorTest, BasicGesture) { 303 TEST_F(WindowSelectorTest, BasicGesture) {
291 gfx::Rect bounds(0, 0, 400, 400); 304 gfx::Rect bounds(0, 0, 400, 400);
292 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 305 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
293 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); 306 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
294 wm::ActivateWindow(window1.get()); 307 wm::ActivateWindow(window1.get());
295 EXPECT_EQ(window1.get(), GetFocusedWindow()); 308 EXPECT_EQ(window1.get(), GetFocusedWindow());
296 ToggleOverview(); 309 ToggleOverview();
297 EXPECT_EQ(NULL, GetFocusedWindow()); 310 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
298 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 311 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
299 window2.get()); 312 window2.get());
300 generator.GestureTapAt(gfx::ToEnclosingRect( 313 generator.GestureTapAt(gfx::ToEnclosingRect(
301 GetTransformedTargetBounds(window2.get())).CenterPoint()); 314 GetTransformedTargetBounds(window2.get())).CenterPoint());
302 EXPECT_EQ(window2.get(), GetFocusedWindow()); 315 EXPECT_EQ(window2.get(), GetFocusedWindow());
303 } 316 }
304 317
305 // Tests that a window does not receive located events when in overview mode. 318 // Tests that a window does not receive located events when in overview mode.
306 TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) { 319 TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) {
307 gfx::Rect window_bounds(20, 10, 200, 300); 320 gfx::Rect window_bounds(20, 10, 200, 300);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 508 }
496 509
497 // Tests that exiting overview mode without selecting a window restores focus 510 // Tests that exiting overview mode without selecting a window restores focus
498 // to the previously focused window. 511 // to the previously focused window.
499 TEST_F(WindowSelectorTest, CancelRestoresFocus) { 512 TEST_F(WindowSelectorTest, CancelRestoresFocus) {
500 gfx::Rect bounds(0, 0, 400, 400); 513 gfx::Rect bounds(0, 0, 400, 400);
501 scoped_ptr<aura::Window> window(CreateWindow(bounds)); 514 scoped_ptr<aura::Window> window(CreateWindow(bounds));
502 wm::ActivateWindow(window.get()); 515 wm::ActivateWindow(window.get());
503 EXPECT_EQ(window.get(), GetFocusedWindow()); 516 EXPECT_EQ(window.get(), GetFocusedWindow());
504 517
505 // In overview mode, focus should be removed. 518 // In overview mode, the text filter widget should be focused.
506 ToggleOverview(); 519 ToggleOverview();
507 EXPECT_EQ(NULL, GetFocusedWindow()); 520 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
508 521
509 // If canceling overview mode, focus should be restored. 522 // If canceling overview mode, focus should be restored.
510 ToggleOverview(); 523 ToggleOverview();
511 EXPECT_EQ(window.get(), GetFocusedWindow()); 524 EXPECT_EQ(window.get(), GetFocusedWindow());
512 } 525 }
513 526
514 // Tests that overview mode is exited if the last remaining window is destroyed. 527 // Tests that overview mode is exited if the last remaining window is destroyed.
515 TEST_F(WindowSelectorTest, LastWindowDestroyed) { 528 TEST_F(WindowSelectorTest, LastWindowDestroyed) {
516 gfx::Rect bounds(0, 0, 400, 400); 529 gfx::Rect bounds(0, 0, 400, 400);
517 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); 530 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1); 1020 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1);
1008 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2); 1021 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2);
1009 1022
1010 EXPECT_FALSE(widget2->IsClosed()); 1023 EXPECT_FALSE(widget2->IsClosed());
1011 event_generator2.ClickLeftButton(); 1024 event_generator2.ClickLeftButton();
1012 EXPECT_TRUE(widget2->IsClosed()); 1025 EXPECT_TRUE(widget2->IsClosed());
1013 RunAllPendingInMessageLoop(); 1026 RunAllPendingInMessageLoop();
1014 EXPECT_FALSE(IsSelecting()); 1027 EXPECT_FALSE(IsSelecting());
1015 } 1028 }
1016 1029
1030 // Creates three windows and tests filtering them by title.
1031 TEST_F(WindowSelectorTest, BasicTextFiltering) {
1032 gfx::Rect bounds(0, 0, 100, 100);
1033 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
1034 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
1035 scoped_ptr<aura::Window> window0(CreateWindow(bounds));
1036 base::string16 window2_title = base::UTF8ToUTF16("Test - Wikipedia");
1037 base::string16 window1_title = base::UTF8ToUTF16("For those about to test");
1038 base::string16 window0_title = base::UTF8ToUTF16("We salute you");
1039 window0->set_title(window0_title);
1040 window1->set_title(window1_title);
1041 window2->set_title(window2_title);
1042 ToggleOverview();
1043 FilterItems("Test");
1044
1045 std::vector<WindowSelectorItem*> items = GetWindowItemsForRoot(0);
1046
1047 EXPECT_TRUE(items[0]->dimmed());
1048 EXPECT_FALSE(items[1]->dimmed());
1049 EXPECT_FALSE(items[2]->dimmed());
1050 }
flackr 2014/06/27 20:00:07 Cool, nice and simple! Maybe a few more tests lik
Nina 2014/06/27 22:42:02 There's a v2 of this which you might want to see a
1051
1017 } // namespace ash 1052 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698