diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 19:31:23 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 19:31:23 +0000 |
commit | 1124dea06ec4f030992f95ab653ab3759b694fde (patch) | |
tree | c0937830d343965eb1540010b22c8290b5c68c99 /mojo/service_manager | |
parent | 6ba332af6e2c3b5039bbf3ecd7aac2df11e82217 (diff) | |
download | chromium_src-1124dea06ec4f030992f95ab653ab3759b694fde.zip chromium_src-1124dea06ec4f030992f95ab653ab3759b694fde.tar.gz chromium_src-1124dea06ec4f030992f95ab653ab3759b694fde.tar.bz2 |
Changes view manager test to connect via shell
Previously code was linking with ViewManager, now I'm connecting
through the shell. As part of this I'm adding a general class that
should make it easy to connect to any server through the shell.
For the time being I'm making the shell explicitly link with the
viewmanager. Eventually that'll have to change.
BUG=365012
TEST=covered by tests
R=davemoore@chromium.org
Review URL: https://codereview.chromium.org/256133002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/service_manager')
-rw-r--r-- | mojo/service_manager/service_manager.cc | 45 | ||||
-rw-r--r-- | mojo/service_manager/service_manager.h | 21 |
2 files changed, 58 insertions, 8 deletions
diff --git a/mojo/service_manager/service_manager.cc b/mojo/service_manager/service_manager.cc index c34e83f..b62c6e14b 100644 --- a/mojo/service_manager/service_manager.cc +++ b/mojo/service_manager/service_manager.cc @@ -58,14 +58,59 @@ class ServiceManager::ServiceFactory : public Shell, public ErrorHandler { ServiceManager* const manager_; const GURL url_; RemotePtr<ShellClient> shell_client_; + DISALLOW_COPY_AND_ASSIGN(ServiceFactory); }; +class ServiceManager::TestAPI::TestShellConnection + : public Shell, + public ErrorHandler { + public: + explicit TestShellConnection(ServiceManager* manager) : manager_(manager) { + InterfacePipe<Shell> pipe; + shell_client_.reset(pipe.handle_to_peer.Pass(), this, this); + shell_handle_ = pipe.handle_to_self.Pass(); + } + virtual ~TestShellConnection() {} + + ScopedShellHandle GetShellHandle() { + return shell_handle_.Pass(); + } + + // Shell: + virtual void Connect(const String& url, + ScopedMessagePipeHandle client_pipe) OVERRIDE { + manager_->Connect(GURL(url.To<std::string>()), client_pipe.Pass()); + } + + virtual void OnError() OVERRIDE { + } + + private: + ServiceManager* manager_; + RemotePtr<ShellClient> shell_client_; + ScopedShellHandle shell_handle_; + + DISALLOW_COPY_AND_ASSIGN(TestShellConnection); +}; + // static +ServiceManager::TestAPI::TestAPI(ServiceManager* manager) : manager_(manager) { +} + +ServiceManager::TestAPI::~TestAPI() { +} + bool ServiceManager::TestAPI::HasCreatedInstance() { return has_created_instance; } +ScopedShellHandle ServiceManager::TestAPI::GetShellHandle() { + if (!shell_connection_.get()) + shell_connection_.reset(new TestShellConnection(manager_)); + return shell_connection_->GetShellHandle().Pass(); +} + bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const { return manager_->url_to_service_factory_.find(url) != manager_->url_to_service_factory_.end(); diff --git a/mojo/service_manager/service_manager.h b/mojo/service_manager/service_manager.h index 40cb8cd..ae41127 100644 --- a/mojo/service_manager/service_manager.h +++ b/mojo/service_manager/service_manager.h @@ -16,27 +16,32 @@ #include "mojo/service_manager/service_manager_export.h" #include "url/gurl.h" -namespace content { - class MojoTest; -} - namespace mojo { class MOJO_SERVICE_MANAGER_EXPORT ServiceManager { public: // API for testing. class MOJO_SERVICE_MANAGER_EXPORT TestAPI { - private: - friend class ServiceManagerTest; - friend class content::MojoTest; + public: + explicit TestAPI(ServiceManager* manager); + ~TestAPI(); + + // Returns a handle to the shell. + ScopedShellHandle GetShellHandle(); - explicit TestAPI(ServiceManager* manager) : manager_(manager) {} // Returns true if the shared instance has been created. static bool HasCreatedInstance(); // Returns true if there is a ServiceFactory for this URL. bool HasFactoryForURL(const GURL& url) const; + private: + class TestShellConnection; + ServiceManager* manager_; + + scoped_ptr<TestShellConnection> shell_connection_; + + DISALLOW_COPY_AND_ASSIGN(TestAPI); }; // Interface class for debugging only. |