OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/mus/top_level_window_factory.h" | 5 #include "ash/mus/top_level_window_factory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "ash/mus/test/wm_test_base.h" | |
14 #include "ash/mus/window_manager.h" | 13 #include "ash/mus/window_manager.h" |
15 #include "ash/mus/window_manager_application.h" | 14 #include "ash/mus/window_manager_application.h" |
16 #include "ash/shell_port.h" | 15 #include "ash/shell.h" |
17 #include "ash/test/ash_test.h" | 16 #include "ash/test/ash_test.h" |
18 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
19 #include "ash/test/ash_test_helper.h" | 18 #include "ash/test/ash_test_helper.h" |
20 #include "ash/wm_window.h" | 19 #include "ash/wm/window_properties.h" |
| 20 #include "services/ui/public/cpp/property_type_converters.h" |
| 21 #include "ui/aura/mus/property_converter.h" |
21 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
22 #include "ui/display/screen.h" | 23 #include "ui/display/screen.h" |
| 24 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gfx/test/gfx_util.h" |
| 26 #include "ui/wm/core/window_util.h" |
23 | 27 |
24 namespace ash { | 28 namespace ash { |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
28 int64_t GetDisplayId(aura::Window* window) { | 32 int64_t GetDisplayId(aura::Window* window) { |
29 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); | 33 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); |
30 } | 34 } |
31 | 35 |
| 36 aura::Window* CreateFullscreenTestWindow(mus::WindowManager* window_manager, |
| 37 int64_t display_id) { |
| 38 std::map<std::string, std::vector<uint8_t>> properties; |
| 39 properties[ui::mojom::WindowManager::kShowState_Property] = |
| 40 mojo::ConvertTo<std::vector<uint8_t>>( |
| 41 static_cast<aura::PropertyConverter::PrimitiveType>( |
| 42 ui::mojom::ShowState::FULLSCREEN)); |
| 43 if (display_id != display::kInvalidDisplayId) { |
| 44 properties[ui::mojom::WindowManager::kDisplayId_InitProperty] = |
| 45 mojo::ConvertTo<std::vector<uint8_t>>(display_id); |
| 46 } |
| 47 aura::Window* window = mus::CreateAndParentTopLevelWindow( |
| 48 window_manager, ui::mojom::WindowType::WINDOW, &properties); |
| 49 window->Show(); |
| 50 return window; |
| 51 } |
| 52 |
32 } // namespace | 53 } // namespace |
33 | 54 |
34 using TopLevelWindowFactoryTest = AshTest; | 55 using TopLevelWindowFactoryTest = test::AshTestBase; |
35 | 56 |
36 TEST_F(TopLevelWindowFactoryTest, CreateFullscreenWindow) { | 57 TEST_F(TopLevelWindowFactoryTest, CreateFullscreenWindow) { |
37 std::unique_ptr<WindowOwner> window_owner = CreateToplevelTestWindow(); | 58 std::unique_ptr<aura::Window> window = CreateTestWindow(); |
38 WmWindow* window = window_owner->window(); | 59 ::wm::SetWindowFullscreen(window.get(), true); |
39 window->SetFullscreen(true); | 60 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
40 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow(); | 61 EXPECT_EQ(root_window->bounds(), window->bounds()); |
41 EXPECT_EQ(root_window->GetBounds(), window->GetBounds()); | |
42 } | 62 } |
43 | 63 |
44 using TopLevelWindowFactoryWmTest = mus::WmTestBase; | 64 using TopLevelWindowFactoryWmTest = test::AshTestBase; |
45 | 65 |
46 TEST_F(TopLevelWindowFactoryWmTest, IsWindowShownInCorrectDisplay) { | 66 TEST_F(TopLevelWindowFactoryWmTest, IsWindowShownInCorrectDisplay) { |
47 UpdateDisplay("400x400,400x400"); | 67 UpdateDisplay("400x400,400x400"); |
48 EXPECT_NE(GetPrimaryDisplay().id(), GetSecondaryDisplay().id()); | 68 EXPECT_NE(GetPrimaryDisplay().id(), GetSecondaryDisplay().id()); |
49 | 69 |
| 70 mus::WindowManager* window_manager = |
| 71 ash_test_helper()->window_manager_app()->window_manager(); |
| 72 |
50 std::unique_ptr<aura::Window> window_primary_display( | 73 std::unique_ptr<aura::Window> window_primary_display( |
51 CreateFullscreenTestWindow(GetPrimaryDisplay().id())); | 74 CreateFullscreenTestWindow(window_manager, GetPrimaryDisplay().id())); |
52 std::unique_ptr<aura::Window> window_secondary_display( | 75 std::unique_ptr<aura::Window> window_secondary_display( |
53 CreateFullscreenTestWindow(GetSecondaryDisplay().id())); | 76 CreateFullscreenTestWindow(window_manager, GetSecondaryDisplay().id())); |
54 | 77 |
55 EXPECT_EQ(GetPrimaryDisplay().id(), | 78 EXPECT_EQ(GetPrimaryDisplay().id(), |
56 GetDisplayId(window_primary_display.get())); | 79 GetDisplayId(window_primary_display.get())); |
57 EXPECT_EQ(GetSecondaryDisplay().id(), | 80 EXPECT_EQ(GetSecondaryDisplay().id(), |
58 GetDisplayId(window_secondary_display.get())); | 81 GetDisplayId(window_secondary_display.get())); |
59 } | 82 } |
60 | 83 |
61 using TopLevelWindowFactoryAshTest = test::AshTestBase; | 84 using TopLevelWindowFactoryAshTest = test::AshTestBase; |
62 | 85 |
63 TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) { | 86 TEST_F(TopLevelWindowFactoryAshTest, TopLevelNotShownOnCreate) { |
64 std::map<std::string, std::vector<uint8_t>> properties; | 87 std::map<std::string, std::vector<uint8_t>> properties; |
65 std::unique_ptr<aura::Window> window(mus::CreateAndParentTopLevelWindow( | 88 std::unique_ptr<aura::Window> window(mus::CreateAndParentTopLevelWindow( |
66 ash_test_helper()->window_manager_app()->window_manager(), | 89 ash_test_helper()->window_manager_app()->window_manager(), |
67 ui::mojom::WindowType::WINDOW, &properties)); | 90 ui::mojom::WindowType::WINDOW, &properties)); |
68 ASSERT_TRUE(window); | 91 ASSERT_TRUE(window); |
69 EXPECT_FALSE(window->IsVisible()); | 92 EXPECT_FALSE(window->IsVisible()); |
70 } | 93 } |
71 | 94 |
| 95 TEST_F(TopLevelWindowFactoryAshTest, CreateTopLevelWindow) { |
| 96 const gfx::Rect bounds(1, 2, 124, 345); |
| 97 std::map<std::string, std::vector<uint8_t>> properties; |
| 98 properties[ui::mojom::WindowManager::kBounds_InitProperty] = |
| 99 mojo::ConvertTo<std::vector<uint8_t>>(bounds); |
| 100 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = |
| 101 mojo::ConvertTo<std::vector<uint8_t>>( |
| 102 static_cast<aura::PropertyConverter::PrimitiveType>( |
| 103 ui::mojom::kResizeBehaviorCanResize | |
| 104 ui::mojom::kResizeBehaviorCanMaximize | |
| 105 ui::mojom::kResizeBehaviorCanMinimize)); |
| 106 mus::WindowManager* window_manager = |
| 107 ash_test_helper()->window_manager_app()->window_manager(); |
| 108 // |window| is owned by its parent. |
| 109 aura::Window* window = CreateAndParentTopLevelWindow( |
| 110 window_manager, ui::mojom::WindowType::WINDOW, &properties); |
| 111 ASSERT_TRUE(window->parent()); |
| 112 EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id()); |
| 113 EXPECT_EQ(bounds, window->bounds()); |
| 114 EXPECT_EQ(WidgetCreationType::FOR_CLIENT, |
| 115 window->GetProperty(kWidgetCreationTypeKey)); |
| 116 } |
| 117 |
72 } // namespace ash | 118 } // namespace ash |
OLD | NEW |