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 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 } | 1149 } |
1150 | 1150 |
1151 TEST_F(ViewManagerTest, ConnectTwice) { | 1151 TEST_F(ViewManagerTest, ConnectTwice) { |
1152 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1152 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
1153 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1153 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
1154 | 1154 |
1155 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1155 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1156 | 1156 |
1157 // Try to connect again to 1,1, this should fail as already connected to that | 1157 // Try to connect again to 1,1, this should fail as already connected to that |
1158 // root. | 1158 // root. |
1159 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1159 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
1160 | 1160 |
1161 // Connecting to 1,2 should succeed and end up in connection2. | 1161 // Connecting to 1,2 should succeed and end up in connection2. |
1162 { | 1162 { |
1163 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); | 1163 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); |
1164 connection2_->DoRunLoopUntilChangesCount(1); | 1164 connection2_->DoRunLoopUntilChangesCount(1); |
1165 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1165 const Changes changes(ChangesToDescription1(connection2_->changes())); |
1166 ASSERT_EQ(1u, changes.size()); | 1166 ASSERT_EQ(1u, changes.size()); |
1167 EXPECT_EQ("OnEmbed creator=mojo:test_url", changes[0]); | 1167 EXPECT_EQ("NodeDeleted node=1,1", changes[0]); |
1168 EXPECT_EQ("[node=1,2 parent=null]", | |
1169 ChangeNodeDescription(connection2_->changes())); | |
1170 } | 1168 } |
1171 } | 1169 } |
1172 | 1170 |
1173 TEST_F(ViewManagerTest, OnNodeInput) { | 1171 TEST_F(ViewManagerTest, OnNodeInput) { |
1174 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1172 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
1175 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1173 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1176 | 1174 |
1177 // Dispatch an event to the node and verify its received. | 1175 // Dispatch an event to the node and verify its received. |
1178 { | 1176 { |
1179 EventPtr event(Event::New()); | 1177 EventPtr event(Event::New()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 | 1224 |
1227 // Connection 1 should have been told about the add (it owns the node). | 1225 // Connection 1 should have been told about the add (it owns the node). |
1228 { | 1226 { |
1229 connection_->DoRunLoopUntilChangesCount(1); | 1227 connection_->DoRunLoopUntilChangesCount(1); |
1230 const Changes changes(ChangesToDescription1(connection_->changes())); | 1228 const Changes changes(ChangesToDescription1(connection_->changes())); |
1231 ASSERT_EQ(1u, changes.size()); | 1229 ASSERT_EQ(1u, changes.size()); |
1232 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null", | 1230 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null", |
1233 changes[0]); | 1231 changes[0]); |
1234 } | 1232 } |
1235 | 1233 |
1236 // Embed 1,1 back in connection 2. | 1234 // Embed 1,1 again. |
1237 { | 1235 { |
1238 // 2 should be told about the new embed. | 1236 // We should get a new connection for the new embedding. |
1239 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1237 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
1240 connection2_->DoRunLoopUntilChangesCount(1); | 1238 ViewManagerProxy* connection4 = ViewManagerProxy::WaitForInstance(); |
1241 const std::vector<Change>& changes(connection2_->changes()); | 1239 connection4->DoRunLoopUntilChangesCount(1); |
| 1240 const std::vector<Change>& changes(connection4->changes()); |
1242 ASSERT_EQ(1u, changes.size()); | 1241 ASSERT_EQ(1u, changes.size()); |
1243 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 1242 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
1244 ChangesToDescription1(changes)[0]); | 1243 ChangesToDescription1(changes)[0]); |
1245 EXPECT_EQ("[node=1,1 parent=null]", | 1244 EXPECT_EQ("[node=1,1 parent=null]", |
1246 ChangeNodeDescription(changes)); | 1245 ChangeNodeDescription(changes)); |
1247 | 1246 |
1248 // And 3 should get a delete. | 1247 // And 3 should get a delete. |
1249 connection3_->DoRunLoopUntilChangesCount(1); | 1248 connection3_->DoRunLoopUntilChangesCount(1); |
1250 ASSERT_EQ(1u, connection3_->changes().size()); | 1249 ASSERT_EQ(1u, connection3_->changes().size()); |
1251 EXPECT_EQ("NodeDeleted node=1,1", | 1250 EXPECT_EQ("NodeDeleted node=1,1", |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1283 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
1285 // originating connection. | 1284 // originating connection. |
1286 | 1285 |
1287 // TODO(beng): Add tests for focus: | 1286 // TODO(beng): Add tests for focus: |
1288 // - focus between two nodes known to a connection | 1287 // - focus between two nodes known to a connection |
1289 // - focus between nodes unknown to one of the connections. | 1288 // - focus between nodes unknown to one of the connections. |
1290 // - focus between nodes unknown to either connection. | 1289 // - focus between nodes unknown to either connection. |
1291 | 1290 |
1292 } // namespace service | 1291 } // namespace service |
1293 } // namespace mojo | 1292 } // namespace mojo |
OLD | NEW |