| 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/public/cpp/application/application.h" | 10 #include "mojo/public/cpp/application/application.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 void WaitForAllChangesToBeAcked(ViewManager* manager) { | 46 void WaitForAllChangesToBeAcked(ViewManager* manager) { |
| 47 ViewManagerPrivate(manager).synchronizer()->set_changes_acked_callback( | 47 ViewManagerPrivate(manager).synchronizer()->set_changes_acked_callback( |
| 48 base::Bind(&QuitRunLoopOnChangesAcked)); | 48 base::Bind(&QuitRunLoopOnChangesAcked)); |
| 49 DoRunLoop(); | 49 DoRunLoop(); |
| 50 ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback(); | 50 ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 class ConnectServiceLoader : public ServiceLoader { | 53 class ConnectServiceLoader : public ServiceLoader { |
| 54 public: | 54 public: |
| 55 explicit ConnectServiceLoader(base::Callback<void(ViewManager*)> callback) | 55 explicit ConnectServiceLoader(const ViewManager::RootCallback& callback) |
| 56 : callback_(callback) {} | 56 : callback_(callback) {} |
| 57 virtual ~ConnectServiceLoader() {} | 57 virtual ~ConnectServiceLoader() {} |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 // Overridden from ServiceLoader: | 60 // Overridden from ServiceLoader: |
| 61 virtual void LoadService(ServiceManager* manager, | 61 virtual void LoadService(ServiceManager* manager, |
| 62 const GURL& url, | 62 const GURL& url, |
| 63 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 63 ScopedMessagePipeHandle shell_handle) OVERRIDE { |
| 64 scoped_ptr<Application> app(new Application(shell_handle.Pass())); | 64 scoped_ptr<Application> app(new Application(shell_handle.Pass())); |
| 65 ViewManager::Create(app.get(), callback_); | 65 // TODO(beng): test removed callback. |
| 66 ViewManager::Create(app.get(), callback_, ViewManager::RootCallback()); |
| 66 apps_.push_back(app.release()); | 67 apps_.push_back(app.release()); |
| 67 } | 68 } |
| 68 virtual void OnServiceError(ServiceManager* manager, | 69 virtual void OnServiceError(ServiceManager* manager, |
| 69 const GURL& url) OVERRIDE { | 70 const GURL& url) OVERRIDE { |
| 70 } | 71 } |
| 71 | 72 |
| 72 ScopedVector<Application> apps_; | 73 ScopedVector<Application> apps_; |
| 73 base::Callback<void(ViewManager*)> callback_; | 74 ViewManager::RootCallback callback_; |
| 74 | 75 |
| 75 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); | 76 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 class ActiveViewChangedObserver : public ViewTreeNodeObserver { | 79 class ActiveViewChangedObserver : public ViewTreeNodeObserver { |
| 79 public: | 80 public: |
| 80 explicit ActiveViewChangedObserver(ViewTreeNode* node) | 81 explicit ActiveViewChangedObserver(ViewTreeNode* node) |
| 81 : node_(node) {} | 82 : node_(node) {} |
| 82 virtual ~ActiveViewChangedObserver() {} | 83 virtual ~ActiveViewChangedObserver() {} |
| 83 | 84 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 return view_manager; | 321 return view_manager; |
| 321 } | 322 } |
| 322 | 323 |
| 323 void UnloadApplication(const GURL& url) { | 324 void UnloadApplication(const GURL& url) { |
| 324 test_helper_.SetLoaderForURL(scoped_ptr<ServiceLoader>(), url); | 325 test_helper_.SetLoaderForURL(scoped_ptr<ServiceLoader>(), url); |
| 325 } | 326 } |
| 326 | 327 |
| 327 private: | 328 private: |
| 328 // Overridden from testing::Test: | 329 // Overridden from testing::Test: |
| 329 virtual void SetUp() OVERRIDE { | 330 virtual void SetUp() OVERRIDE { |
| 330 base::Callback<void(ViewManager*)> ready_callback = | 331 ViewManager::RootCallback ready_callback = |
| 331 base::Bind(&ViewManagerTest::OnViewManagerLoaded, | 332 base::Bind(&ViewManagerTest::OnViewManagerLoaded, |
| 332 base::Unretained(this)); | 333 base::Unretained(this)); |
| 333 test_helper_.Init(); | 334 test_helper_.Init(); |
| 334 test_helper_.SetLoaderForURL( | 335 test_helper_.SetLoaderForURL( |
| 335 scoped_ptr<ServiceLoader>(new ConnectServiceLoader(ready_callback)), | 336 scoped_ptr<ServiceLoader>(new ConnectServiceLoader(ready_callback)), |
| 336 GURL(kWindowManagerURL)); | 337 GURL(kWindowManagerURL)); |
| 337 test_helper_.SetLoaderForURL( | 338 test_helper_.SetLoaderForURL( |
| 338 scoped_ptr<ServiceLoader>(new ConnectServiceLoader(ready_callback)), | 339 scoped_ptr<ServiceLoader>(new ConnectServiceLoader(ready_callback)), |
| 339 GURL(kEmbeddedApp1URL)); | 340 GURL(kEmbeddedApp1URL)); |
| 340 | 341 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 355 bool result = false; | 356 bool result = false; |
| 356 view_manager_init->Connect( | 357 view_manager_init->Connect( |
| 357 url, | 358 url, |
| 358 base::Bind(&ViewManagerTest::ViewManagerInitConnectCallback, | 359 base::Bind(&ViewManagerTest::ViewManagerInitConnectCallback, |
| 359 base::Unretained(this), &result)); | 360 base::Unretained(this), &result)); |
| 360 RunRunLoop(); | 361 RunRunLoop(); |
| 361 window_manager_ = GetLoadedViewManager(); | 362 window_manager_ = GetLoadedViewManager(); |
| 362 return result; | 363 return result; |
| 363 } | 364 } |
| 364 | 365 |
| 365 void OnViewManagerLoaded(ViewManager* view_manager) { | 366 void OnViewManagerLoaded(ViewManager* view_manager, ViewTreeNode* root) { |
| 366 loaded_view_manager_ = view_manager; | 367 loaded_view_manager_ = view_manager; |
| 367 connect_loop_->Quit(); | 368 connect_loop_->Quit(); |
| 368 } | 369 } |
| 369 | 370 |
| 370 void RunRunLoop() { | 371 void RunRunLoop() { |
| 371 base::RunLoop run_loop; | 372 base::RunLoop run_loop; |
| 372 connect_loop_ = &run_loop; | 373 connect_loop_ = &run_loop; |
| 373 connect_loop_->Run(); | 374 connect_loop_->Run(); |
| 374 connect_loop_ = NULL; | 375 connect_loop_ = NULL; |
| 375 } | 376 } |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 window_manager()->roots().front()->AddChild(node1); | 692 window_manager()->roots().front()->AddChild(node1); |
| 692 ViewTreeNode* node2 = ViewTreeNode::Create(window_manager()); | 693 ViewTreeNode* node2 = ViewTreeNode::Create(window_manager()); |
| 693 window_manager()->roots().front()->AddChild(node2); | 694 window_manager()->roots().front()->AddChild(node2); |
| 694 ViewManager* embedded1 = Embed(window_manager(), node1); | 695 ViewManager* embedded1 = Embed(window_manager(), node1); |
| 695 ViewManager* embedded2 = Embed(window_manager(), node2); | 696 ViewManager* embedded2 = Embed(window_manager(), node2); |
| 696 EXPECT_EQ(embedded1, embedded2); | 697 EXPECT_EQ(embedded1, embedded2); |
| 697 } | 698 } |
| 698 | 699 |
| 699 } // namespace view_manager | 700 } // namespace view_manager |
| 700 } // namespace mojo | 701 } // namespace mojo |
| OLD | NEW |