OLD | NEW |
(Empty) | |
| 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 "wm/foreign_window.h" |
| 6 |
| 7 #include "base/memory/ref_counted.h" |
| 8 #include "ui/aura/root_window.h" |
| 9 #include "ui/aura/window_tracker.h" |
| 10 #include "wm/foreign_test_window.h" |
| 11 #include "wm/test/wm_test_base.h" |
| 12 |
| 13 namespace wm { |
| 14 namespace test { |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Add all windows with ForeignWindows to |window_tracker|. |
| 19 void AddForeignWindowsToWindowTracker( |
| 20 aura::Window* window, |
| 21 aura::WindowTracker& window_tracker) { |
| 22 if (ForeignWindow::GetForeignWindowForNativeView(window)) |
| 23 window_tracker.Add(window); |
| 24 for (size_t i = 0; i < window->children().size(); ++i) |
| 25 AddForeignWindowsToWindowTracker(window->children()[i], window_tracker); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 typedef wm::test::WmTestBase ForeignWindowTest; |
| 31 |
| 32 // Test that aura windows are added and removed correctly when creating and |
| 33 // destroying foreign windows. |
| 34 TEST_F(ForeignWindowTest, AddRemove) { |
| 35 ForeignTestWindow::CreateParams params( |
| 36 ash::Shell::GetPrimaryRootWindow()->GetAcceleratedWidget()); |
| 37 scoped_ptr<ForeignTestWindow> test_window1(new ForeignTestWindow(params)); |
| 38 scoped_ptr<ForeignTestWindow> test_window2(new ForeignTestWindow(params)); |
| 39 test_window1->Sync(); |
| 40 test_window2->Sync(); |
| 41 RunAllPendingInMessageLoop(); |
| 42 aura::WindowTracker tracker; |
| 43 AddForeignWindowsToWindowTracker( |
| 44 ash::Shell::GetPrimaryRootWindow(), tracker); |
| 45 EXPECT_EQ(2u, tracker.windows().size()); |
| 46 test_window1->Destroy(); |
| 47 test_window1->Sync(); |
| 48 RunAllPendingInMessageLoop(); |
| 49 EXPECT_EQ(1u, tracker.windows().size()); |
| 50 test_window2->Destroy(); |
| 51 test_window2->Sync(); |
| 52 RunAllPendingInMessageLoop(); |
| 53 EXPECT_EQ(0u, tracker.windows().size()); |
| 54 } |
| 55 |
| 56 // Test that aura window properties are updated correctly when foreign |
| 57 // is mapped/unmapped. |
| 58 TEST_F(ForeignWindowTest, IsVisible) { |
| 59 ForeignTestWindow::CreateParams params( |
| 60 ash::Shell::GetPrimaryRootWindow()->GetAcceleratedWidget()); |
| 61 scoped_ptr<ForeignTestWindow> test_window(new ForeignTestWindow(params)); |
| 62 test_window->Sync(); |
| 63 RunAllPendingInMessageLoop(); |
| 64 aura::WindowTracker tracker; |
| 65 AddForeignWindowsToWindowTracker( |
| 66 ash::Shell::GetPrimaryRootWindow(), tracker); |
| 67 EXPECT_EQ(1u, tracker.windows().size()); |
| 68 EXPECT_FALSE((*tracker.windows().begin())->IsVisible()); |
| 69 test_window->Show(); |
| 70 test_window->Sync(); |
| 71 RunAllPendingInMessageLoop(); |
| 72 EXPECT_TRUE((*tracker.windows().begin())->IsVisible()); |
| 73 test_window->Hide(); |
| 74 test_window->Sync(); |
| 75 RunAllPendingInMessageLoop(); |
| 76 EXPECT_FALSE((*tracker.windows().begin())->IsVisible()); |
| 77 } |
| 78 |
| 79 } // namespace test |
| 80 } // namespace wm |
OLD | NEW |