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

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

Issue 308763004: Minor cleanup of view manager test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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/test_change_tracker.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/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 15 matching lines...) Expand all
26 #include "mojo/shell/shell_test_helper.h" 26 #include "mojo/shell/shell_test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
29 29
30 namespace mojo { 30 namespace mojo {
31 namespace view_manager { 31 namespace view_manager {
32 namespace service { 32 namespace service {
33 33
34 namespace { 34 namespace {
35 35
36 // TODO(sky): clean this up. Should be moved to the single place its used.
37 base::RunLoop* current_run_loop = NULL;
38
39 const char kTestServiceURL[] = "mojo:test_url"; 36 const char kTestServiceURL[] = "mojo:test_url";
40 37
41 void INodesToTestNodes(const Array<INodePtr>& data,
42 std::vector<TestNode>* test_nodes) {
43 for (size_t i = 0; i < data.size(); ++i) {
44 TestNode node;
45 node.parent_id = data[i]->parent_id;
46 node.node_id = data[i]->node_id;
47 node.view_id = data[i]->view_id;
48 test_nodes->push_back(node);
49 }
50 }
51
52 // ViewManagerProxy is a proxy to an IViewManager. It handles invoking 38 // ViewManagerProxy is a proxy to an IViewManager. It handles invoking
53 // IViewManager functions on the right thread in a synchronous manner (each 39 // IViewManager functions on the right thread in a synchronous manner (each
54 // IViewManager cover function blocks until the response from the IViewManager 40 // IViewManager cover function blocks until the response from the IViewManager
55 // is returned). In addition it tracks the set of IViewManagerClient messages 41 // is returned). In addition it tracks the set of IViewManagerClient messages
56 // received by way of a vector of Changes. Use DoRunLoopUntilChangesCount() to 42 // received by way of a vector of Changes. Use DoRunLoopUntilChangesCount() to
57 // wait for a certain number of messages to be received. 43 // wait for a certain number of messages to be received.
58 class ViewManagerProxy : public TestChangeTracker::Delegate { 44 class ViewManagerProxy : public TestChangeTracker::Delegate {
59 public: 45 public:
60 ViewManagerProxy(TestChangeTracker* tracker, base::MessageLoop* loop) 46 ViewManagerProxy(TestChangeTracker* tracker, base::MessageLoop* loop)
61 : tracker_(tracker), 47 : tracker_(tracker),
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 const GURL& url) OVERRIDE { 464 const GURL& url) OVERRIDE {
479 } 465 }
480 466
481 private: 467 private:
482 base::MessageLoop* initial_loop_; 468 base::MessageLoop* initial_loop_;
483 ScopedVector<Application> apps_; 469 ScopedVector<Application> apps_;
484 470
485 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); 471 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader);
486 }; 472 };
487 473
488 // Sets |current_run_loop| and runs it. It is expected that someone else quits
489 // the loop.
490 void DoRunLoop() {
491 DCHECK(!current_run_loop);
492
493 base::RunLoop run_loop;
494 current_run_loop = &run_loop;
495 current_run_loop->Run();
496 current_run_loop = NULL;
497 }
498
499 // Boolean callback. Sets |result_cache| to the value of |result| and quits
500 // the run loop.
501 void BooleanCallback(bool* result_cache, bool result) {
502 *result_cache = result;
503 current_run_loop->Quit();
504 }
505
506 // Creates an id used for transport from the specified parameters. 474 // Creates an id used for transport from the specified parameters.
507 TransportNodeId BuildNodeId(TransportConnectionId connection_id, 475 TransportNodeId BuildNodeId(TransportConnectionId connection_id,
508 TransportConnectionSpecificNodeId node_id) { 476 TransportConnectionSpecificNodeId node_id) {
509 return (connection_id << 16) | node_id; 477 return (connection_id << 16) | node_id;
510 } 478 }
511 479
512 // Creates an id used for transport from the specified parameters. 480 // Creates an id used for transport from the specified parameters.
513 TransportViewId BuildViewId(TransportConnectionId connection_id, 481 TransportViewId BuildViewId(TransportConnectionId connection_id,
514 TransportConnectionSpecificViewId view_id) { 482 TransportConnectionSpecificViewId view_id) {
515 return (connection_id << 16) | view_id; 483 return (connection_id << 16) | view_id;
516 } 484 }
517 485
486 // Callback from ViewManagerInitConnect(). |result| is the result of the
487 // Connect() call and |run_loop| the nested RunLoop.
488 void ViewManagerInitConnectCallback(bool* result_cache,
489 base::RunLoop* run_loop,
490 bool result) {
491 *result_cache = result;
492 run_loop->Quit();
493 }
494
518 // Resposible for establishing connection to the viewmanager. Blocks until get 495 // Resposible for establishing connection to the viewmanager. Blocks until get
519 // back result. 496 // back result.
520 bool ViewManagerInitConnect(IViewManagerInit* view_manager_init, 497 bool ViewManagerInitConnect(IViewManagerInit* view_manager_init,
521 const std::string& url) { 498 const std::string& url) {
522 bool result = false; 499 bool result = false;
523 view_manager_init->Connect(url, base::Bind(&BooleanCallback, &result)); 500 base::RunLoop run_loop;
524 DoRunLoop(); 501 view_manager_init->Connect(url,
502 base::Bind(&ViewManagerInitConnectCallback,
503 &result, &run_loop));
504 run_loop.Run();
525 return result; 505 return result;
526 } 506 }
527 507
528 } // namespace 508 } // namespace
529 509
530 typedef std::vector<std::string> Changes; 510 typedef std::vector<std::string> Changes;
531 511
532 class ViewManagerConnectionTest : public testing::Test { 512 class ViewManagerConnectionTest : public testing::Test {
533 public: 513 public:
534 ViewManagerConnectionTest() : connection_(NULL), connection2_(NULL) {} 514 ViewManagerConnectionTest() : connection_(NULL), connection2_(NULL) {}
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 // TODO(sky): add coverage of test that destroys connections and ensures other 1327 // TODO(sky): add coverage of test that destroys connections and ensures other
1348 // connections get deletion notification (or advanced server id). 1328 // connections get deletion notification (or advanced server id).
1349 1329
1350 // TODO(sky): need to better track changes to initial connection. For example, 1330 // TODO(sky): need to better track changes to initial connection. For example,
1351 // that SetBounsdNodes/AddNode and the like don't result in messages to the 1331 // that SetBounsdNodes/AddNode and the like don't result in messages to the
1352 // originating connection. 1332 // originating connection.
1353 1333
1354 } // namespace service 1334 } // namespace service
1355 } // namespace view_manager 1335 } // namespace view_manager
1356 } // namespace mojo 1336 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/test_change_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698