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

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

Issue 383293002: Start of adding enums for error codes (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
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Destroys the connection, blocking until done. 87 // Destroys the connection, blocking until done.
88 void Destroy() { 88 void Destroy() {
89 router_->CloseMessagePipe(); 89 router_->CloseMessagePipe();
90 } 90 }
91 91
92 // The following functions are cover methods for ViewManagerService. They 92 // The following functions are cover methods for ViewManagerService. They
93 // block until the result is received. 93 // block until the result is received.
94 bool CreateNode(Id node_id) { 94 bool CreateNode(Id node_id) {
95 changes_.clear(); 95 changes_.clear();
96 bool result = false; 96 ErrorCode result = ERROR_CODE_NONE;
97 view_manager_->CreateNode(node_id, 97 view_manager_->CreateNode(
98 base::Bind(&ViewManagerProxy::GotResult, 98 node_id,
99 base::Unretained(this), &result)); 99 base::Bind(&ViewManagerProxy::GotResultWithErrorCode,
100 base::Unretained(this), &result));
101 RunMainLoop();
102 return result == ERROR_CODE_NONE;
103 }
104 ErrorCode CreateNodeWithErrorCode(Id node_id) {
105 changes_.clear();
106 ErrorCode result = ERROR_CODE_NONE;
107 view_manager_->CreateNode(
108 node_id,
109 base::Bind(&ViewManagerProxy::GotResultWithErrorCode,
110 base::Unretained(this), &result));
100 RunMainLoop(); 111 RunMainLoop();
101 return result; 112 return result;
102 } 113 }
103 bool AddNode(Id parent, Id child, Id server_change_id) { 114 bool AddNode(Id parent, Id child, Id server_change_id) {
104 changes_.clear(); 115 changes_.clear();
105 bool result = false; 116 bool result = false;
106 view_manager_->AddNode(parent, child, server_change_id, 117 view_manager_->AddNode(parent, child, server_change_id,
107 base::Bind(&ViewManagerProxy::GotResult, 118 base::Bind(&ViewManagerProxy::GotResult,
108 base::Unretained(this), &result)); 119 base::Unretained(this), &result));
109 RunMainLoop(); 120 RunMainLoop();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 main_run_loop_->Quit(); 245 main_run_loop_->Quit();
235 } 246 }
236 247
237 // Callbacks from the various ViewManagerService functions. 248 // Callbacks from the various ViewManagerService functions.
238 void GotResult(bool* result_cache, bool result) { 249 void GotResult(bool* result_cache, bool result) {
239 *result_cache = result; 250 *result_cache = result;
240 DCHECK(main_run_loop_); 251 DCHECK(main_run_loop_);
241 main_run_loop_->Quit(); 252 main_run_loop_->Quit();
242 } 253 }
243 254
255 void GotResultWithErrorCode(ErrorCode* error_code_cache,
256 ErrorCode error_code) {
257 *error_code_cache = error_code;
258 DCHECK(main_run_loop_);
259 main_run_loop_->Quit();
260 }
261
244 void GotNodeTree(std::vector<TestNode>* nodes, Array<NodeDataPtr> results) { 262 void GotNodeTree(std::vector<TestNode>* nodes, Array<NodeDataPtr> results) {
245 NodeDatasToTestNodes(results, nodes); 263 NodeDatasToTestNodes(results, nodes);
246 DCHECK(main_run_loop_); 264 DCHECK(main_run_loop_);
247 main_run_loop_->Quit(); 265 main_run_loop_->Quit();
248 } 266 }
249 267
250 // TestChangeTracker::Delegate: 268 // TestChangeTracker::Delegate:
251 virtual void OnChangeAdded() OVERRIDE { 269 virtual void OnChangeAdded() OVERRIDE {
252 if (quit_count_ > 0 && --quit_count_ == 0) 270 if (quit_count_ > 0 && --quit_count_ == 0)
253 QuitCountReached(); 271 QuitCountReached();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 // Change ids start at 1 as well. 552 // Change ids start at 1 as well.
535 EXPECT_EQ(static_cast<Id>(1), connection2_->changes()[0].change_id); 553 EXPECT_EQ(static_cast<Id>(1), connection2_->changes()[0].change_id);
536 } 554 }
537 555
538 // Verifies client gets a valid id. 556 // Verifies client gets a valid id.
539 TEST_F(ViewManagerTest, CreateNode) { 557 TEST_F(ViewManagerTest, CreateNode) {
540 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); 558 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1)));
541 EXPECT_TRUE(connection_->changes().empty()); 559 EXPECT_TRUE(connection_->changes().empty());
542 560
543 // Can't create a node with the same id. 561 // Can't create a node with the same id.
544 ASSERT_FALSE(connection_->CreateNode(BuildNodeId(1, 1))); 562 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE,
563 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1)));
545 EXPECT_TRUE(connection_->changes().empty()); 564 EXPECT_TRUE(connection_->changes().empty());
546 565
547 // Can't create a node with a bogus connection id. 566 // Can't create a node with a bogus connection id.
548 EXPECT_FALSE(connection_->CreateNode(BuildNodeId(2, 1))); 567 EXPECT_EQ(
568 ERROR_CODE_ILLEGAL_ARGUMENT,
569 connection_->CreateNodeWithErrorCode(BuildNodeId(2, 1)));
549 EXPECT_TRUE(connection_->changes().empty()); 570 EXPECT_TRUE(connection_->changes().empty());
550 } 571 }
551 572
552 TEST_F(ViewManagerTest, CreateViewFailsWithBogusConnectionId) { 573 TEST_F(ViewManagerTest, CreateViewFailsWithBogusConnectionId) {
553 EXPECT_FALSE(connection_->CreateView(BuildViewId(2, 1))); 574 EXPECT_FALSE(connection_->CreateView(BuildViewId(2, 1)));
554 EXPECT_TRUE(connection_->changes().empty()); 575 EXPECT_TRUE(connection_->changes().empty());
555 } 576 }
556 577
557 // Verifies hierarchy changes. 578 // Verifies hierarchy changes.
558 TEST_F(ViewManagerTest, AddRemoveNotify) { 579 TEST_F(ViewManagerTest, AddRemoveNotify) {
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 // originating connection. 1397 // originating connection.
1377 1398
1378 // TODO(beng): Add tests for focus: 1399 // TODO(beng): Add tests for focus:
1379 // - focus between two nodes known to a connection 1400 // - focus between two nodes known to a connection
1380 // - focus between nodes unknown to one of the connections. 1401 // - focus between nodes unknown to one of the connections.
1381 // - focus between nodes unknown to either connection. 1402 // - focus between nodes unknown to either connection.
1382 1403
1383 } // namespace service 1404 } // namespace service
1384 } // namespace view_manager 1405 } // namespace view_manager
1385 } // namespace mojo 1406 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698