Commit 301a2c3d authored by sky@chromium.org's avatar sky@chromium.org

Minor cleanup of view manager test

BUG=none
TEST=none
R=ben@chromium.org

Review URL: https://codereview.chromium.org/308763004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273978 0039d316-1c4b-4281-b951-d872f2087c98
parent 21b7765a
...@@ -21,17 +21,6 @@ std::string NodeIdToString(TransportNodeId id) { ...@@ -21,17 +21,6 @@ std::string NodeIdToString(TransportNodeId id) {
namespace { namespace {
void INodesToTestNodes(const Array<INodePtr>& data,
std::vector<TestNode>* test_nodes) {
for (size_t i = 0; i < data.size(); ++i) {
TestNode node;
node.parent_id = data[i]->parent_id;
node.node_id = data[i]->node_id;
node.view_id = data[i]->view_id;
test_nodes->push_back(node);
}
}
std::string RectToString(const gfx::Rect& rect) { std::string RectToString(const gfx::Rect& rect) {
return base::StringPrintf("%d,%d %dx%d", rect.x(), rect.y(), rect.width(), return base::StringPrintf("%d,%d %dx%d", rect.x(), rect.y(), rect.width(),
rect.height()); rect.height());
...@@ -100,6 +89,17 @@ std::string ChangeNodeDescription(const std::vector<Change>& changes) { ...@@ -100,6 +89,17 @@ std::string ChangeNodeDescription(const std::vector<Change>& changes) {
return JoinString(node_strings, ','); return JoinString(node_strings, ',');
} }
void INodesToTestNodes(const Array<INodePtr>& data,
std::vector<TestNode>* test_nodes) {
for (size_t i = 0; i < data.size(); ++i) {
TestNode node;
node.parent_id = data[i]->parent_id;
node.node_id = data[i]->node_id;
node.view_id = data[i]->view_id;
test_nodes->push_back(node);
}
}
Change::Change() Change::Change()
: type(CHANGE_TYPE_CONNECTION_ESTABLISHED), : type(CHANGE_TYPE_CONNECTION_ESTABLISHED),
connection_id(0), connection_id(0),
......
...@@ -63,6 +63,10 @@ std::vector<std::string> ChangesToDescription1( ...@@ -63,6 +63,10 @@ std::vector<std::string> ChangesToDescription1(
// if change.size() != 1. // if change.size() != 1.
std::string ChangeNodeDescription(const std::vector<Change>& changes); std::string ChangeNodeDescription(const std::vector<Change>& changes);
// Converts INodes to TestNodes.
void INodesToTestNodes(const Array<INodePtr>& data,
std::vector<TestNode>* test_nodes);
// TestChangeTracker is used to record IViewManagerClient functions. It notifies // TestChangeTracker is used to record IViewManagerClient functions. It notifies
// a delegate any time a change is added. // a delegate any time a change is added.
class TestChangeTracker { class TestChangeTracker {
......
...@@ -33,22 +33,8 @@ namespace service { ...@@ -33,22 +33,8 @@ namespace service {
namespace { namespace {
// TODO(sky): clean this up. Should be moved to the single place its used.
base::RunLoop* current_run_loop = NULL;
const char kTestServiceURL[] = "mojo:test_url"; const char kTestServiceURL[] = "mojo:test_url";
void INodesToTestNodes(const Array<INodePtr>& data,
std::vector<TestNode>* test_nodes) {
for (size_t i = 0; i < data.size(); ++i) {
TestNode node;
node.parent_id = data[i]->parent_id;
node.node_id = data[i]->node_id;
node.view_id = data[i]->view_id;
test_nodes->push_back(node);
}
}
// ViewManagerProxy is a proxy to an IViewManager. It handles invoking // ViewManagerProxy is a proxy to an IViewManager. It handles invoking
// IViewManager functions on the right thread in a synchronous manner (each // IViewManager functions on the right thread in a synchronous manner (each
// IViewManager cover function blocks until the response from the IViewManager // IViewManager cover function blocks until the response from the IViewManager
...@@ -485,24 +471,6 @@ class ConnectServiceLoader : public ServiceLoader { ...@@ -485,24 +471,6 @@ class ConnectServiceLoader : public ServiceLoader {
DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader);
}; };
// Sets |current_run_loop| and runs it. It is expected that someone else quits
// the loop.
void DoRunLoop() {
DCHECK(!current_run_loop);
base::RunLoop run_loop;
current_run_loop = &run_loop;
current_run_loop->Run();
current_run_loop = NULL;
}
// Boolean callback. Sets |result_cache| to the value of |result| and quits
// the run loop.
void BooleanCallback(bool* result_cache, bool result) {
*result_cache = result;
current_run_loop->Quit();
}
// Creates an id used for transport from the specified parameters. // Creates an id used for transport from the specified parameters.
TransportNodeId BuildNodeId(TransportConnectionId connection_id, TransportNodeId BuildNodeId(TransportConnectionId connection_id,
TransportConnectionSpecificNodeId node_id) { TransportConnectionSpecificNodeId node_id) {
...@@ -515,13 +483,25 @@ TransportViewId BuildViewId(TransportConnectionId connection_id, ...@@ -515,13 +483,25 @@ TransportViewId BuildViewId(TransportConnectionId connection_id,
return (connection_id << 16) | view_id; return (connection_id << 16) | view_id;
} }
// Callback from ViewManagerInitConnect(). |result| is the result of the
// Connect() call and |run_loop| the nested RunLoop.
void ViewManagerInitConnectCallback(bool* result_cache,
base::RunLoop* run_loop,
bool result) {
*result_cache = result;
run_loop->Quit();
}
// Resposible for establishing connection to the viewmanager. Blocks until get // Resposible for establishing connection to the viewmanager. Blocks until get
// back result. // back result.
bool ViewManagerInitConnect(IViewManagerInit* view_manager_init, bool ViewManagerInitConnect(IViewManagerInit* view_manager_init,
const std::string& url) { const std::string& url) {
bool result = false; bool result = false;
view_manager_init->Connect(url, base::Bind(&BooleanCallback, &result)); base::RunLoop run_loop;
DoRunLoop(); view_manager_init->Connect(url,
base::Bind(&ViewManagerInitConnectCallback,
&result, &run_loop));
run_loop.Run();
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment