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 "components/view_manager/public/cpp/view_manager.h" | 5 #include "components/view_manager/public/cpp/view_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
14 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h" | 14 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h" |
15 #include "components/view_manager/public/cpp/view_manager_client_factory.h" | 15 #include "components/view_manager/public/cpp/view_manager_client_factory.h" |
16 #include "components/view_manager/public/cpp/view_manager_context.h" | |
17 #include "components/view_manager/public/cpp/view_manager_delegate.h" | 16 #include "components/view_manager/public/cpp/view_manager_delegate.h" |
| 17 #include "components/view_manager/public/cpp/view_manager_init.h" |
18 #include "components/view_manager/public/cpp/view_observer.h" | 18 #include "components/view_manager/public/cpp/view_observer.h" |
19 #include "mojo/application/application_test_base_chromium.h" | 19 #include "mojo/application/application_test_base_chromium.h" |
20 #include "mojo/application/public/cpp/application_connection.h" | 20 #include "mojo/application/public/cpp/application_connection.h" |
21 #include "mojo/application/public/cpp/application_delegate.h" | 21 #include "mojo/application/public/cpp/application_delegate.h" |
22 #include "mojo/application/public/cpp/application_impl.h" | 22 #include "mojo/application/public/cpp/application_impl.h" |
23 #include "mojo/application/public/cpp/service_provider_impl.h" | 23 #include "mojo/application/public/cpp/service_provider_impl.h" |
24 #include "ui/mojo/geometry/geometry_util.h" | 24 #include "ui/mojo/geometry/geometry_util.h" |
25 | 25 |
26 namespace mojo { | 26 namespace mojo { |
27 | 27 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 most_recent_view_manager_ = root->view_manager(); | 220 most_recent_view_manager_ = root->view_manager(); |
221 QuitRunLoop(); | 221 QuitRunLoop(); |
222 } | 222 } |
223 void OnViewManagerDisconnected(ViewManager* view_manager) override {} | 223 void OnViewManagerDisconnected(ViewManager* view_manager) override {} |
224 | 224 |
225 private: | 225 private: |
226 // Overridden from testing::Test: | 226 // Overridden from testing::Test: |
227 void SetUp() override { | 227 void SetUp() override { |
228 ApplicationTestBase::SetUp(); | 228 ApplicationTestBase::SetUp(); |
229 | 229 |
230 view_manager_context_.reset(new ViewManagerContext(application_impl())); | 230 view_manager_init_.reset( |
231 view_manager_context_->Embed(application_impl()->url()); | 231 new ViewManagerInit(application_impl(), this, nullptr)); |
232 ASSERT_TRUE(DoRunLoopWithTimeout()); | 232 ASSERT_TRUE(DoRunLoopWithTimeout()); |
233 std::swap(window_manager_, most_recent_view_manager_); | 233 std::swap(window_manager_, most_recent_view_manager_); |
234 } | 234 } |
235 | 235 |
236 // Overridden from testing::Test: | 236 // Overridden from testing::Test: |
237 void TearDown() override { ApplicationTestBase::TearDown(); } | 237 void TearDown() override { ApplicationTestBase::TearDown(); } |
238 | 238 |
| 239 scoped_ptr<ViewManagerInit> view_manager_init_; |
| 240 |
239 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 241 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
240 | 242 |
241 scoped_ptr<ViewManagerContext> view_manager_context_; | |
242 | |
243 // Used to receive the most recent view manager loaded by an embed action. | 243 // Used to receive the most recent view manager loaded by an embed action. |
244 ViewManager* most_recent_view_manager_; | 244 ViewManager* most_recent_view_manager_; |
245 // The View Manager connection held by the window manager (app running at the | 245 // The View Manager connection held by the window manager (app running at the |
246 // root view). | 246 // root view). |
247 ViewManager* window_manager_; | 247 ViewManager* window_manager_; |
248 | 248 |
249 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | 249 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
250 }; | 250 }; |
251 | 251 |
252 TEST_F(ViewManagerTest, RootView) { | 252 TEST_F(ViewManagerTest, RootView) { |
253 ASSERT_NE(nullptr, window_manager()); | 253 ASSERT_NE(nullptr, window_manager()); |
254 EXPECT_NE(nullptr, window_manager()->GetRoot()); | 254 EXPECT_NE(nullptr, window_manager()->GetRoot()); |
255 EXPECT_EQ("mojo:window_manager", window_manager()->GetEmbedderURL()); | 255 // No one embedded the window_manager(), so it has no url. |
| 256 EXPECT_TRUE(window_manager()->GetEmbedderURL().empty()); |
256 } | 257 } |
257 | 258 |
258 TEST_F(ViewManagerTest, Embed) { | 259 TEST_F(ViewManagerTest, Embed) { |
259 View* view = window_manager()->CreateView(); | 260 View* view = window_manager()->CreateView(); |
260 ASSERT_NE(nullptr, view); | 261 ASSERT_NE(nullptr, view); |
261 view->SetVisible(true); | 262 view->SetVisible(true); |
262 window_manager()->GetRoot()->AddChild(view); | 263 window_manager()->GetRoot()->AddChild(view); |
263 ViewManager* embedded = Embed(window_manager(), view); | 264 ViewManager* embedded = Embed(window_manager(), view); |
264 ASSERT_NE(nullptr, embedded); | 265 ASSERT_NE(nullptr, embedded); |
265 | 266 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 view11->SetFocus(); | 605 view11->SetFocus(); |
605 ASSERT_TRUE(DoRunLoopWithTimeout()); | 606 ASSERT_TRUE(DoRunLoopWithTimeout()); |
606 ASSERT_NE(nullptr, observer.last_gained_focus()); | 607 ASSERT_NE(nullptr, observer.last_gained_focus()); |
607 ASSERT_NE(nullptr, observer.last_lost_focus()); | 608 ASSERT_NE(nullptr, observer.last_lost_focus()); |
608 EXPECT_EQ(view11->id(), observer.last_gained_focus()->id()); | 609 EXPECT_EQ(view11->id(), observer.last_gained_focus()->id()); |
609 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_lost_focus()->id()); | 610 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_lost_focus()->id()); |
610 } | 611 } |
611 } | 612 } |
612 | 613 |
613 } // namespace mojo | 614 } // namespace mojo |
OLD | NEW |