OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ASSERT_EQ(3u, parent.children().size()); | 364 ASSERT_EQ(3u, parent.children().size()); |
365 EXPECT_EQ(&child2, parent.children()[0]); | 365 EXPECT_EQ(&child2, parent.children()[0]); |
366 EXPECT_EQ(&child1, parent.children()[1]); | 366 EXPECT_EQ(&child1, parent.children()[1]); |
367 EXPECT_EQ(&child3, parent.children()[2]); | 367 EXPECT_EQ(&child3, parent.children()[2]); |
368 ASSERT_EQ(3u, parent.layer()->children().size()); | 368 ASSERT_EQ(3u, parent.layer()->children().size()); |
369 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 369 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
370 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 370 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
371 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); | 371 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); |
372 } | 372 } |
373 | 373 |
374 // Various destruction assertions. | 374 // Various capture assertions. |
375 TEST_F(WindowTest, CaptureTests) { | 375 TEST_F(WindowTest, CaptureTests) { |
376 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | 376 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
377 CaptureWindowDelegateImpl delegate; | 377 CaptureWindowDelegateImpl delegate; |
378 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 378 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
379 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 379 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
380 EXPECT_FALSE(window->HasCapture()); | 380 EXPECT_FALSE(window->HasCapture()); |
381 | 381 |
382 // Do a capture. | 382 // Do a capture. |
383 window->SetCapture(); | 383 window->SetCapture(); |
384 EXPECT_TRUE(window->HasCapture()); | 384 EXPECT_TRUE(window->HasCapture()); |
(...skipping 23 matching lines...) Expand all Loading... |
408 | 408 |
409 // Removing the capture window from parent should reset the capture window | 409 // Removing the capture window from parent should reset the capture window |
410 // in the root window. | 410 // in the root window. |
411 window->SetCapture(); | 411 window->SetCapture(); |
412 EXPECT_EQ(window.get(), root_window->capture_window()); | 412 EXPECT_EQ(window.get(), root_window->capture_window()); |
413 window->parent()->RemoveChild(window.get()); | 413 window->parent()->RemoveChild(window.get()); |
414 EXPECT_FALSE(window->HasCapture()); | 414 EXPECT_FALSE(window->HasCapture()); |
415 EXPECT_EQ(NULL, root_window->capture_window()); | 415 EXPECT_EQ(NULL, root_window->capture_window()); |
416 } | 416 } |
417 | 417 |
| 418 // Changes capture while capture is already ongoing. |
| 419 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { |
| 420 CaptureWindowDelegateImpl delegate; |
| 421 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| 422 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 423 CaptureWindowDelegateImpl delegate2; |
| 424 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 425 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); |
| 426 EXPECT_FALSE(window->HasCapture()); |
| 427 |
| 428 // Do a capture. |
| 429 window->SetCapture(); |
| 430 delegate.set_mouse_event_count(0); |
| 431 EXPECT_TRUE(window->HasCapture()); |
| 432 EXPECT_EQ(0, delegate.capture_lost_count()); |
| 433 EventGenerator generator(gfx::Point(50, 50)); |
| 434 generator.PressLeftButton(); |
| 435 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 436 delegate.set_mouse_event_count(0); |
| 437 |
| 438 // Reset the capture. |
| 439 window->ReleaseCapture(); |
| 440 w2->SetCapture(); |
| 441 delegate2.set_mouse_event_count(0); |
| 442 generator.MoveMouseTo(gfx::Point(40, 40)); |
| 443 EXPECT_EQ(0, delegate.mouse_event_count()); |
| 444 EXPECT_EQ(2, delegate2.mouse_event_count()); |
| 445 } |
| 446 |
418 // Verifies capture is reset when a window is destroyed. | 447 // Verifies capture is reset when a window is destroyed. |
419 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { | 448 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { |
420 RootWindow* root_window = RootWindow::GetInstance(); | 449 RootWindow* root_window = RootWindow::GetInstance(); |
421 CaptureWindowDelegateImpl delegate; | 450 CaptureWindowDelegateImpl delegate; |
422 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 451 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
423 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 452 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
424 EXPECT_FALSE(window->HasCapture()); | 453 EXPECT_FALSE(window->HasCapture()); |
425 | 454 |
426 // Do a capture. | 455 // Do a capture. |
427 window->SetCapture(); | 456 window->SetCapture(); |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 | 1167 |
1139 w3->Activate(); | 1168 w3->Activate(); |
1140 EXPECT_EQ(w2.get(), active()); | 1169 EXPECT_EQ(w2.get(), active()); |
1141 | 1170 |
1142 w1->Activate(); | 1171 w1->Activate(); |
1143 EXPECT_EQ(w1.get(), active()); | 1172 EXPECT_EQ(w1.get(), active()); |
1144 } | 1173 } |
1145 | 1174 |
1146 } // namespace test | 1175 } // namespace test |
1147 } // namespace aura | 1176 } // namespace aura |
OLD | NEW |