Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: services/view_manager/view_manager_client_apptest.cc

Issue 996533002: Remove hardcoded tests URLs from apptests. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Edit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/view_manager/public/cpp/view_manager.h" 5 #include "mojo/services/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 "mojo/public/cpp/application/application_connection.h" 14 #include "mojo/public/cpp/application/application_connection.h"
15 #include "mojo/public/cpp/application/application_delegate.h" 15 #include "mojo/public/cpp/application/application_delegate.h"
16 #include "mojo/public/cpp/application/application_impl.h" 16 #include "mojo/public/cpp/application/application_impl.h"
17 #include "mojo/public/cpp/application/application_test_base.h" 17 #include "mojo/public/cpp/application/application_test_base.h"
18 #include "mojo/public/cpp/application/service_provider_impl.h" 18 #include "mojo/public/cpp/application/service_provider_impl.h"
19 #include "mojo/services/geometry/public/cpp/geometry_util.h" 19 #include "mojo/services/geometry/public/cpp/geometry_util.h"
20 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h" 20 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h"
21 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h" 21 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
22 #include "mojo/services/view_manager/public/cpp/view_manager_context.h" 22 #include "mojo/services/view_manager/public/cpp/view_manager_context.h"
23 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h" 23 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
24 #include "mojo/services/view_manager/public/cpp/view_observer.h" 24 #include "mojo/services/view_manager/public/cpp/view_observer.h"
25 25
26 namespace mojo { 26 namespace mojo {
27 27
28 namespace { 28 namespace {
29 29
30 const char kViewManagerClientTestAppURL[] =
31 "mojo:mojo_view_manager_client_apptests";
32
33 base::RunLoop* current_run_loop = nullptr; 30 base::RunLoop* current_run_loop = nullptr;
34 31
35 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { 32 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
36 CHECK(current_run_loop); 33 CHECK(current_run_loop);
37 *timeout = true; 34 *timeout = true;
38 timeout_task.Run(); 35 timeout_task.Run();
39 } 36 }
40 37
41 bool DoRunLoopWithTimeout() { 38 bool DoRunLoopWithTimeout() {
42 if (current_run_loop != nullptr) 39 if (current_run_loop != nullptr)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 connection->AddService(view_manager_client_factory_.get()); 196 connection->AddService(view_manager_client_factory_.get());
200 return true; 197 return true;
201 } 198 }
202 199
203 ViewManager* window_manager() { return window_manager_; } 200 ViewManager* window_manager() { return window_manager_; }
204 201
205 // Embeds another version of the test app @ view; returns nullptr on timeout. 202 // Embeds another version of the test app @ view; returns nullptr on timeout.
206 ViewManager* Embed(ViewManager* view_manager, View* view) { 203 ViewManager* Embed(ViewManager* view_manager, View* view) {
207 DCHECK_EQ(view_manager, view->view_manager()); 204 DCHECK_EQ(view_manager, view->view_manager());
208 most_recent_view_manager_ = nullptr; 205 most_recent_view_manager_ = nullptr;
209 view->Embed(kViewManagerClientTestAppURL); 206 view->Embed(application_impl()->url());
210 if (!DoRunLoopWithTimeout()) 207 if (!DoRunLoopWithTimeout())
211 return nullptr; 208 return nullptr;
212 ViewManager* vm = nullptr; 209 ViewManager* vm = nullptr;
213 std::swap(vm, most_recent_view_manager_); 210 std::swap(vm, most_recent_view_manager_);
214 return vm; 211 return vm;
215 } 212 }
216 213
217 ApplicationDelegate* GetApplicationDelegate() override { return this; } 214 ApplicationDelegate* GetApplicationDelegate() override { return this; }
218 215
219 // Overridden from ViewManagerDelegate: 216 // Overridden from ViewManagerDelegate:
220 void OnEmbed(View* root, 217 void OnEmbed(View* root,
221 InterfaceRequest<ServiceProvider> services, 218 InterfaceRequest<ServiceProvider> services,
222 ServiceProviderPtr exposed_services) override { 219 ServiceProviderPtr exposed_services) override {
223 most_recent_view_manager_ = root->view_manager(); 220 most_recent_view_manager_ = root->view_manager();
224 QuitRunLoop(); 221 QuitRunLoop();
225 } 222 }
226 void OnViewManagerDisconnected(ViewManager* view_manager) override {} 223 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
227 224
228 private: 225 private:
229 // Overridden from testing::Test: 226 // Overridden from testing::Test:
230 void SetUp() override { 227 void SetUp() override {
231 ApplicationTestBase::SetUp(); 228 ApplicationTestBase::SetUp();
232 229
233 view_manager_context_.reset(new ViewManagerContext(application_impl())); 230 view_manager_context_.reset(new ViewManagerContext(application_impl()));
234 view_manager_context_->Embed(kViewManagerClientTestAppURL); 231 view_manager_context_->Embed(application_impl()->url());
235 ASSERT_TRUE(DoRunLoopWithTimeout()); 232 ASSERT_TRUE(DoRunLoopWithTimeout());
236 std::swap(window_manager_, most_recent_view_manager_); 233 std::swap(window_manager_, most_recent_view_manager_);
237 } 234 }
238 235
239 // Overridden from testing::Test: 236 // Overridden from testing::Test:
240 void TearDown() override { ApplicationTestBase::TearDown(); } 237 void TearDown() override { ApplicationTestBase::TearDown(); }
241 238
242 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; 239 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
243 240
244 scoped_ptr<ViewManagerContext> view_manager_context_; 241 scoped_ptr<ViewManagerContext> view_manager_context_;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ASSERT_NE(nullptr, embedded2); 377 ASSERT_NE(nullptr, embedded2);
381 EXPECT_NE(embedded1, embedded2); 378 EXPECT_NE(embedded1, embedded2);
382 } 379 }
383 380
384 TEST_F(ViewManagerTest, EmbeddingIdentity) { 381 TEST_F(ViewManagerTest, EmbeddingIdentity) {
385 View* view = window_manager()->CreateView(); 382 View* view = window_manager()->CreateView();
386 view->SetVisible(true); 383 view->SetVisible(true);
387 window_manager()->GetRoot()->AddChild(view); 384 window_manager()->GetRoot()->AddChild(view);
388 ViewManager* embedded = Embed(window_manager(), view); 385 ViewManager* embedded = Embed(window_manager(), view);
389 ASSERT_NE(nullptr, embedded); 386 ASSERT_NE(nullptr, embedded);
390 EXPECT_EQ(kViewManagerClientTestAppURL, embedded->GetEmbedderURL()); 387 EXPECT_EQ(application_impl()->url(), embedded->GetEmbedderURL());
391 } 388 }
392 389
393 // TODO(alhaad): Currently, the RunLoop gets stuck waiting for order change. 390 // TODO(alhaad): Currently, the RunLoop gets stuck waiting for order change.
394 // Debug and re-enable this. 391 // Debug and re-enable this.
395 TEST_F(ViewManagerTest, DISABLED_Reorder) { 392 TEST_F(ViewManagerTest, DISABLED_Reorder) {
396 View* view1 = window_manager()->CreateView(); 393 View* view1 = window_manager()->CreateView();
397 view1->SetVisible(true); 394 view1->SetVisible(true);
398 window_manager()->GetRoot()->AddChild(view1); 395 window_manager()->GetRoot()->AddChild(view1);
399 396
400 ViewManager* embedded = Embed(window_manager(), view1); 397 ViewManager* embedded = Embed(window_manager(), view1);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 view11->SetFocus(); 604 view11->SetFocus();
608 ASSERT_TRUE(DoRunLoopWithTimeout()); 605 ASSERT_TRUE(DoRunLoopWithTimeout());
609 ASSERT_NE(nullptr, observer.last_gained_focus()); 606 ASSERT_NE(nullptr, observer.last_gained_focus());
610 ASSERT_NE(nullptr, observer.last_lost_focus()); 607 ASSERT_NE(nullptr, observer.last_lost_focus());
611 EXPECT_EQ(view11->id(), observer.last_gained_focus()->id()); 608 EXPECT_EQ(view11->id(), observer.last_gained_focus()->id());
612 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_lost_focus()->id()); 609 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_lost_focus()->id());
613 } 610 }
614 } 611 }
615 612
616 } // namespace mojo 613 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/lib/application_test_base.cc ('k') | services/view_manager/view_manager_service_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698