Commit ea891b57 authored by ben@chromium.org's avatar ben@chromium.org

Get view manager client lib unit test harness to run again. Does not get any...

Get view manager client lib unit test harness to run again. Does not get any individual tests working

R=sky@chromium.org
http://crbug.com/365012

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274618 0039d316-1c4b-4281-b951-d872f2087c98
parent 4064297a
...@@ -19,7 +19,7 @@ class EmbeddedApp : public Application { ...@@ -19,7 +19,7 @@ class EmbeddedApp : public Application {
private: private:
// Overridden from Application: // Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE { virtual void Initialize() MOJO_OVERRIDE {
view_manager_ = new view_manager::ViewManager(this); view_manager_ = view_manager::ViewManager::CreateBlocking(this);
view_manager::View* view = view_manager::View::Create(view_manager_); view_manager::View* view = view_manager::View::Create(view_manager_);
view_manager_->tree()->SetActiveView(view); view_manager_->tree()->SetActiveView(view);
view->SetColor(SK_ColorYELLOW); view->SetColor(SK_ColorYELLOW);
......
...@@ -19,7 +19,7 @@ class WindowManager : public Application { ...@@ -19,7 +19,7 @@ class WindowManager : public Application {
private: private:
// Overridden from Application: // Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE { virtual void Initialize() MOJO_OVERRIDE {
view_manager_ = new view_manager::ViewManager(this); view_manager_ = view_manager::ViewManager::CreateBlocking(this);
view_manager::ViewTreeNode* node = view_manager::ViewTreeNode* node =
view_manager::ViewTreeNode::Create(view_manager_); view_manager::ViewTreeNode::Create(view_manager_);
view_manager_->tree()->AddChild(node); view_manager_->tree()->AddChild(node);
......
...@@ -4,23 +4,27 @@ ...@@ -4,23 +4,27 @@
#include "mojo/services/public/cpp/view_manager/view_manager.h" #include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "base/message_loop/message_loop.h" #include "base/bind.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/application/application.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
#include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view.h"
namespace mojo { namespace mojo {
namespace view_manager { namespace view_manager {
namespace {
ViewManager::ViewManager(Application* application) void OnViewManagerReady(base::RunLoop* loop, ViewManager* manager) {
: synchronizer_(NULL), loop->Quit();
tree_(NULL) {
application->AddService<ViewManagerSynchronizer>(this);
// Block in a nested message loop until the ViewManagerSynchronizer is set up.
base::MessageLoop::current()->Run();
} }
} // namespace
////////////////////////////////////////////////////////////////////////////////
// ViewManager, public:
ViewManager::~ViewManager() { ViewManager::~ViewManager() {
while (!nodes_.empty()) { while (!nodes_.empty()) {
IdToNodeMap::iterator it = nodes_.begin(); IdToNodeMap::iterator it = nodes_.begin();
...@@ -38,6 +42,23 @@ ViewManager::~ViewManager() { ...@@ -38,6 +42,23 @@ ViewManager::~ViewManager() {
} }
} }
// static
ViewManager* ViewManager::CreateBlocking(Application* application) {
base::RunLoop init_loop;
ViewManager* manager = new ViewManager(
application,
base::Bind(&OnViewManagerReady, &init_loop));
init_loop.Run();
return manager;
}
// static
void ViewManager::Create(
Application* application,
const base::Callback<void(ViewManager*)> ready_callback) {
new ViewManager(application, ready_callback);
}
ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) {
IdToNodeMap::const_iterator it = nodes_.find(id); IdToNodeMap::const_iterator it = nodes_.find(id);
return it != nodes_.end() ? it->second : NULL; return it != nodes_.end() ? it->second : NULL;
...@@ -52,5 +73,17 @@ void ViewManager::Embed(const String& url, ViewTreeNode* node) { ...@@ -52,5 +73,17 @@ void ViewManager::Embed(const String& url, ViewTreeNode* node) {
synchronizer_->Embed(url, node->id()); synchronizer_->Embed(url, node->id());
} }
////////////////////////////////////////////////////////////////////////////////
// ViewManager, private:
ViewManager::ViewManager(
Application* application,
const base::Callback<void(ViewManager*)> ready_callback)
: ready_callback_(ready_callback),
synchronizer_(NULL),
tree_(NULL) {
application->AddService<ViewManagerSynchronizer>(this);
}
} // namespace view_manager } // namespace view_manager
} // namespace mojo } // namespace mojo
...@@ -19,6 +19,10 @@ class ViewManagerPrivate { ...@@ -19,6 +19,10 @@ class ViewManagerPrivate {
explicit ViewManagerPrivate(ViewManager* manager); explicit ViewManagerPrivate(ViewManager* manager);
~ViewManagerPrivate(); ~ViewManagerPrivate();
void NotifyReady() {
manager_->ready_callback_.Run(manager_);
}
ViewManagerSynchronizer* synchronizer() { ViewManagerSynchronizer* synchronizer() {
return manager_->synchronizer_; return manager_->synchronizer_;
} }
......
...@@ -560,12 +560,10 @@ void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( ...@@ -560,12 +560,10 @@ void ViewManagerSynchronizer::OnViewManagerConnectionEstablished(
connection_id_ = connection_id; connection_id_ = connection_id;
next_server_change_id_ = next_server_change_id; next_server_change_id_ = next_server_change_id;
ViewManagerPrivate(view_manager()).set_root( ViewManagerPrivate private_manager(view_manager());
BuildNodeTree(view_manager(), nodes)); private_manager.set_root(BuildNodeTree(view_manager(), nodes));
Sync(); Sync();
private_manager.NotifyReady();
base::MessageLoop::current()->Quit();
} }
void ViewManagerSynchronizer::OnServerChangeIdAdvanced( void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
......
include_rules = [
"+mojo/service_manager",
]
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/service_manager/service_manager.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
...@@ -20,6 +22,8 @@ namespace mojo { ...@@ -20,6 +22,8 @@ namespace mojo {
namespace view_manager { namespace view_manager {
namespace { namespace {
const char kTestServiceURL[] = "mojo:test_url";
base::RunLoop* current_run_loop = NULL; base::RunLoop* current_run_loop = NULL;
void DoRunLoop() { void DoRunLoop() {
...@@ -44,6 +48,33 @@ void WaitForAllChangesToBeAcked(ViewManager* manager) { ...@@ -44,6 +48,33 @@ void WaitForAllChangesToBeAcked(ViewManager* manager) {
ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback(); ViewManagerPrivate(manager).synchronizer()->ClearChangesAckedCallback();
} }
// Used with IViewManager::Connect(). Creates a TestViewManagerClientConnection,
// which creates and owns the ViewManagerProxy.
class ConnectServiceLoader : public ServiceLoader {
public:
explicit ConnectServiceLoader(base::Callback<void(ViewManager*)> callback)
: callback_(callback) {}
virtual ~ConnectServiceLoader() {}
// ServiceLoader:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
ScopedMessagePipeHandle shell_handle) OVERRIDE {
scoped_ptr<Application> app(new Application(shell_handle.Pass()));
ViewManager::Create(app.get(), callback_);
apps_.push_back(app.release());
}
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE {
}
private:
ScopedVector<Application> apps_;
base::Callback<void(ViewManager*)> callback_;
DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader);
};
class ActiveViewChangedObserver : public ViewTreeNodeObserver { class ActiveViewChangedObserver : public ViewTreeNodeObserver {
public: public:
explicit ActiveViewChangedObserver(ViewTreeNode* node) explicit ActiveViewChangedObserver(ViewTreeNode* node)
...@@ -276,10 +307,45 @@ class ViewManagerTest : public testing::Test { ...@@ -276,10 +307,45 @@ class ViewManagerTest : public testing::Test {
// Overridden from testing::Test: // Overridden from testing::Test:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
test_helper_.Init(); test_helper_.Init();
ConnectServiceLoader* loader =
new ConnectServiceLoader(
base::Bind(&ViewManagerTest::OnViewManagerLoaded,
base::Unretained(this)));
test_helper_.SetLoaderForURL(
scoped_ptr<ServiceLoader>(loader),
GURL(kTestServiceURL));
ConnectToService(test_helper_.service_provider(),
"mojo:mojo_view_manager",
&view_manager_init_);
ASSERT_TRUE(ViewManagerInitConnect(view_manager_init_.get(),
kTestServiceURL));
}
void ViewManagerInitConnectCallback(bool* result_cache,
bool result) {
*result_cache = result;
}
bool ViewManagerInitConnect(IViewManagerInit* view_manager_init,
const std::string& url) {
bool result = false;
view_manager_init->Connect(
url,
base::Bind(&ViewManagerTest::ViewManagerInitConnectCallback,
base::Unretained(this), &result));
init_loop_.Run();
return result;
}
void OnViewManagerLoaded(ViewManager* view_manager) {
init_loop_.Quit();
} }
base::MessageLoop loop_; base::MessageLoop loop_;
base::RunLoop init_loop_;
shell::ShellTestHelper test_helper_; shell::ShellTestHelper test_helper_;
IViewManagerInitPtr view_manager_init_;
ViewManager* view_manager_1_; ViewManager* view_manager_1_;
ViewManager* view_manager_2_; ViewManager* view_manager_2_;
int commit_count_; int commit_count_;
...@@ -336,6 +402,9 @@ class HierarchyChanged_NodeCreatedObserver : public TreeObserverBase { ...@@ -336,6 +402,9 @@ class HierarchyChanged_NodeCreatedObserver : public TreeObserverBase {
// TODO(beng): reenable these once converted to new way of connecting. // TODO(beng): reenable these once converted to new way of connecting.
TEST_F(ViewManagerTest, SetUp) {
}
TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeCreated) { TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeCreated) {
HierarchyChanged_NodeCreatedObserver observer(view_manager_2()); HierarchyChanged_NodeCreatedObserver observer(view_manager_2());
ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1()); ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1());
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/bindings/callback.h" #include "mojo/public/cpp/bindings/callback.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h" #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
...@@ -27,16 +28,16 @@ class ViewTreeNode; ...@@ -27,16 +28,16 @@ class ViewTreeNode;
// TODO: displays // TODO: displays
class ViewManager { class ViewManager {
public: public:
// Blocks on establishing the connection and subsequently receiving a node
// tree from the service.
// TODO(beng): blocking is currently achieved by running a nested runloop,
// which will dispatch all messages on all pipes while blocking.
// we should instead wait on the client pipe receiving a
// connection established message.
// TODO(beng): this method could optionally not block if supplied a callback.
explicit ViewManager(Application* application);
~ViewManager(); ~ViewManager();
// |ready_callback| is run when the ViewManager connection is established
// and ready to use.
static void Create(
Application* application,
const base::Callback<void(ViewManager*)> ready_callback);
// Blocks until ViewManager is ready to use.
static ViewManager* CreateBlocking(Application* application);
ViewTreeNode* tree() { return tree_; } ViewTreeNode* tree() { return tree_; }
ViewTreeNode* GetNodeById(TransportNodeId id); ViewTreeNode* GetNodeById(TransportNodeId id);
...@@ -49,6 +50,11 @@ class ViewManager { ...@@ -49,6 +50,11 @@ class ViewManager {
typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap; typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap;
typedef std::map<TransportViewId, View*> IdToViewMap; typedef std::map<TransportViewId, View*> IdToViewMap;
ViewManager(Application* application,
const base::Callback<void(ViewManager*)> ready_callback);
base::Callback<void(ViewManager*)> ready_callback_;
ViewManagerSynchronizer* synchronizer_; ViewManagerSynchronizer* synchronizer_;
ViewTreeNode* tree_; ViewTreeNode* tree_;
......
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