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

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

Issue 1907153002: mash/wm: Fix detecting container windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « mash/wm/window_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h"
12 #include "components/mus/public/cpp/window.h" 13 #include "components/mus/public/cpp/window.h"
13 #include "components/mus/public/cpp/window_tree_connection.h" 14 #include "components/mus/public/cpp/window_tree_connection.h"
14 #include "components/mus/public/cpp/window_tree_delegate.h" 15 #include "components/mus/public/cpp/window_tree_delegate.h"
15 #include "components/mus/public/interfaces/window_tree.mojom.h" 16 #include "components/mus/public/interfaces/window_tree.mojom.h"
17 #include "mash/wm/public/interfaces/user_window_controller.mojom.h"
16 #include "services/shell/public/cpp/shell_test.h" 18 #include "services/shell/public/cpp/shell_test.h"
17 19
18 namespace mash { 20 namespace mash {
19 namespace wm { 21 namespace wm {
20 22
21 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate { 23 class WindowTreeDelegateImpl : public mus::WindowTreeDelegate {
22 public: 24 public:
23 WindowTreeDelegateImpl() {} 25 WindowTreeDelegateImpl() {}
24 ~WindowTreeDelegateImpl() override {} 26 ~WindowTreeDelegateImpl() override {}
25 27
(...skipping 11 matching lines...) Expand all
37 ~WindowManagerTest() override {} 39 ~WindowManagerTest() override {}
38 40
39 private: 41 private:
40 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); 42 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest);
41 }; 43 };
42 44
43 void OnEmbed(bool success) { 45 void OnEmbed(bool success) {
44 ASSERT_TRUE(success); 46 ASSERT_TRUE(success);
45 } 47 }
46 48
49 class TestUserWindowObserver : public mojom::UserWindowObserver {
50 public:
51 explicit TestUserWindowObserver(shell::Connector* connector)
52 : binding_(this), window_count_(0u), expected_window_count_(0u) {
53 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_);
54 user_window_controller_->AddUserWindowObserver(
55 binding_.CreateInterfacePtrAndBind());
56 }
57
58 ~TestUserWindowObserver() override {}
59
60 bool WaitUntilWindowCountReaches(size_t expected) {
61 DCHECK(quit_callback_.is_null());
62 if (window_count_ != expected) {
63 base::RunLoop loop;
64 quit_callback_ = loop.QuitClosure();
65 expected_window_count_ = expected;
66 loop.Run();
67 quit_callback_ = base::Closure();
68 }
69 return window_count_ == expected;
70 }
71
72 private:
73 void QuitIfNecessary() {
74 if (window_count_ == expected_window_count_ && !quit_callback_.is_null())
75 quit_callback_.Run();
76 }
77
78 // mojom::UserWindowObserver:
79 void OnUserWindowObserverAdded(
80 mojo::Array<mojom::UserWindowPtr> user_windows) override {
81 window_count_ = user_windows.size();
82 QuitIfNecessary();
83 }
84
85 void OnUserWindowAdded(mojom::UserWindowPtr user_window) override {
86 ++window_count_;
87 QuitIfNecessary();
88 }
89
90 void OnUserWindowRemoved(uint32_t window_id) override {
91 ASSERT_TRUE(window_count_);
92 --window_count_;
93 QuitIfNecessary();
94 }
95
96 void OnUserWindowTitleChanged(uint32_t window_id,
97 const mojo::String& window_title) override {}
98 void OnUserWindowFocusChanged(uint32_t window_id, bool has_focus) override {}
99 void OnUserWindowAppIconChanged(uint32_t window_id,
100 mojo::Array<uint8_t> app_icon) override {}
101
102 mojom::UserWindowControllerPtr user_window_controller_;
103 mojo::Binding<mojom::UserWindowObserver> binding_;
104
105 size_t window_count_;
106 size_t expected_window_count_;
107 base::Closure quit_callback_;
108
109 DISALLOW_COPY_AND_ASSIGN(TestUserWindowObserver);
110 };
111
47 TEST_F(WindowManagerTest, OpenWindow) { 112 TEST_F(WindowManagerTest, OpenWindow) {
48 WindowTreeDelegateImpl window_tree_delegate; 113 WindowTreeDelegateImpl window_tree_delegate;
49 114
50 // Bring up the the desktop_wm. 115 // Bring up the the desktop_wm.
51 connector()->Connect("mojo:desktop_wm"); 116 connector()->Connect("mojo:desktop_wm");
52 117
53 // Connect to mus and create a new top level window. The request goes to 118 // Connect to mus and create a new top level window. The request goes to
54 // the |desktop_wm|, but is async. 119 // the |desktop_wm|, but is async.
55 std::unique_ptr<mus::WindowTreeConnection> connection( 120 std::unique_ptr<mus::WindowTreeConnection> connection(
56 mus::WindowTreeConnection::Create(&window_tree_delegate, connector())); 121 mus::WindowTreeConnection::Create(&window_tree_delegate, connector()));
57 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr); 122 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr);
58 ASSERT_TRUE(top_level_window); 123 ASSERT_TRUE(top_level_window);
59 mus::Window* child_window = connection->NewWindow(); 124 mus::Window* child_window = connection->NewWindow();
60 ASSERT_TRUE(child_window); 125 ASSERT_TRUE(child_window);
61 top_level_window->AddChild(child_window); 126 top_level_window->AddChild(child_window);
62 127
63 // Create another WindowTreeConnection by way of embedding in 128 // Create another WindowTreeConnection by way of embedding in
64 // |child_window|. This blocks until it succeeds. 129 // |child_window|. This blocks until it succeeds.
65 mus::mojom::WindowTreeClientPtr tree_client; 130 mus::mojom::WindowTreeClientPtr tree_client;
66 auto tree_client_request = GetProxy(&tree_client); 131 auto tree_client_request = GetProxy(&tree_client);
67 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed)); 132 child_window->Embed(std::move(tree_client), base::Bind(&OnEmbed));
68 std::unique_ptr<mus::WindowTreeConnection> child_connection( 133 std::unique_ptr<mus::WindowTreeConnection> child_connection(
69 mus::WindowTreeConnection::Create( 134 mus::WindowTreeConnection::Create(
70 &window_tree_delegate, std::move(tree_client_request), 135 &window_tree_delegate, std::move(tree_client_request),
71 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); 136 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED));
72 ASSERT_TRUE(!child_connection->GetRoots().empty()); 137 ASSERT_TRUE(!child_connection->GetRoots().empty());
73 } 138 }
74 139
140 TEST_F(WindowManagerTest, OpenWindowAndClose) {
141 // Bring up the the desktop_wm.
142 connector()->Connect("mojo:desktop_wm");
143
144 TestUserWindowObserver observer(connector());
145
146 // Connect to mus and create a new top level window.
147 WindowTreeDelegateImpl window_tree_delegate;
148 std::unique_ptr<mus::WindowTreeConnection> connection(
149 mus::WindowTreeConnection::Create(&window_tree_delegate, connector()));
150 mus::Window* top_level_window = connection->NewTopLevelWindow(nullptr);
151 ASSERT_TRUE(top_level_window);
152
153 observer.WaitUntilWindowCountReaches(1u);
154 connection.reset();
155 observer.WaitUntilWindowCountReaches(0u);
156 }
157
75 } // namespace wm 158 } // namespace wm
76 } // namespace mash 159 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698