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 "ui/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 delegate ? delegate : | 95 delegate ? delegate : |
96 test::TestWindowDelegate::CreateSelfDestroyingDelegate()); | 96 test::TestWindowDelegate::CreateSelfDestroyingDelegate()); |
97 window->set_id(id); | 97 window->set_id(id); |
98 window->Init(ui::LAYER_TEXTURED); | 98 window->Init(ui::LAYER_TEXTURED); |
99 window->SetParent(parent); | 99 window->SetParent(parent); |
100 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 100 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
101 window->Show(); | 101 window->Show(); |
102 return window; | 102 return window; |
103 } | 103 } |
104 | 104 |
| 105 bool IsFocusedWindow(aura::Window* window) { |
| 106 return client::GetFocusClient(window)->GetFocusedWindow() == window; |
| 107 } |
| 108 |
105 } // namespace | 109 } // namespace |
106 | 110 |
107 typedef test::AuraTestBase RootWindowTest; | 111 typedef test::AuraTestBase RootWindowTest; |
108 | 112 |
109 TEST_F(RootWindowTest, OnHostMouseEvent) { | 113 TEST_F(RootWindowTest, OnHostMouseEvent) { |
110 // Create two non-overlapping windows so we don't have to worry about which | 114 // Create two non-overlapping windows so we don't have to worry about which |
111 // is on top. | 115 // is on top. |
112 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); | 116 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
113 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); | 117 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
114 const int kWindowWidth = 123; | 118 const int kWindowWidth = 123; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 client.GetNonLockWindow()); | 330 client.GetNonLockWindow()); |
327 w1->set_id(1); | 331 w1->set_id(1); |
328 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20), | 332 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20), |
329 client.GetNonLockWindow()); | 333 client.GetNonLockWindow()); |
330 w2->set_id(2); | 334 w2->set_id(2); |
331 scoped_ptr<Window> w3( | 335 scoped_ptr<Window> w3( |
332 test::CreateTestWindowWithDelegate(&d, 3, gfx::Rect(30, 30, 20, 20), | 336 test::CreateTestWindowWithDelegate(&d, 3, gfx::Rect(30, 30, 20, 20), |
333 client.GetLockWindow())); | 337 client.GetLockWindow())); |
334 | 338 |
335 w1->Focus(); | 339 w1->Focus(); |
336 EXPECT_TRUE(w1->GetFocusManager()->IsFocusedWindow(w1)); | 340 EXPECT_TRUE(IsFocusedWindow(w1)); |
337 | 341 |
338 client.Lock(); | 342 client.Lock(); |
339 | 343 |
340 // Since we're locked, the attempt to focus w2 will be ignored. | 344 // Since we're locked, the attempt to focus w2 will be ignored. |
341 w2->Focus(); | 345 w2->Focus(); |
342 EXPECT_TRUE(w1->GetFocusManager()->IsFocusedWindow(w1)); | 346 EXPECT_TRUE(IsFocusedWindow(w1)); |
343 EXPECT_FALSE(w1->GetFocusManager()->IsFocusedWindow(w2)); | 347 EXPECT_FALSE(IsFocusedWindow(w2)); |
344 | 348 |
345 { | 349 { |
346 // Attempting to send a key event to w1 (not in the lock container) should | 350 // Attempting to send a key event to w1 (not in the lock container) should |
347 // cause focus to be reset. | 351 // cause focus to be reset. |
348 test::EventGenerator generator(root_window()); | 352 test::EventGenerator generator(root_window()); |
349 generator.PressKey(ui::VKEY_SPACE, 0); | 353 generator.PressKey(ui::VKEY_SPACE, 0); |
350 EXPECT_EQ(NULL, w1->GetFocusManager()->GetFocusedWindow()); | 354 EXPECT_EQ(NULL, client::GetFocusClient(w1)->GetFocusedWindow()); |
351 } | 355 } |
352 | 356 |
353 { | 357 { |
354 // Events sent to a window not in the lock container will not be processed. | 358 // Events sent to a window not in the lock container will not be processed. |
355 // i.e. never sent to the non-lock container's event filter. | 359 // i.e. never sent to the non-lock container's event filter. |
356 test::EventGenerator generator(root_window(), w1); | 360 test::EventGenerator generator(root_window(), w1); |
357 generator.PressLeftButton(); | 361 generator.PressLeftButton(); |
358 EXPECT_EQ(0, nonlock_ef->num_mouse_events()); | 362 EXPECT_EQ(0, nonlock_ef->num_mouse_events()); |
359 | 363 |
360 // Events sent to a window in the lock container will be processed. | 364 // Events sent to a window in the lock container will be processed. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 TEST_F(RootWindowTest, DeleteWindowDuringDispatch) { | 699 TEST_F(RootWindowTest, DeleteWindowDuringDispatch) { |
696 // Verifies that we can delete a window during each phase of event handling. | 700 // Verifies that we can delete a window during each phase of event handling. |
697 // Deleting the window should not cause a crash, only prevent further | 701 // Deleting the window should not cause a crash, only prevent further |
698 // processing from occurring. | 702 // processing from occurring. |
699 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 703 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
700 DeletingWindowDelegate d11; | 704 DeletingWindowDelegate d11; |
701 Window* w11 = CreateWindow(11, w1.get(), &d11); | 705 Window* w11 = CreateWindow(11, w1.get(), &d11); |
702 WindowTracker tracker; | 706 WindowTracker tracker; |
703 DeletingEventFilter* w1_filter = new DeletingEventFilter; | 707 DeletingEventFilter* w1_filter = new DeletingEventFilter; |
704 w1->SetEventFilter(w1_filter); | 708 w1->SetEventFilter(w1_filter); |
705 w1->GetFocusManager()->SetFocusedWindow(w11, NULL); | 709 client::GetFocusClient(w1.get())->FocusWindow(w11, NULL); |
706 | 710 |
707 test::EventGenerator generator(root_window(), w11); | 711 test::EventGenerator generator(root_window(), w11); |
708 | 712 |
709 // First up, no one deletes anything. | 713 // First up, no one deletes anything. |
710 tracker.Add(w11); | 714 tracker.Add(w11); |
711 d11.Reset(w11, false); | 715 d11.Reset(w11, false); |
712 | 716 |
713 generator.PressLeftButton(); | 717 generator.PressLeftButton(); |
714 EXPECT_TRUE(tracker.Contains(w11)); | 718 EXPECT_TRUE(tracker.Contains(w11)); |
715 EXPECT_TRUE(d11.got_event()); | 719 EXPECT_TRUE(d11.got_event()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { | 768 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { |
765 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 769 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
766 DetachesParentOnTapDelegate delegate; | 770 DetachesParentOnTapDelegate delegate; |
767 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); | 771 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); |
768 Window* child = CreateWindow(11, parent.get(), &delegate); | 772 Window* child = CreateWindow(11, parent.get(), &delegate); |
769 test::EventGenerator generator(root_window(), child); | 773 test::EventGenerator generator(root_window(), child); |
770 generator.GestureTapAt(gfx::Point(40, 40)); | 774 generator.GestureTapAt(gfx::Point(40, 40)); |
771 } | 775 } |
772 | 776 |
773 } // namespace aura | 777 } // namespace aura |
OLD | NEW |