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

Unified Diff: mojo/shell/shell_test_helper.cc

Issue 308053008: Simplifies ShellTestHelper and ViewManager tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge to trunk Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/shell_test_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/shell_test_helper.cc
diff --git a/mojo/shell/shell_test_helper.cc b/mojo/shell/shell_test_helper.cc
index 1fc3ae498d71b70f77eae11ead76c17939523529..33cd1624cc2db32b15f02009a20f8c315bd2e4ce 100644
--- a/mojo/shell/shell_test_helper.cc
+++ b/mojo/shell/shell_test_helper.cc
@@ -6,40 +6,11 @@
#include "base/command_line.h"
#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "mojo/service_manager/service_loader.h"
-#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
namespace mojo {
namespace shell {
-// State used on the background thread. Be careful, this is created on the main
-// thread than passed to the shell thread. Destruction happens on the shell
-// thread.
-struct ShellTestHelper::State {
- scoped_ptr<Context> context;
- scoped_ptr<ServiceManager::TestAPI> test_api;
- ScopedMessagePipeHandle service_provider_handle;
-};
-
-namespace {
-
-void StartShellOnShellThread(ShellTestHelper::State* state) {
- state->context.reset(new Context);
- state->test_api.reset(
- new ServiceManager::TestAPI(state->context->service_manager()));
- state->service_provider_handle = state->test_api->GetServiceProviderHandle();
-}
-
-void SetLoaderForURLOnShellThread(ShellTestHelper::State* state,
- scoped_ptr<ServiceLoader> loader,
- const GURL& url) {
- state->context->service_manager()->SetLoaderForURL(loader.Pass(), url);
-}
-
-} // namespace
-
class ShellTestHelper::TestServiceProvider : public ServiceProvider {
public:
TestServiceProvider() {}
@@ -55,51 +26,25 @@ class ShellTestHelper::TestServiceProvider : public ServiceProvider {
DISALLOW_COPY_AND_ASSIGN(TestServiceProvider);
};
-ShellTestHelper::ShellTestHelper()
- : service_provider_thread_("shell_test_helper"),
- state_(NULL) {
+ShellTestHelper::ShellTestHelper() {
base::CommandLine::Init(0, NULL);
mojo::shell::InitializeLogging();
}
ShellTestHelper::~ShellTestHelper() {
- if (state_) {
- // |state_| contains data created on the background thread. Destroy it
- // there so that there aren't any race conditions.
- service_provider_thread_.message_loop()->DeleteSoon(FROM_HERE, state_);
- state_ = NULL;
- }
}
void ShellTestHelper::Init() {
- DCHECK(!state_);
- state_ = new State;
- service_provider_thread_.Start();
- base::MessageLoopProxy* message_loop_proxy =
- service_provider_thread_.message_loop()->message_loop_proxy();
- message_loop_proxy->PostTaskAndReply(
- FROM_HERE,
- base::Bind(&StartShellOnShellThread, state_),
- base::Bind(&ShellTestHelper::OnServiceProviderStarted,
- base::Unretained(this)));
- run_loop_.reset(new base::RunLoop);
- run_loop_->Run();
+ context_.reset(new Context);
+ test_api_.reset(new ServiceManager::TestAPI(context_->service_manager()));
+ local_service_provider_.reset(new TestServiceProvider);
+ service_provider_.Bind(test_api_->GetServiceProviderHandle().Pass());
+ service_provider_.set_client(local_service_provider_.get());
}
void ShellTestHelper::SetLoaderForURL(scoped_ptr<ServiceLoader> loader,
const GURL& url) {
- service_provider_thread_.message_loop()->message_loop_proxy()->PostTask(
- FROM_HERE,
- base::Bind(&SetLoaderForURLOnShellThread, state_, base::Passed(&loader),
- url));
-}
-
-void ShellTestHelper::OnServiceProviderStarted() {
- DCHECK(state_);
- local_service_provider_.reset(new TestServiceProvider);
- service_provider_.Bind(state_->service_provider_handle.Pass());
- service_provider_.set_client(local_service_provider_.get());
- run_loop_->Quit();
+ context_->service_manager()->SetLoaderForURL(loader.Pass(), url);
}
} // namespace shell
« no previous file with comments | « mojo/shell/shell_test_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698