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

Side by Side Diff: mojo/services/view_manager/view_manager_unittest.cc

Issue 405163002: Add EmbedRoot to ViewManagerService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
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 <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"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 Id old_view_id) OVERRIDE { 356 Id old_view_id) OVERRIDE {
357 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); 357 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id);
358 } 358 }
359 virtual void OnViewInputEvent(Id view_id, 359 virtual void OnViewInputEvent(Id view_id,
360 EventPtr event, 360 EventPtr event,
361 const Callback<void()>& callback) OVERRIDE { 361 const Callback<void()>& callback) OVERRIDE {
362 tracker_.OnViewInputEvent(view_id, event.Pass()); 362 tracker_.OnViewInputEvent(view_id, event.Pass());
363 } 363 }
364 virtual void OnFocusChanged(Id gained_focus_id, 364 virtual void OnFocusChanged(Id gained_focus_id,
365 Id lost_focus_id) OVERRIDE {} 365 Id lost_focus_id) OVERRIDE {}
366 virtual void EmbedRoot(const String& url) OVERRIDE { 366 virtual void Embed(const String& url) OVERRIDE {
367 tracker_.OnEmbedRoot(url); 367 tracker_.OnEmbed(url);
368 } 368 }
369 virtual void DispatchOnViewInputEvent(Id view_id, 369 virtual void DispatchOnViewInputEvent(Id view_id,
370 mojo::EventPtr event) OVERRIDE { 370 mojo::EventPtr event) OVERRIDE {
371 } 371 }
372 372
373 private: 373 private:
374 TestChangeTracker tracker_; 374 TestChangeTracker tracker_;
375 ViewManagerProxy connection_; 375 ViewManagerProxy connection_;
376 376
377 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); 377 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 ConnectionSpecificId node_id) { 414 ConnectionSpecificId node_id) {
415 return (connection_id << 16) | node_id; 415 return (connection_id << 16) | node_id;
416 } 416 }
417 417
418 // Creates an id used for transport from the specified parameters. 418 // Creates an id used for transport from the specified parameters.
419 Id BuildViewId(ConnectionSpecificId connection_id, 419 Id BuildViewId(ConnectionSpecificId connection_id,
420 ConnectionSpecificId view_id) { 420 ConnectionSpecificId view_id) {
421 return (connection_id << 16) | view_id; 421 return (connection_id << 16) | view_id;
422 } 422 }
423 423
424 // Callback from EmbedRoot(). |result| is the result of the 424 // Callback from Embed(). |result| is the result of the
425 // Embed() call and |run_loop| the nested RunLoop. 425 // Embed() call and |run_loop| the nested RunLoop.
426 void EmbedRootCallback(bool* result_cache, 426 void EmbedCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
427 base::RunLoop* run_loop,
428 bool result) {
429 *result_cache = result; 427 *result_cache = result;
430 run_loop->Quit(); 428 run_loop->Quit();
431 } 429 }
432 430
433 // Responsible for establishing the initial ViewManagerService connection. 431 // Embed from an application that does not yet have a view manager connection.
434 // Blocks until result is determined. 432 // Blocks until result is determined.
435 bool EmbedRoot(ViewManagerInitService* view_manager_init, 433 bool InitEmbed(ViewManagerInitService* view_manager_init,
436 const std::string& url) { 434 const std::string& url,
435 size_t number_of_calls) {
437 bool result = false; 436 bool result = false;
438 base::RunLoop run_loop; 437 base::RunLoop run_loop;
439 view_manager_init->EmbedRoot(url, base::Bind(&EmbedRootCallback, 438 for (size_t i = 0; i < number_of_calls; ++i) {
440 &result, &run_loop)); 439 view_manager_init->Embed(url, base::Bind(&EmbedCallback,
440 &result, &run_loop));
441 }
441 run_loop.Run(); 442 run_loop.Run();
442 return result; 443 return result;
443 } 444 }
444 445
445 } // namespace 446 } // namespace
446 447
447 typedef std::vector<std::string> Changes; 448 typedef std::vector<std::string> Changes;
448 449
449 class ViewManagerTest : public testing::Test { 450 class ViewManagerTest : public testing::Test {
450 public: 451 public:
451 ViewManagerTest() : connection_(NULL), connection2_(NULL) {} 452 ViewManagerTest() : connection_(NULL), connection2_(NULL) {}
452 453
453 virtual void SetUp() OVERRIDE { 454 virtual void SetUp() OVERRIDE {
454 test_helper_.Init(); 455 test_helper_.Init();
455 456
456 test_helper_.SetLoaderForURL( 457 test_helper_.SetLoaderForURL(
457 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 458 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
458 GURL(kTestServiceURL)); 459 GURL(kTestServiceURL));
459 460
460 test_helper_.SetLoaderForURL( 461 test_helper_.SetLoaderForURL(
461 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 462 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
462 GURL(kTestServiceURL2)); 463 GURL(kTestServiceURL2));
463 464
464 test_helper_.service_manager()->ConnectToService( 465 test_helper_.service_manager()->ConnectToService(
465 GURL("mojo:mojo_view_manager"), 466 GURL("mojo:mojo_view_manager"),
466 &view_manager_init_); 467 &view_manager_init_);
467 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); 468 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
468 469
469 connection_ = ViewManagerProxy::WaitForInstance(); 470 connection_ = ViewManagerProxy::WaitForInstance();
470 ASSERT_TRUE(connection_ != NULL); 471 ASSERT_TRUE(connection_ != NULL);
471 connection_->DoRunLoopUntilChangesCount(1); 472 connection_->DoRunLoopUntilChangesCount(1);
472 } 473 }
473 474
474 virtual void TearDown() OVERRIDE { 475 virtual void TearDown() OVERRIDE {
475 if (connection2_) 476 if (connection2_)
476 connection2_->Destroy(); 477 connection2_->Destroy();
477 if (connection_) 478 if (connection_)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 shell::ShellTestHelper test_helper_; 514 shell::ShellTestHelper test_helper_;
514 515
515 ViewManagerInitServicePtr view_manager_init_; 516 ViewManagerInitServicePtr view_manager_init_;
516 517
517 ViewManagerProxy* connection_; 518 ViewManagerProxy* connection_;
518 ViewManagerProxy* connection2_; 519 ViewManagerProxy* connection2_;
519 520
520 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 521 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
521 }; 522 };
522 523
523 TEST_F(ViewManagerTest, SecondEmbedRoot) { 524 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) {
524 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); 525 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
525 connection_->DoRunLoopUntilChangesCount(1); 526 connection_->DoRunLoopUntilChangesCount(1);
526 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); 527 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
527 } 528 }
528 529
530 TEST_F(ViewManagerTest, SecondEmbedRoot_Service) {
531 ASSERT_TRUE(connection_->Embed(BuildNodeId(0, 0), kTestServiceURL));
532 connection_->DoRunLoopUntilChangesCount(1);
533 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
534 }
535
536 TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) {
537 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 2));
538 connection_->DoRunLoopUntilChangesCount(2);
539 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
540 EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url);
541 }
542
529 // Verifies client gets a valid id. 543 // Verifies client gets a valid id.
530 TEST_F(ViewManagerTest, ValidId) { 544 TEST_F(ViewManagerTest, ValidId) {
531 // TODO(beng): this should really have the URL of the application that 545 // TODO(beng): this should really have the URL of the application that
532 // connected to ViewManagerInit. 546 // connected to ViewManagerInit.
533 EXPECT_EQ("OnConnectionEstablished creator=", 547 EXPECT_EQ("OnConnectionEstablished creator=",
534 ChangesToDescription1(connection_->changes())[0]); 548 ChangesToDescription1(connection_->changes())[0]);
535 549
536 // All these tests assume 1 for the client id. The only real assertion here is 550 // All these tests assume 1 for the client id. The only real assertion here is
537 // the client id is not zero, but adding this as rest of code here assumes 1. 551 // the client id is not zero, but adding this as rest of code here assumes 1.
538 EXPECT_EQ(1, connection_->changes()[0].connection_id); 552 EXPECT_EQ(1, connection_->changes()[0].connection_id);
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 // originating connection. 1408 // originating connection.
1395 1409
1396 // TODO(beng): Add tests for focus: 1410 // TODO(beng): Add tests for focus:
1397 // - focus between two nodes known to a connection 1411 // - focus between two nodes known to a connection
1398 // - focus between nodes unknown to one of the connections. 1412 // - focus between nodes unknown to one of the connections.
1399 // - focus between nodes unknown to either connection. 1413 // - focus between nodes unknown to either connection.
1400 1414
1401 } // namespace service 1415 } // namespace service
1402 } // namespace view_manager 1416 } // namespace view_manager
1403 } // namespace mojo 1417 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | mojo/services/window_manager/window_manager_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698