OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/public/cpp/view_manager/view_manager.h" | 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/application_manager/application_manager.h" | 10 #include "mojo/application_manager/application_manager.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
14 #include "mojo/public/cpp/application/service_provider_impl.h" | 14 #include "mojo/public/cpp/application/service_provider_impl.h" |
15 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
16 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" | |
17 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 16 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
18 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 17 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
19 #include "mojo/services/public/cpp/view_manager/util.h" | 18 #include "mojo/services/public/cpp/view_manager/util.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 21 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
22 #include "mojo/shell/shell_test_helper.h" | 22 #include "mojo/shell/shell_test_helper.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace mojo { | 25 namespace mojo { |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kWindowManagerURL[] = "mojo:window_manager"; | 28 const char kWindowManagerURL[] = "mojo:window_manager"; |
29 const char kEmbeddedApp1URL[] = "mojo:embedded_app_1"; | 29 const char kEmbeddedApp1URL[] = "mojo:embedded_app_1"; |
30 | 30 |
31 base::RunLoop* current_run_loop = NULL; | 31 base::RunLoop* current_run_loop = NULL; |
32 | 32 |
33 void DoRunLoop() { | 33 void DoRunLoop() { |
34 base::RunLoop run_loop; | 34 base::RunLoop run_loop; |
35 current_run_loop = &run_loop; | 35 current_run_loop = &run_loop; |
36 current_run_loop->Run(); | 36 current_run_loop->Run(); |
37 current_run_loop = NULL; | 37 current_run_loop = NULL; |
38 } | 38 } |
39 | 39 |
40 void QuitRunLoop() { | 40 void QuitRunLoop() { |
41 current_run_loop->Quit(); | 41 current_run_loop->Quit(); |
42 } | 42 } |
43 | 43 |
44 class ConnectApplicationLoader : public ApplicationLoader, | 44 class ConnectApplicationLoader : public ApplicationLoader, |
45 public ApplicationDelegate, | 45 public ApplicationDelegate, |
46 public ViewManagerDelegate { | 46 public ViewManagerDelegate { |
47 public: | 47 public: |
48 typedef base::Callback<void(ViewManager*, Node*)> LoadedCallback; | 48 typedef base::Callback<void(ViewManager*, View*)> LoadedCallback; |
49 | 49 |
50 explicit ConnectApplicationLoader(const LoadedCallback& callback) | 50 explicit ConnectApplicationLoader(const LoadedCallback& callback) |
51 : callback_(callback), view_manager_client_factory_(this) {} | 51 : callback_(callback), view_manager_client_factory_(this) {} |
52 virtual ~ConnectApplicationLoader() {} | 52 virtual ~ConnectApplicationLoader() {} |
53 | 53 |
54 private: | 54 private: |
55 // Overridden from ApplicationLoader: | 55 // Overridden from ApplicationLoader: |
56 virtual void Load(ApplicationManager* manager, | 56 virtual void Load(ApplicationManager* manager, |
57 const GURL& url, | 57 const GURL& url, |
58 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { | 58 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { |
59 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 59 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
60 if (!shell_handle.is_valid()) | 60 if (!shell_handle.is_valid()) |
61 return; | 61 return; |
62 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 62 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
63 shell_handle.Pass())); | 63 shell_handle.Pass())); |
64 apps_.push_back(app.release()); | 64 apps_.push_back(app.release()); |
65 } | 65 } |
66 | 66 |
67 virtual void OnServiceError(ApplicationManager* manager, | 67 virtual void OnServiceError(ApplicationManager* manager, |
68 const GURL& url) OVERRIDE {} | 68 const GURL& url) OVERRIDE {} |
69 | 69 |
70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
71 OVERRIDE { | 71 OVERRIDE { |
72 connection->AddService(&view_manager_client_factory_); | 72 connection->AddService(&view_manager_client_factory_); |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 // Overridden from ViewManagerDelegate: | 76 // Overridden from ViewManagerDelegate: |
77 virtual void OnEmbed(ViewManager* view_manager, | 77 virtual void OnEmbed(ViewManager* view_manager, |
78 Node* root, | 78 View* root, |
79 ServiceProviderImpl* exported_services, | 79 ServiceProviderImpl* exported_services, |
80 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 80 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
81 callback_.Run(view_manager, root); | 81 callback_.Run(view_manager, root); |
82 } | 82 } |
83 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} | 83 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} |
84 | 84 |
85 ScopedVector<ApplicationImpl> apps_; | 85 ScopedVector<ApplicationImpl> apps_; |
86 LoadedCallback callback_; | 86 LoadedCallback callback_; |
87 ViewManagerClientFactory view_manager_client_factory_; | 87 ViewManagerClientFactory view_manager_client_factory_; |
88 | 88 |
89 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); | 89 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); |
90 }; | 90 }; |
91 | 91 |
92 class BoundsChangeObserver : public NodeObserver { | 92 class BoundsChangeObserver : public ViewObserver { |
93 public: | 93 public: |
94 explicit BoundsChangeObserver(Node* node) : node_(node) {} | 94 explicit BoundsChangeObserver(View* view) : view_(view) {} |
95 virtual ~BoundsChangeObserver() {} | 95 virtual ~BoundsChangeObserver() {} |
96 | 96 |
97 private: | 97 private: |
98 // Overridden from NodeObserver: | 98 // Overridden from ViewObserver: |
99 virtual void OnNodeBoundsChanged(Node* node, | 99 virtual void OnViewBoundsChanged(View* view, |
100 const gfx::Rect& old_bounds, | 100 const gfx::Rect& old_bounds, |
101 const gfx::Rect& new_bounds) OVERRIDE { | 101 const gfx::Rect& new_bounds) OVERRIDE { |
102 DCHECK_EQ(node, node_); | 102 DCHECK_EQ(view, view_); |
103 QuitRunLoop(); | 103 QuitRunLoop(); |
104 } | 104 } |
105 | 105 |
106 Node* node_; | 106 View* view_; |
107 | 107 |
108 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 108 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
109 }; | 109 }; |
110 | 110 |
111 // Wait until the bounds of the supplied node change. | 111 // Wait until the bounds of the supplied view change. |
112 void WaitForBoundsToChange(Node* node) { | 112 void WaitForBoundsToChange(View* view) { |
113 BoundsChangeObserver observer(node); | 113 BoundsChangeObserver observer(view); |
114 node->AddObserver(&observer); | 114 view->AddObserver(&observer); |
115 DoRunLoop(); | 115 DoRunLoop(); |
116 node->RemoveObserver(&observer); | 116 view->RemoveObserver(&observer); |
117 } | 117 } |
118 | 118 |
119 // Spins a runloop until the tree beginning at |root| has |tree_size| nodes | 119 // Spins a runloop until the tree beginning at |root| has |tree_size| views |
120 // (including |root|). | 120 // (including |root|). |
121 class TreeSizeMatchesObserver : public NodeObserver { | 121 class TreeSizeMatchesObserver : public ViewObserver { |
122 public: | 122 public: |
123 TreeSizeMatchesObserver(Node* tree, size_t tree_size) | 123 TreeSizeMatchesObserver(View* tree, size_t tree_size) |
124 : tree_(tree), | 124 : tree_(tree), |
125 tree_size_(tree_size) {} | 125 tree_size_(tree_size) {} |
126 virtual ~TreeSizeMatchesObserver() {} | 126 virtual ~TreeSizeMatchesObserver() {} |
127 | 127 |
128 bool IsTreeCorrectSize() { | 128 bool IsTreeCorrectSize() { |
129 return CountNodes(tree_) == tree_size_; | 129 return CountViews(tree_) == tree_size_; |
130 } | 130 } |
131 | 131 |
132 private: | 132 private: |
133 // Overridden from NodeObserver: | 133 // Overridden from ViewObserver: |
134 virtual void OnTreeChanged(const TreeChangeParams& params) OVERRIDE { | 134 virtual void OnTreeChanged(const TreeChangeParams& params) OVERRIDE { |
135 if (IsTreeCorrectSize()) | 135 if (IsTreeCorrectSize()) |
136 QuitRunLoop(); | 136 QuitRunLoop(); |
137 } | 137 } |
138 | 138 |
139 size_t CountNodes(const Node* node) const { | 139 size_t CountViews(const View* view) const { |
140 size_t count = 1; | 140 size_t count = 1; |
141 Node::Children::const_iterator it = node->children().begin(); | 141 View::Children::const_iterator it = view->children().begin(); |
142 for (; it != node->children().end(); ++it) | 142 for (; it != view->children().end(); ++it) |
143 count += CountNodes(*it); | 143 count += CountViews(*it); |
144 return count; | 144 return count; |
145 } | 145 } |
146 | 146 |
147 Node* tree_; | 147 View* tree_; |
148 size_t tree_size_; | 148 size_t tree_size_; |
149 | 149 |
150 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); | 150 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); |
151 }; | 151 }; |
152 | 152 |
153 void WaitForTreeSizeToMatch(Node* node, size_t tree_size) { | 153 void WaitForTreeSizeToMatch(View* view, size_t tree_size) { |
154 TreeSizeMatchesObserver observer(node, tree_size); | 154 TreeSizeMatchesObserver observer(view, tree_size); |
155 if (observer.IsTreeCorrectSize()) | 155 if (observer.IsTreeCorrectSize()) |
156 return; | 156 return; |
157 node->AddObserver(&observer); | 157 view->AddObserver(&observer); |
158 DoRunLoop(); | 158 DoRunLoop(); |
159 node->RemoveObserver(&observer); | 159 view->RemoveObserver(&observer); |
160 } | 160 } |
161 | 161 |
162 // Utility class that waits for the destruction of some number of nodes and | 162 // Utility class that waits for the destruction of some number of views and |
163 // views. | 163 // views. |
164 class DestructionObserver : public NodeObserver { | 164 class DestructionObserver : public ViewObserver { |
165 public: | 165 public: |
166 // |nodes| or |views| can be NULL. | 166 // |views| or |views| can be NULL. |
167 explicit DestructionObserver(std::set<Id>* nodes) : nodes_(nodes) {} | 167 explicit DestructionObserver(std::set<Id>* views) : views_(views) {} |
168 | 168 |
169 private: | 169 private: |
170 // Overridden from NodeObserver: | 170 // Overridden from ViewObserver: |
171 virtual void OnNodeDestroyed(Node* node) OVERRIDE { | 171 virtual void OnViewDestroyed(View* view) OVERRIDE { |
172 std::set<Id>::iterator it = nodes_->find(node->id()); | 172 std::set<Id>::iterator it = views_->find(view->id()); |
173 if (it != nodes_->end()) | 173 if (it != views_->end()) |
174 nodes_->erase(it); | 174 views_->erase(it); |
175 if (CanQuit()) | 175 if (CanQuit()) |
176 QuitRunLoop(); | 176 QuitRunLoop(); |
177 } | 177 } |
178 | 178 |
179 bool CanQuit() { | 179 bool CanQuit() { |
180 return !nodes_ || nodes_->empty(); | 180 return !views_ || views_->empty(); |
181 } | 181 } |
182 | 182 |
183 std::set<Id>* nodes_; | 183 std::set<Id>* views_; |
184 | 184 |
185 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); | 185 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
186 }; | 186 }; |
187 | 187 |
188 void WaitForDestruction(ViewManager* view_manager, std::set<Id>* nodes) { | 188 void WaitForDestruction(ViewManager* view_manager, std::set<Id>* views) { |
189 DestructionObserver observer(nodes); | 189 DestructionObserver observer(views); |
190 DCHECK(nodes); | 190 DCHECK(views); |
191 if (nodes) { | 191 if (views) { |
192 for (std::set<Id>::const_iterator it = nodes->begin(); | 192 for (std::set<Id>::const_iterator it = views->begin(); |
193 it != nodes->end(); ++it) { | 193 it != views->end(); ++it) { |
194 view_manager->GetNodeById(*it)->AddObserver(&observer); | 194 view_manager->GetViewById(*it)->AddObserver(&observer); |
195 } | 195 } |
196 } | 196 } |
197 DoRunLoop(); | 197 DoRunLoop(); |
198 } | 198 } |
199 | 199 |
200 class OrderChangeObserver : public NodeObserver { | 200 class OrderChangeObserver : public ViewObserver { |
201 public: | 201 public: |
202 OrderChangeObserver(Node* node) : node_(node) { | 202 OrderChangeObserver(View* view) : view_(view) { |
203 node_->AddObserver(this); | 203 view_->AddObserver(this); |
204 } | 204 } |
205 virtual ~OrderChangeObserver() { | 205 virtual ~OrderChangeObserver() { |
206 node_->RemoveObserver(this); | 206 view_->RemoveObserver(this); |
207 } | 207 } |
208 | 208 |
209 private: | 209 private: |
210 // Overridden from NodeObserver: | 210 // Overridden from ViewObserver: |
211 virtual void OnNodeReordered(Node* node, | 211 virtual void OnViewReordered(View* view, |
212 Node* relative_node, | 212 View* relative_view, |
213 OrderDirection direction) OVERRIDE { | 213 OrderDirection direction) OVERRIDE { |
214 DCHECK_EQ(node, node_); | 214 DCHECK_EQ(view, view_); |
215 QuitRunLoop(); | 215 QuitRunLoop(); |
216 } | 216 } |
217 | 217 |
218 Node* node_; | 218 View* view_; |
219 | 219 |
220 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 220 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
221 }; | 221 }; |
222 | 222 |
223 void WaitForOrderChange(ViewManager* view_manager, Node* node) { | 223 void WaitForOrderChange(ViewManager* view_manager, View* view) { |
224 OrderChangeObserver observer(node); | 224 OrderChangeObserver observer(view); |
225 DoRunLoop(); | 225 DoRunLoop(); |
226 } | 226 } |
227 | 227 |
228 // Tracks a node's destruction. Query is_valid() for current state. | 228 // Tracks a view's destruction. Query is_valid() for current state. |
229 class NodeTracker : public NodeObserver { | 229 class ViewTracker : public ViewObserver { |
230 public: | 230 public: |
231 explicit NodeTracker(Node* node) : node_(node) { | 231 explicit ViewTracker(View* view) : view_(view) { |
232 node_->AddObserver(this); | 232 view_->AddObserver(this); |
233 } | 233 } |
234 virtual ~NodeTracker() { | 234 virtual ~ViewTracker() { |
235 if (node_) | 235 if (view_) |
236 node_->RemoveObserver(this); | 236 view_->RemoveObserver(this); |
237 } | 237 } |
238 | 238 |
239 bool is_valid() const { return !!node_; } | 239 bool is_valid() const { return !!view_; } |
240 | 240 |
241 private: | 241 private: |
242 // Overridden from NodeObserver: | 242 // Overridden from ViewObserver: |
243 virtual void OnNodeDestroyed(Node* node) OVERRIDE { | 243 virtual void OnViewDestroyed(View* view) OVERRIDE { |
244 DCHECK_EQ(node, node_); | 244 DCHECK_EQ(view, view_); |
245 node_ = NULL; | 245 view_ = NULL; |
246 } | 246 } |
247 | 247 |
248 int id_; | 248 int id_; |
249 Node* node_; | 249 View* view_; |
250 | 250 |
251 DISALLOW_COPY_AND_ASSIGN(NodeTracker); | 251 DISALLOW_COPY_AND_ASSIGN(ViewTracker); |
252 }; | 252 }; |
253 | 253 |
254 } // namespace | 254 } // namespace |
255 | 255 |
256 // ViewManager ----------------------------------------------------------------- | 256 // ViewManager ----------------------------------------------------------------- |
257 | 257 |
258 // These tests model synchronization of two peer connections to the view manager | 258 // These tests model synchronization of two peer connections to the view manager |
259 // service, that are given access to some root node. | 259 // service, that are given access to some root view. |
260 | 260 |
261 class ViewManagerTest : public testing::Test { | 261 class ViewManagerTest : public testing::Test { |
262 public: | 262 public: |
263 ViewManagerTest() | 263 ViewManagerTest() |
264 : connect_loop_(NULL), | 264 : connect_loop_(NULL), |
265 loaded_view_manager_(NULL), | 265 loaded_view_manager_(NULL), |
266 window_manager_(NULL), | 266 window_manager_(NULL), |
267 commit_count_(0) {} | 267 commit_count_(0) {} |
268 | 268 |
269 protected: | 269 protected: |
270 ViewManager* window_manager() { return window_manager_; } | 270 ViewManager* window_manager() { return window_manager_; } |
271 | 271 |
272 Node* CreateNodeInParent(Node* parent) { | 272 View* CreateViewInParent(View* parent) { |
273 ViewManager* parent_manager = NodePrivate(parent).view_manager(); | 273 ViewManager* parent_manager = ViewPrivate(parent).view_manager(); |
274 Node* node = Node::Create(parent_manager); | 274 View* view = View::Create(parent_manager); |
275 parent->AddChild(node); | 275 parent->AddChild(view); |
276 return node; | 276 return view; |
277 } | 277 } |
278 | 278 |
279 // Embeds another version of the test app @ node. | 279 // Embeds another version of the test app @ view. |
280 ViewManager* Embed(ViewManager* view_manager, Node* node) { | 280 ViewManager* Embed(ViewManager* view_manager, View* view) { |
281 DCHECK_EQ(view_manager, NodePrivate(node).view_manager()); | 281 DCHECK_EQ(view_manager, ViewPrivate(view).view_manager()); |
282 node->Embed(kEmbeddedApp1URL); | 282 view->Embed(kEmbeddedApp1URL); |
283 RunRunLoop(); | 283 RunRunLoop(); |
284 return GetLoadedViewManager(); | 284 return GetLoadedViewManager(); |
285 } | 285 } |
286 | 286 |
287 ViewManager* GetLoadedViewManager() { | 287 ViewManager* GetLoadedViewManager() { |
288 ViewManager* view_manager = loaded_view_manager_; | 288 ViewManager* view_manager = loaded_view_manager_; |
289 loaded_view_manager_ = NULL; | 289 loaded_view_manager_ = NULL; |
290 return view_manager; | 290 return view_manager; |
291 } | 291 } |
292 | 292 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 BindToProxy(new ServiceProviderImpl, &sp); | 325 BindToProxy(new ServiceProviderImpl, &sp); |
326 view_manager_init->Embed( | 326 view_manager_init->Embed( |
327 url, sp.Pass(), | 327 url, sp.Pass(), |
328 base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this), | 328 base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this), |
329 &result)); | 329 &result)); |
330 RunRunLoop(); | 330 RunRunLoop(); |
331 window_manager_ = GetLoadedViewManager(); | 331 window_manager_ = GetLoadedViewManager(); |
332 return result; | 332 return result; |
333 } | 333 } |
334 | 334 |
335 void OnViewManagerLoaded(ViewManager* view_manager, Node* root) { | 335 void OnViewManagerLoaded(ViewManager* view_manager, View* root) { |
336 loaded_view_manager_ = view_manager; | 336 loaded_view_manager_ = view_manager; |
337 connect_loop_->Quit(); | 337 connect_loop_->Quit(); |
338 } | 338 } |
339 | 339 |
340 void RunRunLoop() { | 340 void RunRunLoop() { |
341 base::RunLoop run_loop; | 341 base::RunLoop run_loop; |
342 connect_loop_ = &run_loop; | 342 connect_loop_ = &run_loop; |
343 connect_loop_->Run(); | 343 connect_loop_->Run(); |
344 connect_loop_ = NULL; | 344 connect_loop_ = NULL; |
345 } | 345 } |
346 | 346 |
347 base::RunLoop* connect_loop_; | 347 base::RunLoop* connect_loop_; |
348 shell::ShellTestHelper test_helper_; | 348 shell::ShellTestHelper test_helper_; |
349 ViewManagerInitServicePtr view_manager_init_; | 349 ViewManagerInitServicePtr view_manager_init_; |
350 // Used to receive the most recent view manager loaded by an embed action. | 350 // Used to receive the most recent view manager loaded by an embed action. |
351 ViewManager* loaded_view_manager_; | 351 ViewManager* loaded_view_manager_; |
352 // The View Manager connection held by the window manager (app running at the | 352 // The View Manager connection held by the window manager (app running at the |
353 // root node). | 353 // root view). |
354 ViewManager* window_manager_; | 354 ViewManager* window_manager_; |
355 int commit_count_; | 355 int commit_count_; |
356 | 356 |
357 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | 357 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
358 }; | 358 }; |
359 | 359 |
360 TEST_F(ViewManagerTest, SetUp) {} | 360 TEST_F(ViewManagerTest, SetUp) {} |
361 | 361 |
362 TEST_F(ViewManagerTest, Embed) { | 362 TEST_F(ViewManagerTest, Embed) { |
363 Node* node = Node::Create(window_manager()); | 363 View* view = View::Create(window_manager()); |
364 window_manager()->GetRoots().front()->AddChild(node); | 364 window_manager()->GetRoots().front()->AddChild(view); |
365 ViewManager* embedded = Embed(window_manager(), node); | 365 ViewManager* embedded = Embed(window_manager(), view); |
366 EXPECT_TRUE(NULL != embedded); | 366 EXPECT_TRUE(NULL != embedded); |
367 | 367 |
368 Node* node_in_embedded = embedded->GetRoots().front(); | 368 View* view_in_embedded = embedded->GetRoots().front(); |
369 EXPECT_EQ(node->parent(), window_manager()->GetRoots().front()); | 369 EXPECT_EQ(view->parent(), window_manager()->GetRoots().front()); |
370 EXPECT_EQ(NULL, node_in_embedded->parent()); | 370 EXPECT_EQ(NULL, view_in_embedded->parent()); |
371 } | 371 } |
372 | 372 |
373 // Window manager has two nodes, N1 and N11. Embeds A at N1. A should not see | 373 // Window manager has two views, N1 and N11. Embeds A at N1. A should not see |
374 // N11. | 374 // N11. |
375 // TODO(sky): Update client lib to match server. | 375 // TODO(sky): Update client lib to match server. |
376 TEST_F(ViewManagerTest, DISABLED_EmbeddedDoesntSeeChild) { | 376 TEST_F(ViewManagerTest, DISABLED_EmbeddedDoesntSeeChild) { |
377 Node* node = Node::Create(window_manager()); | 377 View* view = View::Create(window_manager()); |
378 window_manager()->GetRoots().front()->AddChild(node); | 378 window_manager()->GetRoots().front()->AddChild(view); |
379 Node* nested = Node::Create(window_manager()); | 379 View* nested = View::Create(window_manager()); |
380 node->AddChild(nested); | 380 view->AddChild(nested); |
381 | 381 |
382 ViewManager* embedded = Embed(window_manager(), node); | 382 ViewManager* embedded = Embed(window_manager(), view); |
383 EXPECT_EQ(embedded->GetRoots().front()->children().front()->id(), | 383 EXPECT_EQ(embedded->GetRoots().front()->children().front()->id(), |
384 nested->id()); | 384 nested->id()); |
385 EXPECT_TRUE(embedded->GetRoots().front()->children().empty()); | 385 EXPECT_TRUE(embedded->GetRoots().front()->children().empty()); |
386 EXPECT_TRUE(nested->parent() == NULL); | 386 EXPECT_TRUE(nested->parent() == NULL); |
387 } | 387 } |
388 | 388 |
389 // http://crbug.com/396300 | 389 // http://crbug.com/396300 |
390 TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupNode) { | 390 TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupView) { |
391 Node* node = Node::Create(window_manager()); | 391 View* view = View::Create(window_manager()); |
392 window_manager()->GetRoots().front()->AddChild(node); | 392 window_manager()->GetRoots().front()->AddChild(view); |
393 ViewManager* embedded = Embed(window_manager(), node); | 393 ViewManager* embedded = Embed(window_manager(), view); |
394 | 394 |
395 Id node_id = node->id(); | 395 Id view_id = view->id(); |
396 | 396 |
397 UnloadApplication(GURL(kWindowManagerURL)); | 397 UnloadApplication(GURL(kWindowManagerURL)); |
398 | 398 |
399 std::set<Id> nodes; | 399 std::set<Id> views; |
400 nodes.insert(node_id); | 400 views.insert(view_id); |
401 WaitForDestruction(embedded, &nodes); | 401 WaitForDestruction(embedded, &views); |
402 | 402 |
403 EXPECT_TRUE(embedded->GetRoots().empty()); | 403 EXPECT_TRUE(embedded->GetRoots().empty()); |
404 } | 404 } |
405 | 405 |
406 // TODO(beng): write a replacement test for the one that once existed here: | 406 // TODO(beng): write a replacement test for the one that once existed here: |
407 // This test validates the following scenario: | 407 // This test validates the following scenario: |
408 // - a node originating from one connection | 408 // - a view originating from one connection |
409 // - a view originating from a second connection | 409 // - a view originating from a second connection |
410 // + the connection originating the node is destroyed | 410 // + the connection originating the view is destroyed |
411 // -> the view should still exist (since the second connection is live) but | 411 // -> the view should still exist (since the second connection is live) but |
412 // should be disconnected from any nodes. | 412 // should be disconnected from any views. |
413 // http://crbug.com/396300 | 413 // http://crbug.com/396300 |
414 // | 414 // |
415 // TODO(beng): The new test should validate the scenario as described above | 415 // TODO(beng): The new test should validate the scenario as described above |
416 // except that the second connection still has a valid tree. | 416 // except that the second connection still has a valid tree. |
417 | 417 |
418 // Verifies that bounds changes applied to a node hierarchy in one connection | 418 // Verifies that bounds changes applied to a view hierarchy in one connection |
419 // are reflected to another. | 419 // are reflected to another. |
420 TEST_F(ViewManagerTest, SetBounds) { | 420 TEST_F(ViewManagerTest, SetBounds) { |
421 Node* node = Node::Create(window_manager()); | 421 View* view = View::Create(window_manager()); |
422 window_manager()->GetRoots().front()->AddChild(node); | 422 window_manager()->GetRoots().front()->AddChild(view); |
423 ViewManager* embedded = Embed(window_manager(), node); | 423 ViewManager* embedded = Embed(window_manager(), view); |
424 | 424 |
425 Node* node_in_embedded = embedded->GetNodeById(node->id()); | 425 View* view_in_embedded = embedded->GetViewById(view->id()); |
426 EXPECT_EQ(node->bounds(), node_in_embedded->bounds()); | 426 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
427 | 427 |
428 node->SetBounds(gfx::Rect(100, 100)); | 428 view->SetBounds(gfx::Rect(100, 100)); |
429 EXPECT_NE(node->bounds(), node_in_embedded->bounds()); | 429 EXPECT_NE(view->bounds(), view_in_embedded->bounds()); |
430 WaitForBoundsToChange(node_in_embedded); | 430 WaitForBoundsToChange(view_in_embedded); |
431 EXPECT_EQ(node->bounds(), node_in_embedded->bounds()); | 431 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
432 } | 432 } |
433 | 433 |
434 // Verifies that bounds changes applied to a node owned by a different | 434 // Verifies that bounds changes applied to a view owned by a different |
435 // connection are refused. | 435 // connection are refused. |
436 TEST_F(ViewManagerTest, SetBoundsSecurity) { | 436 TEST_F(ViewManagerTest, SetBoundsSecurity) { |
437 Node* node = Node::Create(window_manager()); | 437 View* view = View::Create(window_manager()); |
438 window_manager()->GetRoots().front()->AddChild(node); | 438 window_manager()->GetRoots().front()->AddChild(view); |
439 ViewManager* embedded = Embed(window_manager(), node); | 439 ViewManager* embedded = Embed(window_manager(), view); |
440 | 440 |
441 Node* node_in_embedded = embedded->GetNodeById(node->id()); | 441 View* view_in_embedded = embedded->GetViewById(view->id()); |
442 node->SetBounds(gfx::Rect(800, 600)); | 442 view->SetBounds(gfx::Rect(800, 600)); |
443 WaitForBoundsToChange(node_in_embedded); | 443 WaitForBoundsToChange(view_in_embedded); |
444 | 444 |
445 node_in_embedded->SetBounds(gfx::Rect(1024, 768)); | 445 view_in_embedded->SetBounds(gfx::Rect(1024, 768)); |
446 // Bounds change should have been rejected. | 446 // Bounds change should have been rejected. |
447 EXPECT_EQ(node->bounds(), node_in_embedded->bounds()); | 447 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
448 } | 448 } |
449 | 449 |
450 // Verifies that a node can only be destroyed by the connection that created it. | 450 // Verifies that a view can only be destroyed by the connection that created it. |
451 TEST_F(ViewManagerTest, DestroySecurity) { | 451 TEST_F(ViewManagerTest, DestroySecurity) { |
452 Node* node = Node::Create(window_manager()); | 452 View* view = View::Create(window_manager()); |
453 window_manager()->GetRoots().front()->AddChild(node); | 453 window_manager()->GetRoots().front()->AddChild(view); |
454 ViewManager* embedded = Embed(window_manager(), node); | 454 ViewManager* embedded = Embed(window_manager(), view); |
455 | 455 |
456 Node* node_in_embedded = embedded->GetNodeById(node->id()); | 456 View* view_in_embedded = embedded->GetViewById(view->id()); |
457 | 457 |
458 NodeTracker tracker2(node_in_embedded); | 458 ViewTracker tracker2(view_in_embedded); |
459 node_in_embedded->Destroy(); | 459 view_in_embedded->Destroy(); |
460 // Node should not have been destroyed. | 460 // View should not have been destroyed. |
461 EXPECT_TRUE(tracker2.is_valid()); | 461 EXPECT_TRUE(tracker2.is_valid()); |
462 | 462 |
463 NodeTracker tracker1(node); | 463 ViewTracker tracker1(view); |
464 node->Destroy(); | 464 view->Destroy(); |
465 EXPECT_FALSE(tracker1.is_valid()); | 465 EXPECT_FALSE(tracker1.is_valid()); |
466 } | 466 } |
467 | 467 |
468 TEST_F(ViewManagerTest, MultiRoots) { | 468 TEST_F(ViewManagerTest, MultiRoots) { |
469 Node* node1 = Node::Create(window_manager()); | 469 View* view1 = View::Create(window_manager()); |
470 window_manager()->GetRoots().front()->AddChild(node1); | 470 window_manager()->GetRoots().front()->AddChild(view1); |
471 Node* node2 = Node::Create(window_manager()); | 471 View* view2 = View::Create(window_manager()); |
472 window_manager()->GetRoots().front()->AddChild(node2); | 472 window_manager()->GetRoots().front()->AddChild(view2); |
473 ViewManager* embedded1 = Embed(window_manager(), node1); | 473 ViewManager* embedded1 = Embed(window_manager(), view1); |
474 ViewManager* embedded2 = Embed(window_manager(), node2); | 474 ViewManager* embedded2 = Embed(window_manager(), view2); |
475 EXPECT_EQ(embedded1, embedded2); | 475 EXPECT_EQ(embedded1, embedded2); |
476 } | 476 } |
477 | 477 |
478 TEST_F(ViewManagerTest, EmbeddingIdentity) { | 478 TEST_F(ViewManagerTest, EmbeddingIdentity) { |
479 Node* node = Node::Create(window_manager()); | 479 View* view = View::Create(window_manager()); |
480 window_manager()->GetRoots().front()->AddChild(node); | 480 window_manager()->GetRoots().front()->AddChild(view); |
481 ViewManager* embedded = Embed(window_manager(), node); | 481 ViewManager* embedded = Embed(window_manager(), view); |
482 EXPECT_EQ(kWindowManagerURL, embedded->GetEmbedderURL()); | 482 EXPECT_EQ(kWindowManagerURL, embedded->GetEmbedderURL()); |
483 } | 483 } |
484 | 484 |
485 TEST_F(ViewManagerTest, Reorder) { | 485 TEST_F(ViewManagerTest, Reorder) { |
486 Node* node1 = Node::Create(window_manager()); | 486 View* view1 = View::Create(window_manager()); |
487 window_manager()->GetRoots().front()->AddChild(node1); | 487 window_manager()->GetRoots().front()->AddChild(view1); |
488 | 488 |
489 ViewManager* embedded = Embed(window_manager(), node1); | 489 ViewManager* embedded = Embed(window_manager(), view1); |
490 | 490 |
491 Node* node11 = Node::Create(embedded); | 491 View* view11 = View::Create(embedded); |
492 embedded->GetRoots().front()->AddChild(node11); | 492 embedded->GetRoots().front()->AddChild(view11); |
493 Node* node12 = Node::Create(embedded); | 493 View* view12 = View::Create(embedded); |
494 embedded->GetRoots().front()->AddChild(node12); | 494 embedded->GetRoots().front()->AddChild(view12); |
495 | 495 |
496 Node* node1_in_wm = window_manager()->GetNodeById(node1->id()); | 496 View* view1_in_wm = window_manager()->GetViewById(view1->id()); |
497 | 497 |
498 { | 498 { |
499 WaitForTreeSizeToMatch(node1, 2u); | 499 WaitForTreeSizeToMatch(view1, 2u); |
500 node11->MoveToFront(); | 500 view11->MoveToFront(); |
501 WaitForOrderChange(window_manager(), | 501 WaitForOrderChange(window_manager(), |
502 window_manager()->GetNodeById(node11->id())); | 502 window_manager()->GetViewById(view11->id())); |
503 | 503 |
504 EXPECT_EQ(node1_in_wm->children().front(), | 504 EXPECT_EQ(view1_in_wm->children().front(), |
505 window_manager()->GetNodeById(node12->id())); | 505 window_manager()->GetViewById(view12->id())); |
506 EXPECT_EQ(node1_in_wm->children().back(), | 506 EXPECT_EQ(view1_in_wm->children().back(), |
507 window_manager()->GetNodeById(node11->id())); | 507 window_manager()->GetViewById(view11->id())); |
508 } | 508 } |
509 | 509 |
510 { | 510 { |
511 node11->MoveToBack(); | 511 view11->MoveToBack(); |
512 WaitForOrderChange(window_manager(), | 512 WaitForOrderChange(window_manager(), |
513 window_manager()->GetNodeById(node11->id())); | 513 window_manager()->GetViewById(view11->id())); |
514 | 514 |
515 EXPECT_EQ(node1_in_wm->children().front(), | 515 EXPECT_EQ(view1_in_wm->children().front(), |
516 window_manager()->GetNodeById(node11->id())); | 516 window_manager()->GetViewById(view11->id())); |
517 EXPECT_EQ(node1_in_wm->children().back(), | 517 EXPECT_EQ(view1_in_wm->children().back(), |
518 window_manager()->GetNodeById(node12->id())); | 518 window_manager()->GetViewById(view12->id())); |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 // TODO(beng): tests for view event dispatcher. | 522 // TODO(beng): tests for view event dispatcher. |
523 // - verify that we see events for all views. | 523 // - verify that we see events for all views. |
524 | 524 |
525 // TODO(beng): tests for focus: | 525 // TODO(beng): tests for focus: |
526 // - focus between two nodes known to a connection | 526 // - focus between two views known to a connection |
527 // - focus between nodes unknown to one of the connections. | 527 // - focus between views unknown to one of the connections. |
528 // - focus between nodes unknown to either connection. | 528 // - focus between views unknown to either connection. |
529 | 529 |
530 } // namespace mojo | 530 } // namespace mojo |
OLD | NEW |