| 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 <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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 main_loop_(NULL), | 53 main_loop_(NULL), |
| 54 view_manager_(NULL), | 54 view_manager_(NULL), |
| 55 quit_count_(0), | 55 quit_count_(0), |
| 56 router_(NULL) { | 56 router_(NULL) { |
| 57 SetInstance(this); | 57 SetInstance(this); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual ~ViewManagerProxy() { | 60 virtual ~ViewManagerProxy() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Returns true if in an initial state. If this returns false it means the |
| 64 // last test didn't clean up properly, or most likely didn't invoke |
| 65 // WaitForInstance() when it needed to. |
| 66 static bool IsInInitialState() { return instance_ == NULL; } |
| 67 |
| 63 // Runs a message loop until the single instance has been created. | 68 // Runs a message loop until the single instance has been created. |
| 64 static ViewManagerProxy* WaitForInstance() { | 69 static ViewManagerProxy* WaitForInstance() { |
| 65 if (!instance_) | 70 if (!instance_) |
| 66 RunMainLoop(); | 71 RunMainLoop(); |
| 67 ViewManagerProxy* instance = instance_; | 72 ViewManagerProxy* instance = instance_; |
| 68 instance_ = NULL; | 73 instance_ = NULL; |
| 69 return instance; | 74 return instance; |
| 70 } | 75 } |
| 71 | 76 |
| 72 ViewManagerService* view_manager() { return view_manager_; } | 77 ViewManagerService* view_manager() { return view_manager_; } |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 typedef std::vector<std::string> Changes; | 447 typedef std::vector<std::string> Changes; |
| 443 | 448 |
| 444 class ViewManagerTest : public testing::Test { | 449 class ViewManagerTest : public testing::Test { |
| 445 public: | 450 public: |
| 446 ViewManagerTest() | 451 ViewManagerTest() |
| 447 : connection_(NULL), | 452 : connection_(NULL), |
| 448 connection2_(NULL), | 453 connection2_(NULL), |
| 449 connection3_(NULL) {} | 454 connection3_(NULL) {} |
| 450 | 455 |
| 451 virtual void SetUp() OVERRIDE { | 456 virtual void SetUp() OVERRIDE { |
| 457 ASSERT_TRUE(ViewManagerProxy::IsInInitialState()); |
| 458 |
| 452 test_helper_.Init(); | 459 test_helper_.Init(); |
| 453 | 460 |
| 454 test_helper_.SetLoaderForURL( | 461 test_helper_.SetLoaderForURL( |
| 455 scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()), | 462 scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()), |
| 456 GURL(kTestServiceURL)); | 463 GURL(kTestServiceURL)); |
| 457 | 464 |
| 458 test_helper_.SetLoaderForURL( | 465 test_helper_.SetLoaderForURL( |
| 459 scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()), | 466 scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()), |
| 460 GURL(kTestServiceURL2)); | 467 GURL(kTestServiceURL2)); |
| 461 | 468 |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 // Should get nothing for view 2. | 1171 // Should get nothing for view 2. |
| 1165 connection2_->GetViewTree(BuildViewId(1, 2), &views); | 1172 connection2_->GetViewTree(BuildViewId(1, 2), &views); |
| 1166 ASSERT_TRUE(views.empty()); | 1173 ASSERT_TRUE(views.empty()); |
| 1167 | 1174 |
| 1168 // Should get view 1 if asked for. | 1175 // Should get view 1 if asked for. |
| 1169 connection2_->GetViewTree(BuildViewId(1, 1), &views); | 1176 connection2_->GetViewTree(BuildViewId(1, 1), &views); |
| 1170 ASSERT_EQ(1u, views.size()); | 1177 ASSERT_EQ(1u, views.size()); |
| 1171 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); | 1178 EXPECT_EQ("view=1,1 parent=null", views[0].ToString()); |
| 1172 } | 1179 } |
| 1173 | 1180 |
| 1174 TEST_F(ViewManagerTest, ConnectTwice) { | |
| 1175 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | |
| 1176 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); | |
| 1177 | |
| 1178 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | |
| 1179 | |
| 1180 // Try to connect again to 1,1, this should fail as already connected to that | |
| 1181 // root. | |
| 1182 ASSERT_TRUE(connection_->Embed(BuildViewId(1, 1), kTestServiceURL)); | |
| 1183 | |
| 1184 // Connecting to 1,2 should succeed and end up in connection2. | |
| 1185 { | |
| 1186 ASSERT_TRUE(connection_->Embed(BuildViewId(1, 2), kTestServiceURL)); | |
| 1187 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1188 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1189 ASSERT_EQ(1u, changes.size()); | |
| 1190 EXPECT_EQ("ViewDeleted view=1,1", changes[0]); | |
| 1191 } | |
| 1192 } | |
| 1193 | |
| 1194 TEST_F(ViewManagerTest, OnViewInput) { | 1181 TEST_F(ViewManagerTest, OnViewInput) { |
| 1195 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | 1182 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1196 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1183 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1197 | 1184 |
| 1198 // Dispatch an event to the view and verify its received. | 1185 // Dispatch an event to the view and verify its received. |
| 1199 { | 1186 { |
| 1200 EventPtr event(Event::New()); | 1187 EventPtr event(Event::New()); |
| 1201 event->action = static_cast<EventType>(1); | 1188 event->action = static_cast<EventType>(1); |
| 1202 connection_->view_manager()->DispatchOnViewInputEvent(BuildViewId(1, 1), | 1189 connection_->view_manager()->DispatchOnViewInputEvent(BuildViewId(1, 1), |
| 1203 event.Pass()); | 1190 event.Pass()); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 | 1421 |
| 1435 // TODO(sky): add coverage of test that destroys connections and ensures other | 1422 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1436 // connections get deletion notification. | 1423 // connections get deletion notification. |
| 1437 | 1424 |
| 1438 // TODO(sky): need to better track changes to initial connection. For example, | 1425 // TODO(sky): need to better track changes to initial connection. For example, |
| 1439 // that SetBounsdViews/AddView and the like don't result in messages to the | 1426 // that SetBounsdViews/AddView and the like don't result in messages to the |
| 1440 // originating connection. | 1427 // originating connection. |
| 1441 | 1428 |
| 1442 } // namespace service | 1429 } // namespace service |
| 1443 } // namespace mojo | 1430 } // namespace mojo |
| OLD | NEW |