| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 view_manager->DeleteNode(node_id, change_id, | 108 view_manager->DeleteNode(node_id, change_id, |
| 109 base::Bind(&BooleanCallback, &result)); | 109 base::Bind(&BooleanCallback, &result)); |
| 110 DoRunLoop(); | 110 DoRunLoop(); |
| 111 return result; | 111 return result; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Adds a node, blocking until done. | 114 // Adds a node, blocking until done. |
| 115 bool AddNode(IViewManager* view_manager, | 115 bool AddNode(IViewManager* view_manager, |
| 116 TransportNodeId parent, | 116 TransportNodeId parent, |
| 117 TransportNodeId child, | 117 TransportNodeId child, |
| 118 TransportChangeId change_id) { | 118 TransportChangeId server_change_id, |
| 119 TransportChangeId client_change_id) { |
| 119 bool result = false; | 120 bool result = false; |
| 120 view_manager->AddNode(parent, child, change_id, | 121 view_manager->AddNode(parent, child, server_change_id, client_change_id, |
| 121 base::Bind(&BooleanCallback, &result)); | 122 base::Bind(&BooleanCallback, &result)); |
| 122 DoRunLoop(); | 123 DoRunLoop(); |
| 123 return result; | 124 return result; |
| 124 } | 125 } |
| 125 | 126 |
| 126 // Removes a node, blocking until done. | 127 // Removes a node, blocking until done. |
| 127 bool RemoveNodeFromParent(IViewManager* view_manager, | 128 bool RemoveNodeFromParent(IViewManager* view_manager, |
| 128 TransportNodeId node_id, | 129 TransportNodeId node_id, |
| 129 TransportChangeId change_id) { | 130 TransportChangeId server_change_id, |
| 131 TransportChangeId client_change_id) { |
| 130 bool result = false; | 132 bool result = false; |
| 131 view_manager->RemoveNodeFromParent(node_id, change_id, | 133 view_manager->RemoveNodeFromParent( |
| 132 base::Bind(&BooleanCallback, &result)); | 134 node_id, server_change_id, client_change_id, |
| 135 base::Bind(&BooleanCallback, &result)); |
| 133 DoRunLoop(); | 136 DoRunLoop(); |
| 134 return result; | 137 return result; |
| 135 } | 138 } |
| 136 | 139 |
| 137 void GetNodeTree(IViewManager* view_manager, | 140 void GetNodeTree(IViewManager* view_manager, |
| 138 TransportNodeId node_id, | 141 TransportNodeId node_id, |
| 139 std::vector<TestNode>* nodes) { | 142 std::vector<TestNode>* nodes) { |
| 140 view_manager->GetNodeTree(node_id, base::Bind(&INodesCallback, nodes)); | 143 view_manager->GetNodeTree(node_id, base::Bind(&INodesCallback, nodes)); |
| 141 DoRunLoop(); | 144 DoRunLoop(); |
| 142 } | 145 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 163 DoRunLoop(); | 166 DoRunLoop(); |
| 164 return result; | 167 return result; |
| 165 } | 168 } |
| 166 | 169 |
| 167 } // namespace | 170 } // namespace |
| 168 | 171 |
| 169 typedef std::vector<std::string> Changes; | 172 typedef std::vector<std::string> Changes; |
| 170 | 173 |
| 171 class ViewManagerClientImpl : public IViewManagerClient { | 174 class ViewManagerClientImpl : public IViewManagerClient { |
| 172 public: | 175 public: |
| 173 ViewManagerClientImpl() : id_(0), quit_count_(0) {} | 176 ViewManagerClientImpl() |
| 177 : id_(0), |
| 178 next_server_change_id_(0), |
| 179 quit_count_(0) {} |
| 174 | 180 |
| 175 TransportConnectionId id() const { return id_; } | 181 TransportConnectionId id() const { return id_; } |
| 176 | 182 |
| 183 TransportChangeId next_server_change_id() const { |
| 184 return next_server_change_id_; |
| 185 } |
| 186 |
| 177 Changes GetAndClearChanges() { | 187 Changes GetAndClearChanges() { |
| 178 Changes changes; | 188 Changes changes; |
| 179 changes.swap(changes_); | 189 changes.swap(changes_); |
| 180 return changes; | 190 return changes; |
| 181 } | 191 } |
| 182 | 192 |
| 183 void WaitForId() { | 193 void WaitForId() { |
| 184 if (id_ == 0) | 194 if (id_ == 0) |
| 185 DoRunLoop(); | 195 DoRunLoop(); |
| 186 } | 196 } |
| 187 | 197 |
| 188 void DoRunLoopUntilChangesCount(size_t count) { | 198 void DoRunLoopUntilChangesCount(size_t count) { |
| 189 if (changes_.size() >= count) | 199 if (changes_.size() >= count) |
| 190 return; | 200 return; |
| 191 quit_count_ = count - changes_.size(); | 201 quit_count_ = count - changes_.size(); |
| 192 DoRunLoop(); | 202 DoRunLoop(); |
| 193 } | 203 } |
| 194 | 204 |
| 195 private: | 205 private: |
| 196 // IViewManagerClient overrides: | 206 // IViewManagerClient overrides: |
| 197 virtual void OnConnectionEstablished( | 207 virtual void OnConnectionEstablished( |
| 198 TransportConnectionId connection_id) OVERRIDE { | 208 TransportConnectionId connection_id, |
| 209 TransportChangeId next_server_change_id) OVERRIDE { |
| 199 id_ = connection_id; | 210 id_ = connection_id; |
| 211 next_server_change_id_ = next_server_change_id; |
| 200 if (current_run_loop) | 212 if (current_run_loop) |
| 201 current_run_loop->Quit(); | 213 current_run_loop->Quit(); |
| 202 } | 214 } |
| 203 virtual void OnNodeHierarchyChanged(TransportNodeId node, | 215 virtual void OnNodeHierarchyChanged( |
| 204 TransportNodeId new_parent, | 216 TransportNodeId node, |
| 205 TransportNodeId old_parent, | 217 TransportNodeId new_parent, |
| 206 TransportChangeId change_id) OVERRIDE { | 218 TransportNodeId old_parent, |
| 219 TransportChangeId server_change_id, |
| 220 TransportChangeId client_change_id) OVERRIDE { |
| 207 changes_.push_back( | 221 changes_.push_back( |
| 208 base::StringPrintf( | 222 base::StringPrintf( |
| 209 "change_id=%d node=%s new_parent=%s old_parent=%s", | 223 "change_id=%d,%d node=%s new_parent=%s old_parent=%s", |
| 210 static_cast<int>(change_id), NodeIdToString(node).c_str(), | 224 static_cast<int>(server_change_id), |
| 225 static_cast<int>(client_change_id), |
| 226 NodeIdToString(node).c_str(), |
| 211 NodeIdToString(new_parent).c_str(), | 227 NodeIdToString(new_parent).c_str(), |
| 212 NodeIdToString(old_parent).c_str())); | 228 NodeIdToString(old_parent).c_str())); |
| 213 QuitIfNecessary(); | 229 QuitIfNecessary(); |
| 214 } | 230 } |
| 231 virtual void OnNodeDeleted(TransportNodeId node, |
| 232 TransportChangeId server_change_id, |
| 233 TransportChangeId client_change_id) OVERRIDE { |
| 234 changes_.push_back( |
| 235 base::StringPrintf( |
| 236 "NodeDeleted change_id=%d,%d node=%s", |
| 237 static_cast<int>(server_change_id), |
| 238 static_cast<int>(client_change_id), |
| 239 NodeIdToString(node).c_str())); |
| 240 QuitIfNecessary(); |
| 241 } |
| 215 virtual void OnNodeViewReplaced(TransportNodeId node, | 242 virtual void OnNodeViewReplaced(TransportNodeId node, |
| 216 TransportViewId new_view_id, | 243 TransportViewId new_view_id, |
| 217 TransportViewId old_view_id, | 244 TransportViewId old_view_id, |
| 218 TransportChangeId change_id) OVERRIDE { | 245 TransportChangeId change_id) OVERRIDE { |
| 219 changes_.push_back( | 246 changes_.push_back( |
| 220 base::StringPrintf( | 247 base::StringPrintf( |
| 221 "change_id=%d node=%s new_view=%s old_view=%s", | 248 "change_id=%d node=%s new_view=%s old_view=%s", |
| 222 static_cast<int>(change_id), NodeIdToString(node).c_str(), | 249 static_cast<int>(change_id), NodeIdToString(node).c_str(), |
| 223 NodeIdToString(new_view_id).c_str(), | 250 NodeIdToString(new_view_id).c_str(), |
| 224 NodeIdToString(old_view_id).c_str())); | 251 NodeIdToString(old_view_id).c_str())); |
| 225 QuitIfNecessary(); | 252 QuitIfNecessary(); |
| 226 } | 253 } |
| 227 virtual void OnNodeDeleted(TransportNodeId node, | |
| 228 TransportChangeId change_id) OVERRIDE { | |
| 229 changes_.push_back( | |
| 230 base::StringPrintf( | |
| 231 "change_id=%d node=%s deleted", | |
| 232 static_cast<int>(change_id), NodeIdToString(node).c_str())); | |
| 233 QuitIfNecessary(); | |
| 234 } | |
| 235 | 254 |
| 236 void QuitIfNecessary() { | 255 void QuitIfNecessary() { |
| 237 if (quit_count_ > 0 && --quit_count_ == 0) | 256 if (quit_count_ > 0 && --quit_count_ == 0) |
| 238 current_run_loop->Quit(); | 257 current_run_loop->Quit(); |
| 239 } | 258 } |
| 240 | 259 |
| 241 TransportConnectionId id_; | 260 TransportConnectionId id_; |
| 261 TransportChangeId next_server_change_id_; |
| 242 | 262 |
| 243 // Used to determine when/if to quit the run loop. | 263 // Used to determine when/if to quit the run loop. |
| 244 size_t quit_count_; | 264 size_t quit_count_; |
| 245 | 265 |
| 246 Changes changes_; | 266 Changes changes_; |
| 247 | 267 |
| 248 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 268 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
| 249 }; | 269 }; |
| 250 | 270 |
| 251 class ViewManagerConnectionTest : public testing::Test { | 271 class ViewManagerConnectionTest : public testing::Test { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 IViewManagerPtr view_manager2_; | 304 IViewManagerPtr view_manager2_; |
| 285 | 305 |
| 286 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); | 306 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); |
| 287 }; | 307 }; |
| 288 | 308 |
| 289 // Verifies client gets a valid id. | 309 // Verifies client gets a valid id. |
| 290 TEST_F(ViewManagerConnectionTest, ValidId) { | 310 TEST_F(ViewManagerConnectionTest, ValidId) { |
| 291 // All these tests assume 1 for the client id. The only real assertion here is | 311 // All these tests assume 1 for the client id. The only real assertion here is |
| 292 // the client id is not zero, but adding this as rest of code here assumes 1. | 312 // the client id is not zero, but adding this as rest of code here assumes 1. |
| 293 EXPECT_EQ(1, client_.id()); | 313 EXPECT_EQ(1, client_.id()); |
| 314 |
| 315 // Change ids start at 1 as well. |
| 316 EXPECT_EQ(static_cast<TransportChangeId>(1), client_.next_server_change_id()); |
| 294 } | 317 } |
| 295 | 318 |
| 296 // Verifies two clients/connections get different ids. | 319 // Verifies two clients/connections get different ids. |
| 297 TEST_F(ViewManagerConnectionTest, TwoClientsGetDifferentConnectionIds) { | 320 TEST_F(ViewManagerConnectionTest, TwoClientsGetDifferentConnectionIds) { |
| 298 EstablishSecondConnection(); | 321 EstablishSecondConnection(); |
| 299 EXPECT_NE(0, client2_.id()); | 322 EXPECT_NE(0, client2_.id()); |
| 300 EXPECT_NE(client_.id(), client2_.id()); | 323 EXPECT_NE(client_.id(), client2_.id()); |
| 301 } | 324 } |
| 302 | 325 |
| 303 // Verifies client gets a valid id. | 326 // Verifies client gets a valid id. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 314 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); | 337 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 315 | 338 |
| 316 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 339 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 317 | 340 |
| 318 // Make 2 a child of 1. | 341 // Make 2 a child of 1. |
| 319 { | 342 { |
| 320 AllocationScope scope; | 343 AllocationScope scope; |
| 321 ASSERT_TRUE(AddNode(view_manager_.get(), | 344 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 322 CreateNodeId(client_.id(), 1), | 345 CreateNodeId(client_.id(), 1), |
| 323 CreateNodeId(client_.id(), 2), | 346 CreateNodeId(client_.id(), 2), |
| 347 1, |
| 324 11)); | 348 11)); |
| 325 Changes changes(client_.GetAndClearChanges()); | 349 Changes changes(client_.GetAndClearChanges()); |
| 326 ASSERT_EQ(1u, changes.size()); | 350 ASSERT_EQ(1u, changes.size()); |
| 327 EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null", | 351 EXPECT_EQ("change_id=1,11 node=1,2 new_parent=1,1 old_parent=null", |
| 328 changes[0]); | 352 changes[0]); |
| 329 } | 353 } |
| 330 | 354 |
| 331 // Remove 2 from its parent. | 355 // Remove 2 from its parent. |
| 332 { | 356 { |
| 333 AllocationScope scope; | 357 AllocationScope scope; |
| 334 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 358 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
| 335 CreateNodeId(client_.id(), 2), | 359 CreateNodeId(client_.id(), 2), |
| 360 2, |
| 336 101)); | 361 101)); |
| 337 Changes changes(client_.GetAndClearChanges()); | 362 Changes changes(client_.GetAndClearChanges()); |
| 338 ASSERT_EQ(1u, changes.size()); | 363 ASSERT_EQ(1u, changes.size()); |
| 339 EXPECT_EQ("change_id=101 node=1,2 new_parent=null old_parent=1,1", | 364 EXPECT_EQ("change_id=2,101 node=1,2 new_parent=null old_parent=1,1", |
| 340 changes[0]); | 365 changes[0]); |
| 341 } | 366 } |
| 342 } | 367 } |
| 343 | 368 |
| 369 // Verifies AddNode fails when node is already in position. |
| 370 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { |
| 371 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 372 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 373 |
| 374 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 375 |
| 376 // Make 2 a child of 1. |
| 377 { |
| 378 AllocationScope scope; |
| 379 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 380 CreateNodeId(client_.id(), 1), |
| 381 CreateNodeId(client_.id(), 2), |
| 382 1, |
| 383 11)); |
| 384 Changes changes(client_.GetAndClearChanges()); |
| 385 ASSERT_EQ(1u, changes.size()); |
| 386 EXPECT_EQ("change_id=1,11 node=1,2 new_parent=1,1 old_parent=null", |
| 387 changes[0]); |
| 388 } |
| 389 |
| 390 // Try again, this should fail. |
| 391 { |
| 392 AllocationScope scope; |
| 393 EXPECT_FALSE(AddNode(view_manager_.get(), |
| 394 CreateNodeId(client_.id(), 1), |
| 395 CreateNodeId(client_.id(), 2), |
| 396 2, |
| 397 11)); |
| 398 Changes changes(client_.GetAndClearChanges()); |
| 399 EXPECT_TRUE(changes.empty()); |
| 400 } |
| 401 } |
| 402 |
| 403 // Verifies AddNode fails when node is already in position. |
| 404 TEST_F(ViewManagerConnectionTest, AddAncestorFails) { |
| 405 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 406 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 407 |
| 408 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 409 |
| 410 // Make 2 a child of 1. |
| 411 { |
| 412 AllocationScope scope; |
| 413 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 414 CreateNodeId(client_.id(), 1), |
| 415 CreateNodeId(client_.id(), 2), |
| 416 1, |
| 417 11)); |
| 418 Changes changes(client_.GetAndClearChanges()); |
| 419 ASSERT_EQ(1u, changes.size()); |
| 420 EXPECT_EQ("change_id=1,11 node=1,2 new_parent=1,1 old_parent=null", |
| 421 changes[0]); |
| 422 } |
| 423 |
| 424 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. |
| 425 { |
| 426 AllocationScope scope; |
| 427 EXPECT_FALSE(AddNode(view_manager_.get(), |
| 428 CreateNodeId(client_.id(), 2), |
| 429 CreateNodeId(client_.id(), 1), |
| 430 2, |
| 431 21)); |
| 432 Changes changes(client_.GetAndClearChanges()); |
| 433 EXPECT_TRUE(changes.empty()); |
| 434 } |
| 435 } |
| 436 |
| 344 // Verifies hierarchy changes are sent to multiple clients. | 437 // Verifies hierarchy changes are sent to multiple clients. |
| 345 TEST_F(ViewManagerConnectionTest, AddRemoveNotifyMultipleConnections) { | 438 TEST_F(ViewManagerConnectionTest, AddRemoveNotifyMultipleConnections) { |
| 346 EstablishSecondConnection(); | 439 EstablishSecondConnection(); |
| 347 | 440 |
| 348 // Create two nodes in first connection. | 441 // Create two nodes in first connection. |
| 349 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); | 442 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 350 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); | 443 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 351 | 444 |
| 352 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 445 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 353 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 446 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
| 354 | 447 |
| 355 // Make 2 a child of 1. | 448 // Make 2 a child of 1. |
| 356 { | 449 { |
| 357 AllocationScope scope; | 450 AllocationScope scope; |
| 358 ASSERT_TRUE(AddNode(view_manager_.get(), | 451 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 359 CreateNodeId(client_.id(), 1), | 452 CreateNodeId(client_.id(), 1), |
| 360 CreateNodeId(client_.id(), 2), | 453 CreateNodeId(client_.id(), 2), |
| 454 1, |
| 361 11)); | 455 11)); |
| 362 Changes changes(client_.GetAndClearChanges()); | 456 Changes changes(client_.GetAndClearChanges()); |
| 363 ASSERT_EQ(1u, changes.size()); | 457 ASSERT_EQ(1u, changes.size()); |
| 364 EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null", | 458 EXPECT_EQ("change_id=1,11 node=1,2 new_parent=1,1 old_parent=null", |
| 365 changes[0]); | 459 changes[0]); |
| 366 } | 460 } |
| 367 | 461 |
| 368 // Second client should also have received the change. | 462 // Second client should also have received the change. |
| 369 { | 463 { |
| 370 client2_.DoRunLoopUntilChangesCount(1); | 464 client2_.DoRunLoopUntilChangesCount(1); |
| 371 Changes changes(client2_.GetAndClearChanges()); | 465 Changes changes(client2_.GetAndClearChanges()); |
| 372 ASSERT_EQ(1u, changes.size()); | 466 ASSERT_EQ(1u, changes.size()); |
| 373 EXPECT_EQ("change_id=0 node=1,2 new_parent=1,1 old_parent=null", | 467 EXPECT_EQ("change_id=1,0 node=1,2 new_parent=1,1 old_parent=null", |
| 374 changes[0]); | 468 changes[0]); |
| 375 } | 469 } |
| 376 } | 470 } |
| 377 | 471 |
| 472 // Verifies adding with an invalid id fails. |
| 473 TEST_F(ViewManagerConnectionTest, AddWithInvalidServerId) { |
| 474 // Create two nodes. |
| 475 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 476 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 477 |
| 478 // Make 2 a child of 1. Supply an invalid change id, which should fail. |
| 479 { |
| 480 AllocationScope scope; |
| 481 ASSERT_FALSE(AddNode(view_manager_.get(), |
| 482 CreateNodeId(client_.id(), 1), |
| 483 CreateNodeId(client_.id(), 2), |
| 484 0, |
| 485 11)); |
| 486 Changes changes(client_.GetAndClearChanges()); |
| 487 EXPECT_TRUE(changes.empty()); |
| 488 } |
| 489 } |
| 490 |
| 378 // Verifies adding to root sends right notifications. | 491 // Verifies adding to root sends right notifications. |
| 379 TEST_F(ViewManagerConnectionTest, AddToRoot) { | 492 TEST_F(ViewManagerConnectionTest, AddToRoot) { |
| 380 ASSERT_TRUE(CreateNode(view_manager_.get(), 21)); | 493 ASSERT_TRUE(CreateNode(view_manager_.get(), 21)); |
| 381 ASSERT_TRUE(CreateNode(view_manager_.get(), 3)); | 494 ASSERT_TRUE(CreateNode(view_manager_.get(), 3)); |
| 382 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 495 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 383 | 496 |
| 384 // Make 3 a child of 21. | 497 // Make 3 a child of 21. |
| 385 { | 498 { |
| 386 AllocationScope scope; | 499 AllocationScope scope; |
| 387 ASSERT_TRUE(AddNode(view_manager_.get(), | 500 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 388 CreateNodeId(client_.id(), 21), | 501 CreateNodeId(client_.id(), 21), |
| 389 CreateNodeId(client_.id(), 3), | 502 CreateNodeId(client_.id(), 3), |
| 503 1, |
| 390 11)); | 504 11)); |
| 391 Changes changes(client_.GetAndClearChanges()); | 505 Changes changes(client_.GetAndClearChanges()); |
| 392 ASSERT_EQ(1u, changes.size()); | 506 ASSERT_EQ(1u, changes.size()); |
| 393 EXPECT_EQ("change_id=11 node=1,3 new_parent=1,21 old_parent=null", | 507 EXPECT_EQ("change_id=1,11 node=1,3 new_parent=1,21 old_parent=null", |
| 394 changes[0]); | 508 changes[0]); |
| 395 } | 509 } |
| 396 | 510 |
| 397 // Make 21 a child of the root. | 511 // Make 21 a child of the root. |
| 398 { | 512 { |
| 399 AllocationScope scope; | 513 AllocationScope scope; |
| 400 ASSERT_TRUE(AddNode(view_manager_.get(), | 514 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 401 CreateNodeId(0, 1), | 515 CreateNodeId(0, 1), |
| 402 CreateNodeId(client_.id(), 21), | 516 CreateNodeId(client_.id(), 21), |
| 517 2, |
| 403 44)); | 518 44)); |
| 404 Changes changes(client_.GetAndClearChanges()); | 519 Changes changes(client_.GetAndClearChanges()); |
| 405 ASSERT_EQ(1u, changes.size()); | 520 ASSERT_EQ(1u, changes.size()); |
| 406 EXPECT_EQ("change_id=44 node=1,21 new_parent=0,1 old_parent=null", | 521 EXPECT_EQ("change_id=2,44 node=1,21 new_parent=0,1 old_parent=null", |
| 407 changes[0]); | 522 changes[0]); |
| 408 } | 523 } |
| 409 } | 524 } |
| 410 | 525 |
| 411 // Verifies DeleteNode works. | 526 // Verifies DeleteNode works. |
| 412 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 527 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
| 413 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); | 528 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 414 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); | 529 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 415 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 530 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 416 | 531 |
| 417 // Make 2 a child of 1. | 532 // Make 2 a child of 1. |
| 418 { | 533 { |
| 419 AllocationScope scope; | 534 AllocationScope scope; |
| 420 ASSERT_TRUE(AddNode(view_manager_.get(), | 535 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 421 CreateNodeId(client_.id(), 1), | 536 CreateNodeId(client_.id(), 1), |
| 422 CreateNodeId(client_.id(), 2), | 537 CreateNodeId(client_.id(), 2), |
| 538 1, |
| 423 11)); | 539 11)); |
| 424 Changes changes(client_.GetAndClearChanges()); | 540 Changes changes(client_.GetAndClearChanges()); |
| 425 ASSERT_EQ(1u, changes.size()); | 541 ASSERT_EQ(1u, changes.size()); |
| 426 EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null", | 542 EXPECT_EQ("change_id=1,11 node=1,2 new_parent=1,1 old_parent=null", |
| 427 changes[0]); | 543 changes[0]); |
| 428 } | 544 } |
| 429 | 545 |
| 430 // Add 1 to the root | 546 // Add 1 to the root |
| 431 { | 547 { |
| 432 AllocationScope scope; | 548 AllocationScope scope; |
| 433 ASSERT_TRUE(AddNode(view_manager_.get(), | 549 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 434 CreateNodeId(0, 1), | 550 CreateNodeId(0, 1), |
| 435 CreateNodeId(client_.id(), 1), | 551 CreateNodeId(client_.id(), 1), |
| 552 2, |
| 436 101)); | 553 101)); |
| 437 Changes changes(client_.GetAndClearChanges()); | 554 Changes changes(client_.GetAndClearChanges()); |
| 438 ASSERT_EQ(1u, changes.size()); | 555 ASSERT_EQ(1u, changes.size()); |
| 439 EXPECT_EQ("change_id=101 node=1,1 new_parent=0,1 old_parent=null", | 556 EXPECT_EQ("change_id=2,101 node=1,1 new_parent=0,1 old_parent=null", |
| 440 changes[0]); | 557 changes[0]); |
| 441 } | 558 } |
| 442 | 559 |
| 443 // Delete 1. | 560 // Delete 1. Deleting 1 sends out notification of a removal for both nodes (1 |
| 561 // and 2). |
| 444 { | 562 { |
| 445 AllocationScope scope; | 563 AllocationScope scope; |
| 446 ASSERT_TRUE(DeleteNode(view_manager_.get(), | 564 ASSERT_TRUE(DeleteNode(view_manager_.get(), |
| 447 CreateNodeId(client_.id(), 1), | 565 CreateNodeId(client_.id(), 1), |
| 448 121)); | 566 121)); |
| 449 Changes changes(client_.GetAndClearChanges()); | 567 Changes changes(client_.GetAndClearChanges()); |
| 450 ASSERT_EQ(3u, changes.size()); | 568 ASSERT_EQ(3u, changes.size()); |
| 451 EXPECT_EQ("change_id=121 node=1,1 new_parent=null old_parent=0,1", | 569 EXPECT_EQ("change_id=3,121 node=1,1 new_parent=null old_parent=0,1", |
| 452 changes[0]); | 570 changes[0]); |
| 453 EXPECT_EQ("change_id=121 node=1,2 new_parent=null old_parent=1,1", | 571 EXPECT_EQ("change_id=3,121 node=1,2 new_parent=null old_parent=1,1", |
| 454 changes[1]); | 572 changes[1]); |
| 455 EXPECT_EQ("change_id=121 node=1,1 deleted", changes[2]); | 573 EXPECT_EQ("NodeDeleted change_id=3,121 node=1,1", changes[2]); |
| 456 } | 574 } |
| 457 } | 575 } |
| 458 | 576 |
| 459 // Assertions around setting a view. | 577 // Assertions around setting a view. |
| 460 TEST_F(ViewManagerConnectionTest, SetView) { | 578 TEST_F(ViewManagerConnectionTest, SetView) { |
| 461 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); | 579 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 462 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); | 580 ASSERT_TRUE(CreateNode(view_manager_.get(), 2)); |
| 463 ASSERT_TRUE(CreateView(view_manager_.get(), 11)); | 581 ASSERT_TRUE(CreateView(view_manager_.get(), 11)); |
| 464 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 582 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
| 465 | 583 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 624 |
| 507 // Delete node 1. | 625 // Delete node 1. |
| 508 { | 626 { |
| 509 ASSERT_TRUE(DeleteNode(view_manager_.get(), | 627 ASSERT_TRUE(DeleteNode(view_manager_.get(), |
| 510 CreateNodeId(client_.id(), 1), | 628 CreateNodeId(client_.id(), 1), |
| 511 121)); | 629 121)); |
| 512 Changes changes(client_.GetAndClearChanges()); | 630 Changes changes(client_.GetAndClearChanges()); |
| 513 ASSERT_EQ(2u, changes.size()); | 631 ASSERT_EQ(2u, changes.size()); |
| 514 EXPECT_EQ("change_id=121 node=1,1 new_view=null old_view=1,11", | 632 EXPECT_EQ("change_id=121 node=1,1 new_view=null old_view=1,11", |
| 515 changes[0]); | 633 changes[0]); |
| 516 EXPECT_EQ("change_id=121 node=1,1 deleted", changes[1]); | 634 EXPECT_EQ("NodeDeleted change_id=1,121 node=1,1", changes[1]); |
| 517 } | 635 } |
| 518 | 636 |
| 519 // Set view 11 on node 2. | 637 // Set view 11 on node 2. |
| 520 { | 638 { |
| 521 ASSERT_TRUE(SetView(view_manager_.get(), | 639 ASSERT_TRUE(SetView(view_manager_.get(), |
| 522 CreateNodeId(client_.id(), 2), | 640 CreateNodeId(client_.id(), 2), |
| 523 CreateViewId(client_.id(), 11), | 641 CreateViewId(client_.id(), 11), |
| 524 22)); | 642 22)); |
| 525 Changes changes(client_.GetAndClearChanges()); | 643 Changes changes(client_.GetAndClearChanges()); |
| 526 ASSERT_EQ(1u, changes.size()); | 644 ASSERT_EQ(1u, changes.size()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 // Assertions for GetNodeTree. | 691 // Assertions for GetNodeTree. |
| 574 TEST_F(ViewManagerConnectionTest, GetNodeTree) { | 692 TEST_F(ViewManagerConnectionTest, GetNodeTree) { |
| 575 EstablishSecondConnection(); | 693 EstablishSecondConnection(); |
| 576 | 694 |
| 577 // Create two nodes in first connection, 1 and 11 (11 is a child of 1). | 695 // Create two nodes in first connection, 1 and 11 (11 is a child of 1). |
| 578 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); | 696 ASSERT_TRUE(CreateNode(view_manager_.get(), 1)); |
| 579 ASSERT_TRUE(CreateNode(view_manager_.get(), 11)); | 697 ASSERT_TRUE(CreateNode(view_manager_.get(), 11)); |
| 580 ASSERT_TRUE(AddNode(view_manager_.get(), | 698 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 581 CreateNodeId(0, 1), | 699 CreateNodeId(0, 1), |
| 582 CreateNodeId(client_.id(), 1), | 700 CreateNodeId(client_.id(), 1), |
| 701 1, |
| 583 101)); | 702 101)); |
| 584 ASSERT_TRUE(AddNode(view_manager_.get(), | 703 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 585 CreateNodeId(client_.id(), 1), | 704 CreateNodeId(client_.id(), 1), |
| 586 CreateNodeId(client_.id(), 11), | 705 CreateNodeId(client_.id(), 11), |
| 706 2, |
| 587 102)); | 707 102)); |
| 588 | 708 |
| 589 // Create two nodes in second connection, 2 and 3, both children of the root. | 709 // Create two nodes in second connection, 2 and 3, both children of the root. |
| 590 ASSERT_TRUE(CreateNode(view_manager2_.get(), 2)); | 710 ASSERT_TRUE(CreateNode(view_manager2_.get(), 2)); |
| 591 ASSERT_TRUE(CreateNode(view_manager2_.get(), 3)); | 711 ASSERT_TRUE(CreateNode(view_manager2_.get(), 3)); |
| 592 ASSERT_TRUE(AddNode(view_manager2_.get(), | 712 ASSERT_TRUE(AddNode(view_manager2_.get(), |
| 593 CreateNodeId(0, 1), | 713 CreateNodeId(0, 1), |
| 594 CreateNodeId(client2_.id(), 2), | 714 CreateNodeId(client2_.id(), 2), |
| 715 3, |
| 595 99)); | 716 99)); |
| 596 ASSERT_TRUE(AddNode(view_manager2_.get(), | 717 ASSERT_TRUE(AddNode(view_manager2_.get(), |
| 597 CreateNodeId(0, 1), | 718 CreateNodeId(0, 1), |
| 598 CreateNodeId(client2_.id(), 3), | 719 CreateNodeId(client2_.id(), 3), |
| 720 4, |
| 599 99)); | 721 99)); |
| 600 | 722 |
| 601 // Attach view to node 11 in the first connection. | 723 // Attach view to node 11 in the first connection. |
| 602 ASSERT_TRUE(CreateView(view_manager_.get(), 51)); | 724 ASSERT_TRUE(CreateView(view_manager_.get(), 51)); |
| 603 ASSERT_TRUE(SetView(view_manager_.get(), | 725 ASSERT_TRUE(SetView(view_manager_.get(), |
| 604 CreateNodeId(client_.id(), 11), | 726 CreateNodeId(client_.id(), 11), |
| 605 CreateViewId(client_.id(), 51), | 727 CreateViewId(client_.id(), 51), |
| 606 22)); | 728 22)); |
| 607 | 729 |
| 608 // Verifies GetNodeTree() on the root. | 730 // Verifies GetNodeTree() on the root. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 625 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 747 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
| 626 ASSERT_EQ(2u, nodes.size()); | 748 ASSERT_EQ(2u, nodes.size()); |
| 627 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 749 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 628 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 750 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
| 629 } | 751 } |
| 630 } | 752 } |
| 631 | 753 |
| 632 } // namespace view_manager | 754 } // namespace view_manager |
| 633 } // namespace services | 755 } // namespace services |
| 634 } // namespace mojo | 756 } // namespace mojo |
| OLD | NEW |