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(ash::Shell::GetPrimaryRootWindow()); |
| 36 scoped_ptr<ForeignTestWindow> test_window1(new ForeignTestWindow(params)); |
| 37 scoped_ptr<ForeignTestWindow> test_window2(new ForeignTestWindow(params)); |
| 38 test_window1->Sync(); |
| 39 test_window2->Sync(); |
| 40 RunAllPendingInMessageLoop(); |
| 41 aura::WindowTracker tracker; |
| 42 AddForeignWindowsToWindowTracker( |
| 43 ash::Shell::GetPrimaryRootWindow(), tracker); |
| 44 EXPECT_EQ(2u, tracker.windows().size()); |
| 45 test_window1->Destroy(); |
| 46 test_window1->Sync(); |
| 47 RunAllPendingInMessageLoop(); |
| 48 EXPECT_EQ(1u, tracker.windows().size()); |
| 49 test_window2->Destroy(); |
| 50 test_window2->Sync(); |
| 51 RunAllPendingInMessageLoop(); |
| 52 EXPECT_EQ(0u, tracker.windows().size()); |
| 53 } |
| 54 |
| 55 // Test that aura window properties are updated correctly when foreign |
| 56 // is mapped/unmapped. |
| 57 TEST_F(ForeignWindowTest, IsVisible) { |
| 58 ForeignTestWindow::CreateParams params(ash::Shell::GetPrimaryRootWindow()); |
| 59 scoped_ptr<ForeignTestWindow> test_window(new ForeignTestWindow(params)); |
| 60 test_window->Sync(); |
| 61 RunAllPendingInMessageLoop(); |
| 62 aura::WindowTracker tracker; |
| 63 AddForeignWindowsToWindowTracker( |
| 64 ash::Shell::GetPrimaryRootWindow(), tracker); |
| 65 EXPECT_EQ(1u, tracker.windows().size()); |
| 66 EXPECT_FALSE((*tracker.windows().begin())->IsVisible()); |
| 67 test_window->Show(); |
| 68 test_window->Sync(); |
| 69 RunAllPendingInMessageLoop(); |
| 70 EXPECT_TRUE((*tracker.windows().begin())->IsVisible()); |
| 71 test_window->Hide(); |
| 72 test_window->Sync(); |
| 73 RunAllPendingInMessageLoop(); |
| 74 EXPECT_FALSE((*tracker.windows().begin())->IsVisible()); |
| 75 } |
| 76 |
| 77 } // namespace test |
| 78 } // namespace wm |
OLD | NEW |