Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: mash/wm/window_manager_unittest.cc

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: move comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 <stdint.h>
6
7 #include <memory>
8 #include <utility>
9
10 #include "ash/public/interfaces/user_window_controller.mojom.h"
11 #include "base/bind.h"
12 #include "base/macros.h"
13 #include "base/run_loop.h"
14 #include "components/mus/public/cpp/window.h"
15 #include "components/mus/public/cpp/window_tree_client.h"
16 #include "components/mus/public/cpp/window_tree_client_delegate.h"
17 #include "components/mus/public/interfaces/window_tree.mojom.h"
18 #include "services/shell/public/cpp/shell_test.h"
19
20 namespace mash {
21 namespace wm {
22
23 class WindowTreeClientDelegate : public mus::WindowTreeClientDelegate {
24 public:
25 WindowTreeClientDelegate() {}
26 ~WindowTreeClientDelegate() override {}
27
28 private:
29 // mus::WindowTreeClientDelegate:
30 void OnEmbed(mus::Window* root) override {}
31 void OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) override {}
32 void OnEventObserved(const ui::Event& event, mus::Window* target) override {}
33
34 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientDelegate);
35 };
36
37 class WindowManagerTest : public shell::test::ShellTest {
38 public:
39 WindowManagerTest() : shell::test::ShellTest("exe:mash_unittests") {}
40 ~WindowManagerTest() override {}
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest);
44 };
45
46 void OnEmbed(bool success) {
47 ASSERT_TRUE(success);
48 }
49
50 class TestUserWindowObserver : public ash::mojom::UserWindowObserver {
51 public:
52 explicit TestUserWindowObserver(shell::Connector* connector)
53 : binding_(this), window_count_(0u), expected_window_count_(0u) {
54 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_);
55 user_window_controller_->AddUserWindowObserver(
56 binding_.CreateInterfacePtrAndBind());
57 }
58
59 ~TestUserWindowObserver() override {}
60
61 bool WaitUntilWindowCountReaches(size_t expected) {
62 DCHECK(quit_callback_.is_null());
63 if (window_count_ != expected) {
64 base::RunLoop loop;
65 quit_callback_ = loop.QuitClosure();
66 expected_window_count_ = expected;
67 loop.Run();
68 quit_callback_ = base::Closure();
69 }
70 return window_count_ == expected;
71 }
72
73 private:
74 void QuitIfNecessary() {
75 if (window_count_ == expected_window_count_ && !quit_callback_.is_null())
76 quit_callback_.Run();
77 }
78
79 // mojom::UserWindowObserver:
80 void OnUserWindowObserverAdded(
81 mojo::Array<ash::mojom::UserWindowPtr> user_windows) override {
82 window_count_ = user_windows.size();
83 QuitIfNecessary();
84 }
85
86 void OnUserWindowAdded(ash::mojom::UserWindowPtr user_window) override {
87 ++window_count_;
88 QuitIfNecessary();
89 }
90
91 void OnUserWindowRemoved(uint32_t window_id) override {
92 ASSERT_TRUE(window_count_);
93 --window_count_;
94 QuitIfNecessary();
95 }
96
97 void OnUserWindowTitleChanged(uint32_t window_id,
98 const mojo::String& window_title) override {}
99 void OnUserWindowFocusChanged(uint32_t window_id, bool has_focus) override {}
100 void OnUserWindowAppIconChanged(uint32_t window_id,
101 mojo::Array<uint8_t> app_icon) override {}
102
103 ash::mojom::UserWindowControllerPtr user_window_controller_;
104 mojo::Binding<ash::mojom::UserWindowObserver> binding_;
105
106 size_t window_count_;
107 size_t expected_window_count_;
108 base::Closure quit_callback_;
109
110 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver);
111 };
112
113 TEST_F(WindowManagerTest, OpenWindow) {
114 WindowTreeClientDelegate window_tree_delegate;
115
116 // Bring up the the desktop_wm.
117 connector()->Connect("mojo:desktop_wm");
118
119 // Connect to mus and create a new top level window. The request goes to
120 // the |desktop_wm|, but is async.
121 std::unique_ptr<mus::WindowTreeClient> client(
122 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr));
123 client->ConnectViaWindowTreeFactory(connector());
124 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr);
125 ASSERT_TRUE(top_level_window);
126 mus::Window* child_window = client->NewWindow();
127 ASSERT_TRUE(child_window);
128 top_level_window->AddChild(child_window);
129
130 // Create another WindowTreeClient by way of embedding in
131 // |child_window|. This blocks until it succeeds.
132 mus::mojom::WindowTreeClientPtr tree_client;
133 auto tree_client_request = GetProxy(&tree_client);
134 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed));
135 std::unique_ptr<mus::WindowTreeClient> child_client(
136 new mus::WindowTreeClient(&window_tree_delegate, nullptr,
137 std::move(tree_client_request)));
138 child_client->WaitForEmbed();
139 ASSERT_TRUE(!child_client->GetRoots().empty());
140 }
141
142 TEST_F(WindowManagerTest, OpenWindowAndClose) {
143 // Bring up the the desktop_wm.
144 connector()->Connect("mojo:desktop_wm");
145
146 TestUserWindowObserver observer(connector());
147
148 // Connect to mus and create a new top level window.
149 WindowTreeClientDelegate window_tree_delegate;
150 std::unique_ptr<mus::WindowTreeClient> client(
151 new mus::WindowTreeClient(&window_tree_delegate, nullptr, nullptr));
152 client->ConnectViaWindowTreeFactory(connector());
153 mus::Window* top_level_window = client->NewTopLevelWindow(nullptr);
154 ASSERT_TRUE(top_level_window);
155
156 observer.WaitUntilWindowCountReaches(1u);
157 client.reset();
158 observer.WaitUntilWindowCountReaches(0u);
159 }
160
161 } // namespace wm
162 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_manager_application.cc ('k') | mash/wm/workspace/workspace_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698