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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "mojo/application_manager/application_manager.h" | 7 #include "mojo/application_manager/application_manager.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/service_provider_impl.h" | 10 #include "mojo/public/cpp/application/service_provider_impl.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 void set_focus_changed_callback(const TwoNodeCallback& callback) { | 59 void set_focus_changed_callback(const TwoNodeCallback& callback) { |
60 focus_changed_callback_ = callback; | 60 focus_changed_callback_ = callback; |
61 } | 61 } |
62 void set_active_window_changed_callback(const TwoNodeCallback& callback) { | 62 void set_active_window_changed_callback(const TwoNodeCallback& callback) { |
63 active_window_changed_callback_ = callback; | 63 active_window_changed_callback_ = callback; |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 // Overridden from WindowManagerClient: | 67 // Overridden from WindowManagerClient: |
68 virtual void OnWindowManagerReady() MOJO_OVERRIDE { | 68 virtual void OnWindowManagerReady() override { run_loop_->Quit(); } |
69 run_loop_->Quit(); | 69 virtual void OnCaptureChanged(Id old_capture_node_id, |
70 } | 70 Id new_capture_node_id) override {} |
71 virtual void OnCaptureChanged( | 71 virtual void OnFocusChanged(Id old_focused_node_id, |
72 Id old_capture_node_id, | 72 Id new_focused_node_id) override { |
73 Id new_capture_node_id) MOJO_OVERRIDE { | |
74 } | |
75 virtual void OnFocusChanged( | |
76 Id old_focused_node_id, | |
77 Id new_focused_node_id) MOJO_OVERRIDE { | |
78 if (!focus_changed_callback_.is_null()) | 73 if (!focus_changed_callback_.is_null()) |
79 focus_changed_callback_.Run(old_focused_node_id, new_focused_node_id); | 74 focus_changed_callback_.Run(old_focused_node_id, new_focused_node_id); |
80 } | 75 } |
81 virtual void OnActiveWindowChanged( | 76 virtual void OnActiveWindowChanged(Id old_active_window, |
82 Id old_active_window, | 77 Id new_active_window) override { |
83 Id new_active_window) MOJO_OVERRIDE { | |
84 if (!active_window_changed_callback_.is_null()) | 78 if (!active_window_changed_callback_.is_null()) |
85 active_window_changed_callback_.Run(old_active_window, new_active_window); | 79 active_window_changed_callback_.Run(old_active_window, new_active_window); |
86 } | 80 } |
87 | 81 |
88 base::RunLoop* run_loop_; | 82 base::RunLoop* run_loop_; |
89 TwoNodeCallback focus_changed_callback_; | 83 TwoNodeCallback focus_changed_callback_; |
90 TwoNodeCallback active_window_changed_callback_; | 84 TwoNodeCallback active_window_changed_callback_; |
91 | 85 |
92 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerClient); | 86 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerClient); |
93 }; | 87 }; |
94 | 88 |
95 class TestApplicationLoader : public ApplicationLoader, | 89 class TestApplicationLoader : public ApplicationLoader, |
96 public ApplicationDelegate, | 90 public ApplicationDelegate, |
97 public ViewManagerDelegate { | 91 public ViewManagerDelegate { |
98 public: | 92 public: |
99 typedef base::Callback<void(View*)> RootAddedCallback; | 93 typedef base::Callback<void(View*)> RootAddedCallback; |
100 | 94 |
101 explicit TestApplicationLoader(const RootAddedCallback& root_added_callback) | 95 explicit TestApplicationLoader(const RootAddedCallback& root_added_callback) |
102 : root_added_callback_(root_added_callback) {} | 96 : root_added_callback_(root_added_callback) {} |
103 virtual ~TestApplicationLoader() {} | 97 virtual ~TestApplicationLoader() {} |
104 | 98 |
105 private: | 99 private: |
106 // Overridden from ApplicationLoader: | 100 // Overridden from ApplicationLoader: |
107 virtual void Load(ApplicationManager* application_manager, | 101 virtual void Load(ApplicationManager* application_manager, |
108 const GURL& url, | 102 const GURL& url, |
109 scoped_refptr<LoadCallbacks> callbacks) MOJO_OVERRIDE { | 103 scoped_refptr<LoadCallbacks> callbacks) override { |
110 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 104 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
111 if (!shell_handle.is_valid()) | 105 if (!shell_handle.is_valid()) |
112 return; | 106 return; |
113 scoped_ptr<ApplicationImpl> app( | 107 scoped_ptr<ApplicationImpl> app( |
114 new ApplicationImpl(this, shell_handle.Pass())); | 108 new ApplicationImpl(this, shell_handle.Pass())); |
115 apps_.push_back(app.release()); | 109 apps_.push_back(app.release()); |
116 } | 110 } |
117 virtual void OnApplicationError(ApplicationManager* application_manager, | 111 virtual void OnApplicationError(ApplicationManager* application_manager, |
118 const GURL& url) MOJO_OVERRIDE {} | 112 const GURL& url) override {} |
119 | 113 |
120 // Overridden from ApplicationDelegate: | 114 // Overridden from ApplicationDelegate: |
121 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 115 virtual void Initialize(ApplicationImpl* app) override { |
122 view_manager_client_factory_.reset( | 116 view_manager_client_factory_.reset( |
123 new ViewManagerClientFactory(app->shell(), this)); | 117 new ViewManagerClientFactory(app->shell(), this)); |
124 } | 118 } |
125 | 119 |
126 virtual bool ConfigureIncomingConnection( | 120 virtual bool ConfigureIncomingConnection( |
127 ApplicationConnection* connection) MOJO_OVERRIDE { | 121 ApplicationConnection* connection) override { |
128 connection->AddService(view_manager_client_factory_.get()); | 122 connection->AddService(view_manager_client_factory_.get()); |
129 return true; | 123 return true; |
130 } | 124 } |
131 | 125 |
132 // Overridden from ViewManagerDelegate: | 126 // Overridden from ViewManagerDelegate: |
133 virtual void OnEmbed( | 127 virtual void OnEmbed(ViewManager* view_manager, |
134 ViewManager* view_manager, | 128 View* root, |
135 View* root, | 129 ServiceProviderImpl* exported_services, |
136 ServiceProviderImpl* exported_services, | 130 scoped_ptr<ServiceProvider> imported_services) override { |
137 scoped_ptr<ServiceProvider> imported_services) MOJO_OVERRIDE { | |
138 root_added_callback_.Run(root); | 131 root_added_callback_.Run(root); |
139 } | 132 } |
140 virtual void OnViewManagerDisconnected( | 133 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {} |
141 ViewManager* view_manager) MOJO_OVERRIDE { | |
142 } | |
143 | 134 |
144 RootAddedCallback root_added_callback_; | 135 RootAddedCallback root_added_callback_; |
145 | 136 |
146 ScopedVector<ApplicationImpl> apps_; | 137 ScopedVector<ApplicationImpl> apps_; |
147 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 138 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
148 | 139 |
149 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 140 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
150 }; | 141 }; |
151 | 142 |
152 } // namespace | 143 } // namespace |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 189 } |
199 | 190 |
200 TestWindowManagerClient* window_manager_client() { | 191 TestWindowManagerClient* window_manager_client() { |
201 return window_manager_client_.get(); | 192 return window_manager_client_.get(); |
202 } | 193 } |
203 | 194 |
204 WindowManagerServicePtr window_manager_; | 195 WindowManagerServicePtr window_manager_; |
205 | 196 |
206 private: | 197 private: |
207 // Overridden from testing::Test: | 198 // Overridden from testing::Test: |
208 virtual void SetUp() MOJO_OVERRIDE { | 199 virtual void SetUp() override { |
209 test_helper_.Init(); | 200 test_helper_.Init(); |
210 test_helper_.SetLoaderForURL( | 201 test_helper_.SetLoaderForURL( |
211 scoped_ptr<ApplicationLoader>(new TestApplicationLoader(base::Bind( | 202 scoped_ptr<ApplicationLoader>(new TestApplicationLoader(base::Bind( |
212 &WindowManagerApiTest::OnRootAdded, base::Unretained(this)))), | 203 &WindowManagerApiTest::OnRootAdded, base::Unretained(this)))), |
213 GURL(kTestServiceURL)); | 204 GURL(kTestServiceURL)); |
214 test_helper_.application_manager()->ConnectToService( | 205 test_helper_.application_manager()->ConnectToService( |
215 GURL("mojo:mojo_view_manager"), &view_manager_init_); | 206 GURL("mojo:mojo_view_manager"), &view_manager_init_); |
216 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), | 207 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), |
217 "mojo:mojo_core_window_manager")); | 208 "mojo:mojo_core_window_manager")); |
218 ConnectToWindowManager(); | 209 ConnectToWindowManager(); |
219 } | 210 } |
220 virtual void TearDown() MOJO_OVERRIDE {} | 211 virtual void TearDown() override {} |
221 | 212 |
222 void ConnectToWindowManager() { | 213 void ConnectToWindowManager() { |
223 test_helper_.application_manager()->ConnectToService( | 214 test_helper_.application_manager()->ConnectToService( |
224 GURL("mojo:mojo_core_window_manager"), &window_manager_); | 215 GURL("mojo:mojo_core_window_manager"), &window_manager_); |
225 base::RunLoop connect_loop; | 216 base::RunLoop connect_loop; |
226 window_manager_client_.reset(new TestWindowManagerClient(&connect_loop)); | 217 window_manager_client_.reset(new TestWindowManagerClient(&connect_loop)); |
227 window_manager_.set_client(window_manager_client()); | 218 window_manager_.set_client(window_manager_client()); |
228 connect_loop.Run(); | 219 connect_loop.Run(); |
229 } | 220 } |
230 | 221 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 269 |
279 Id second_window = OpenWindow(); | 270 Id second_window = OpenWindow(); |
280 window_manager_->ActivateWindow(second_window, | 271 window_manager_->ActivateWindow(second_window, |
281 base::Bind(&EmptyResultCallback)); | 272 base::Bind(&EmptyResultCallback)); |
282 ids = WaitForActiveWindowChange(); | 273 ids = WaitForActiveWindowChange(); |
283 EXPECT_EQ(ids.first, first_window); | 274 EXPECT_EQ(ids.first, first_window); |
284 EXPECT_EQ(ids.second, second_window); | 275 EXPECT_EQ(ids.second, second_window); |
285 } | 276 } |
286 | 277 |
287 } // namespace mojo | 278 } // namespace mojo |
OLD | NEW |