| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // How many mouse events have been received? | 120 // How many mouse events have been received? |
| 121 int num_mouse_events_; | 121 int num_mouse_events_; |
| 122 | 122 |
| 123 int num_touch_events_; | 123 int num_touch_events_; |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(EventCountFilter); | 125 DISALLOW_COPY_AND_ASSIGN(EventCountFilter); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { | 128 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { |
| 129 Window* window = | 129 Window* window = new Window( |
| 130 new Window(delegate ? delegate : new test::TestWindowDelegate); | 130 delegate ? delegate : |
| 131 test::TestWindowDelegate::CreateSelfDestroyingDelegate()); |
| 131 window->set_id(id); | 132 window->set_id(id); |
| 132 window->Init(ui::LAYER_TEXTURED); | 133 window->Init(ui::LAYER_TEXTURED); |
| 133 window->SetParent(parent); | 134 window->SetParent(parent); |
| 134 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 135 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 135 window->Show(); | 136 window->Show(); |
| 136 return window; | 137 return window; |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace | 140 } // namespace |
| 140 | 141 |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 bool got_event_; | 700 bool got_event_; |
| 700 | 701 |
| 701 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); | 702 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); |
| 702 }; | 703 }; |
| 703 | 704 |
| 704 TEST_F(RootWindowTest, DeleteWindowDuringDispatch) { | 705 TEST_F(RootWindowTest, DeleteWindowDuringDispatch) { |
| 705 // Verifies that we can delete a window during each phase of event handling. | 706 // Verifies that we can delete a window during each phase of event handling. |
| 706 // Deleting the window should not cause a crash, only prevent further | 707 // Deleting the window should not cause a crash, only prevent further |
| 707 // processing from occurring. | 708 // processing from occurring. |
| 708 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 709 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
| 709 DeletingWindowDelegate* d11 = new DeletingWindowDelegate; | 710 DeletingWindowDelegate d11; |
| 710 Window* w11 = CreateWindow(11, w1.get(), d11); | 711 Window* w11 = CreateWindow(11, w1.get(), &d11); |
| 711 WindowTracker tracker; | 712 WindowTracker tracker; |
| 712 DeletingEventFilter* w1_filter = new DeletingEventFilter; | 713 DeletingEventFilter* w1_filter = new DeletingEventFilter; |
| 713 w1->SetEventFilter(w1_filter); | 714 w1->SetEventFilter(w1_filter); |
| 714 w1->GetFocusManager()->SetFocusedWindow(w11, NULL); | 715 w1->GetFocusManager()->SetFocusedWindow(w11, NULL); |
| 715 | 716 |
| 716 test::EventGenerator generator(root_window(), w11); | 717 test::EventGenerator generator(root_window(), w11); |
| 717 | 718 |
| 718 // First up, no one deletes anything. | 719 // First up, no one deletes anything. |
| 719 tracker.Add(w11); | 720 tracker.Add(w11); |
| 720 d11->Reset(w11, false); | 721 d11.Reset(w11, false); |
| 721 | 722 |
| 722 generator.PressLeftButton(); | 723 generator.PressLeftButton(); |
| 723 EXPECT_TRUE(tracker.Contains(w11)); | 724 EXPECT_TRUE(tracker.Contains(w11)); |
| 724 EXPECT_TRUE(d11->got_event()); | 725 EXPECT_TRUE(d11.got_event()); |
| 725 generator.ReleaseLeftButton(); | 726 generator.ReleaseLeftButton(); |
| 726 | 727 |
| 727 // Delegate deletes w11. This will prevent the post-handle step from applying. | 728 // Delegate deletes w11. This will prevent the post-handle step from applying. |
| 728 w1_filter->Reset(false); | 729 w1_filter->Reset(false); |
| 729 d11->Reset(w11, true); | 730 d11.Reset(w11, true); |
| 730 generator.PressKey(ui::VKEY_A, 0); | 731 generator.PressKey(ui::VKEY_A, 0); |
| 731 EXPECT_FALSE(tracker.Contains(w11)); | 732 EXPECT_FALSE(tracker.Contains(w11)); |
| 732 EXPECT_TRUE(d11->got_event()); | 733 EXPECT_TRUE(d11.got_event()); |
| 733 | 734 |
| 734 // Pre-handle step deletes w11. This will prevent the delegate and the post- | 735 // Pre-handle step deletes w11. This will prevent the delegate and the post- |
| 735 // handle steps from applying. | 736 // handle steps from applying. |
| 736 w11 = CreateWindow(11, w1.get(), d11); | 737 w11 = CreateWindow(11, w1.get(), &d11); |
| 737 w1_filter->Reset(true); | 738 w1_filter->Reset(true); |
| 738 d11->Reset(w11, false); | 739 d11.Reset(w11, false); |
| 739 generator.PressLeftButton(); | 740 generator.PressLeftButton(); |
| 740 EXPECT_FALSE(tracker.Contains(w11)); | 741 EXPECT_FALSE(tracker.Contains(w11)); |
| 741 EXPECT_FALSE(d11->got_event()); | 742 EXPECT_FALSE(d11.got_event()); |
| 742 } | 743 } |
| 743 | 744 |
| 744 } // namespace aura | 745 } // namespace aura |
| OLD | NEW |