sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 1 | // Copyright 2017 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 "ash/public/cpp/config.h" |
| 6 | #include "ash/shell.h" |
| 7 | #include "ash/test/ash_test_base.h" |
| 8 | #include "ash/test/ash_test_helper.h" |
| 9 | #include "ui/aura/test/mus/test_window_manager_client.h" |
| 10 | #include "ui/aura/test/mus/test_window_tree.h" |
| 11 | #include "ui/aura/test/mus/test_window_tree_client_setup.h" |
| 12 | #include "ui/aura/window.h" |
| 13 | |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 14 | namespace ash { |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 15 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 16 | using WindowManagerCommonTest = AshTestBase; |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 17 | |
James Cook | d7ea4d3 | 2017-12-08 00:53:39 | [diff] [blame] | 18 | // TODO(jamescook): Move into one of the existing WindowManager test suites. |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 19 | TEST_F(WindowManagerCommonTest, Focus) { |
| 20 | if (Shell::GetAshConfig() == Config::CLASSIC) |
| 21 | return; |
| 22 | |
| 23 | // Ensure that activation parents have been added, an ancestor of |window| |
| 24 | // must support activation for the focus attempt below to succeed. |
| 25 | aura::TestWindowManagerClient* test_window_manager_client = |
| 26 | ash_test_helper() |
| 27 | ->window_tree_client_setup() |
| 28 | ->test_window_manager_client(); |
| 29 | EXPECT_LT(0u, |
| 30 | test_window_manager_client->GetChangeCountForType( |
| 31 | aura::WindowManagerClientChangeType::ADD_ACTIVATION_PARENT)); |
| 32 | |
| 33 | // Ensure a call to Window::Focus() makes it way to the WindowTree. |
| 34 | std::unique_ptr<aura::Window> window = CreateTestWindow(); |
| 35 | aura::TestWindowTree* test_window_tree = |
| 36 | ash_test_helper()->window_tree_client_setup()->window_tree(); |
| 37 | const size_t initial_focus_count = test_window_tree->GetChangeCountForType( |
| 38 | aura::WindowTreeChangeType::FOCUS); |
| 39 | window->Focus(); |
| 40 | EXPECT_TRUE(window->HasFocus()); |
| 41 | EXPECT_EQ(initial_focus_count + 1, test_window_tree->GetChangeCountForType( |
| 42 | aura::WindowTreeChangeType::FOCUS)); |
| 43 | } |
| 44 | |
sky | 6861271 | 2017-04-27 04:45:04 | [diff] [blame] | 45 | } // namespace ash |