1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/aura/window_targeter.h" 6 7 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/test_event_handler.h" 9 #include "ui/aura/test/test_window_delegate.h" 10 #include "ui/aura/window.h" 11 12 namespace aura { 13 14 class WindowTargeterTest : public test::AuraTestBase { 15 public: 16 WindowTargeterTest() {} 17 virtual ~WindowTargeterTest() {} 18 19 Window* root_window() { return AuraTestBase::root_window(); } 20 }; 21 22 TEST_F(WindowTargeterTest, Basic) { 23 test::TestWindowDelegate delegate; 24 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate)); 25 Window* one = CreateNormalWindow(2, window.get(), &delegate); 26 Window* two = CreateNormalWindow(3, window.get(), &delegate); 27 28 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 29 one->SetBounds(gfx::Rect(0, 0, 500, 100)); 30 two->SetBounds(gfx::Rect(501, 0, 500, 1000)); 31 32 root_window()->Show(); 33 34 test::TestEventHandler handler; 35 one->AddPreTargetHandler(&handler); 36 37 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, 38 gfx::Point(20, 20), 39 gfx::Point(20, 20), 40 ui::EF_NONE); 41 root_window()->GetDispatcher()->AsRootWindowHostDelegate()-> 42 OnHostMouseEvent(&press); 43 EXPECT_EQ(1, handler.num_mouse_events()); 44 45 handler.Reset(); 46 ui::EventDispatchDetails details = 47 root_window()->GetDispatcher()->OnEventFromSource(&press); 48 EXPECT_FALSE(details.dispatcher_destroyed); 49 EXPECT_EQ(1, handler.num_mouse_events()); 50 51 one->RemovePreTargetHandler(&handler); 52 } 53 54 } // namespace aura 55