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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
17 #include "mojo/public/cpp/application/application_connection.h" | 17 #include "mojo/public/cpp/application/application_connection.h" |
18 #include "mojo/public/cpp/application/application_delegate.h" | 18 #include "mojo/public/cpp/application/application_delegate.h" |
19 #include "mojo/public/cpp/application/application_impl.h" | 19 #include "mojo/public/cpp/application/application_impl.h" |
20 #include "mojo/public/cpp/application/connect.h" | 20 #include "mojo/public/cpp/application/connect.h" |
21 #include "mojo/public/cpp/bindings/lib/router.h" | 21 #include "mojo/public/cpp/bindings/lib/router.h" |
| 22 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
22 #include "mojo/service_manager/service_manager.h" | 23 #include "mojo/service_manager/service_manager.h" |
23 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 24 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
24 #include "mojo/services/public/cpp/view_manager/types.h" | 25 #include "mojo/services/public/cpp/view_manager/types.h" |
25 #include "mojo/services/public/cpp/view_manager/util.h" | 26 #include "mojo/services/public/cpp/view_manager/util.h" |
26 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 27 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
27 #include "mojo/services/view_manager/ids.h" | 28 #include "mojo/services/view_manager/ids.h" |
28 #include "mojo/services/view_manager/test_change_tracker.h" | 29 #include "mojo/services/view_manager/test_change_tracker.h" |
29 #include "mojo/shell/shell_test_helper.h" | 30 #include "mojo/shell/shell_test_helper.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 changes_.clear(); | 174 changes_.clear(); |
174 view_manager_->GetNodeTree(node_id, | 175 view_manager_->GetNodeTree(node_id, |
175 base::Bind(&ViewManagerProxy::GotNodeTree, | 176 base::Bind(&ViewManagerProxy::GotNodeTree, |
176 base::Unretained(this), nodes)); | 177 base::Unretained(this), nodes)); |
177 RunMainLoop(); | 178 RunMainLoop(); |
178 } | 179 } |
179 bool Embed(const Id node_id, const char* url) { | 180 bool Embed(const Id node_id, const char* url) { |
180 changes_.clear(); | 181 changes_.clear(); |
181 base::AutoReset<bool> auto_reset(&in_embed_, true); | 182 base::AutoReset<bool> auto_reset(&in_embed_, true); |
182 bool result = false; | 183 bool result = false; |
183 view_manager_->Embed(url, node_id, | 184 ServiceProviderPtr services; |
| 185 view_manager_->Embed(url, node_id, services.Pass(), |
184 base::Bind(&ViewManagerProxy::GotResult, | 186 base::Bind(&ViewManagerProxy::GotResult, |
185 base::Unretained(this), &result)); | 187 base::Unretained(this), &result)); |
186 RunMainLoop(); | 188 RunMainLoop(); |
187 return result; | 189 return result; |
188 } | 190 } |
189 bool DeleteNode(Id node_id) { | 191 bool DeleteNode(Id node_id) { |
190 changes_.clear(); | 192 changes_.clear(); |
191 bool result = false; | 193 bool result = false; |
192 view_manager_->DeleteNode(node_id, | 194 view_manager_->DeleteNode(node_id, |
193 base::Bind(&ViewManagerProxy::GotResult, | 195 base::Bind(&ViewManagerProxy::GotResult, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 tracker_.set_delegate(&connection_); | 312 tracker_.set_delegate(&connection_); |
311 } | 313 } |
312 | 314 |
313 // InterfaceImpl: | 315 // InterfaceImpl: |
314 virtual void OnConnectionEstablished() OVERRIDE { | 316 virtual void OnConnectionEstablished() OVERRIDE { |
315 connection_.set_router(internal_state()->router()); | 317 connection_.set_router(internal_state()->router()); |
316 connection_.set_view_manager(client()); | 318 connection_.set_view_manager(client()); |
317 } | 319 } |
318 | 320 |
319 // ViewManagerClient: | 321 // ViewManagerClient: |
320 virtual void OnEmbed(ConnectionSpecificId connection_id, | 322 virtual void OnEmbed( |
321 const String& creator_url, | 323 ConnectionSpecificId connection_id, |
322 NodeDataPtr root) OVERRIDE { | 324 const String& creator_url, |
| 325 NodeDataPtr root, |
| 326 InterfaceRequest<ServiceProvider> services) OVERRIDE { |
323 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); | 327 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); |
324 } | 328 } |
325 virtual void OnNodeBoundsChanged(Id node_id, | 329 virtual void OnNodeBoundsChanged(Id node_id, |
326 RectPtr old_bounds, | 330 RectPtr old_bounds, |
327 RectPtr new_bounds) OVERRIDE { | 331 RectPtr new_bounds) OVERRIDE { |
328 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 332 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
329 } | 333 } |
330 virtual void OnNodeHierarchyChanged(Id node, | 334 virtual void OnNodeHierarchyChanged(Id node, |
331 Id new_parent, | 335 Id new_parent, |
332 Id old_parent, | 336 Id old_parent, |
(...skipping 16 matching lines...) Expand all Loading... |
349 Id old_view_id) OVERRIDE { | 353 Id old_view_id) OVERRIDE { |
350 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); | 354 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); |
351 } | 355 } |
352 virtual void OnViewInputEvent(Id view_id, | 356 virtual void OnViewInputEvent(Id view_id, |
353 EventPtr event, | 357 EventPtr event, |
354 const Callback<void()>& callback) OVERRIDE { | 358 const Callback<void()>& callback) OVERRIDE { |
355 tracker_.OnViewInputEvent(view_id, event.Pass()); | 359 tracker_.OnViewInputEvent(view_id, event.Pass()); |
356 } | 360 } |
357 virtual void OnFocusChanged(Id gained_focus_id, | 361 virtual void OnFocusChanged(Id gained_focus_id, |
358 Id lost_focus_id) OVERRIDE {} | 362 Id lost_focus_id) OVERRIDE {} |
359 virtual void Embed(const String& url) OVERRIDE { | 363 virtual void Embed( |
| 364 const String& url, |
| 365 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
360 tracker_.DelegateEmbed(url); | 366 tracker_.DelegateEmbed(url); |
361 } | 367 } |
362 virtual void DispatchOnViewInputEvent(Id view_id, | 368 virtual void DispatchOnViewInputEvent(Id view_id, |
363 mojo::EventPtr event) OVERRIDE { | 369 mojo::EventPtr event) OVERRIDE { |
364 } | 370 } |
365 | 371 |
366 private: | 372 private: |
367 TestChangeTracker tracker_; | 373 TestChangeTracker tracker_; |
368 ViewManagerProxy connection_; | 374 ViewManagerProxy connection_; |
369 | 375 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } | 436 } |
431 | 437 |
432 // Embed from an application that does not yet have a view manager connection. | 438 // Embed from an application that does not yet have a view manager connection. |
433 // Blocks until result is determined. | 439 // Blocks until result is determined. |
434 bool InitEmbed(ViewManagerInitService* view_manager_init, | 440 bool InitEmbed(ViewManagerInitService* view_manager_init, |
435 const std::string& url, | 441 const std::string& url, |
436 size_t number_of_calls) { | 442 size_t number_of_calls) { |
437 bool result = false; | 443 bool result = false; |
438 base::RunLoop run_loop; | 444 base::RunLoop run_loop; |
439 for (size_t i = 0; i < number_of_calls; ++i) { | 445 for (size_t i = 0; i < number_of_calls; ++i) { |
440 view_manager_init->Embed(url, base::Bind(&EmbedCallback, | 446 ServiceProviderPtr sp; |
441 &result, &run_loop)); | 447 view_manager_init->Embed(url, sp.Pass(), |
| 448 base::Bind(&EmbedCallback, &result, &run_loop)); |
442 } | 449 } |
443 run_loop.Run(); | 450 run_loop.Run(); |
444 return result; | 451 return result; |
445 } | 452 } |
446 | 453 |
447 } // namespace | 454 } // namespace |
448 | 455 |
449 typedef std::vector<std::string> Changes; | 456 typedef std::vector<std::string> Changes; |
450 | 457 |
451 class ViewManagerTest : public testing::Test { | 458 class ViewManagerTest : public testing::Test { |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1464 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
1458 // originating connection. | 1465 // originating connection. |
1459 | 1466 |
1460 // TODO(beng): Add tests for focus: | 1467 // TODO(beng): Add tests for focus: |
1461 // - focus between two nodes known to a connection | 1468 // - focus between two nodes known to a connection |
1462 // - focus between nodes unknown to one of the connections. | 1469 // - focus between nodes unknown to one of the connections. |
1463 // - focus between nodes unknown to either connection. | 1470 // - focus between nodes unknown to either connection. |
1464 | 1471 |
1465 } // namespace service | 1472 } // namespace service |
1466 } // namespace mojo | 1473 } // namespace mojo |
OLD | NEW |