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

Unified Diff: content/browser/mojo_shell_browsertest.cc

Issue 1149833007: Embed a mojo ApplicationManager in content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
Index: content/browser/mojo_shell_browsertest.cc
diff --git a/content/browser/mojo_shell_browsertest.cc b/content/browser/mojo_shell_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..737be5c9a5ae8d049166480ef01a2696341ecaf0
--- /dev/null
+++ b/content/browser/mojo_shell_browsertest.cc
@@ -0,0 +1,162 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/time/time.h"
+#include "content/public/browser/mojo_app_connection.h"
+#include "content/public/browser/mojo_shell_context.h"
+#include "content/public/common/application_registry.h"
+#include "content/public/common/content_client.h"
+#include "content/public/common/static_mojo_application_loader.h"
+#include "content/public/test/content_browser_test.h"
+#include "content/public/test/test_utils.h"
+#include "content/test/test_content_utility_client.h"
+#include "content/test/test_service.mojom.h"
+#include "mojo/application/public/cpp/application_connection.h"
+#include "mojo/application/public/cpp/application_delegate.h"
+#include "mojo/application/public/cpp/application_impl.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
+
+namespace content {
+
+// Simple TestApp which provides a TestService impl. The app terminates itself
+// after its TestService fulfills a single DoSomething call.
+class TestApp : public mojo::ApplicationDelegate,
+ public mojo::InterfaceFactory<TestService>,
+ public TestService {
+ public:
+ TestApp() : service_binding_(this), app_(nullptr) {}
+
+ ~TestApp() override {}
+
+ private:
+ // mojo::ApplicationDelegate:
+ void Initialize(mojo::ApplicationImpl* app) override {
+ app_ = app;
+ }
+
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override {
+ connection->AddService<TestService>(this);
+ return true;
+ }
+
+ // mojo::InterfaceFactory<TestService>:
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<TestService> request) override {
+ DCHECK(!service_binding_.is_bound());
+ service_binding_.Bind(request.Pass());
+ }
+
+ // TestService:
+ void DoSomething(const DoSomethingCallback& callback) override {
+ callback.Run();
+ DCHECK(app_);
+ app_->Terminate();
+ }
+
+ mojo::Binding<TestService> service_binding_;
+
+ // Not owned.
+ mojo::ApplicationImpl* app_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestApp);
+};
+
+class MojoShellTestUtilityClient : public TestContentUtilityClient {
+ public:
+ MojoShellTestUtilityClient(
+ const base::Callback<void(ApplicationRegistry*)>& registration_callback)
+ : registration_callback_(registration_callback) {}
+
+ // ContentUtilityClient:
+ void RegisterMojoApplications(ApplicationRegistry* registry) override {
+ registration_callback_.Run(registry);
+ }
+
+ private:
+ base::Callback<void(ApplicationRegistry*)> registration_callback_;
+};
+
+class MojoShellTest : public ContentBrowserTest {
+ public:
+ MojoShellTest()
+ : utility_client_(new MojoShellTestUtilityClient(
+ base::Bind(&MojoShellTest::SetUpUtilityApplications,
+ base::Unretained(this)))) {
+ MojoShellContext::SetApplicationRegistryInitializerForTesting(
+ base::Bind(&MojoShellTest::SetUpBrowserApplications,
+ base::Unretained(this)));
+ }
+
+ protected:
+ virtual void SetUpBrowserApplications(ApplicationRegistry* registry) {
+ registry->RegisterStaticAppForURL(
+ GURL("https://test.example.com/in-browser"),
+ base::Bind(&CreateTestApp));
+ }
+
+ virtual void SetUpUtilityApplications(ApplicationRegistry* registry) {
+ registry->RegisterStaticAppForURL(
+ GURL("https://test.example.com/in-utility"),
+ base::Bind(&CreateTestApp));
+ }
+
+ static void ValidateResult(int32_t expected_value,
+ const base::Closure& callback,
+ int32_t value) {
+ EXPECT_EQ(expected_value, value);
+ callback.Run();
+ }
+
+ private:
+ void SetUpOnMainThread() override {
+ ContentBrowserTest::SetUpOnMainThread();
+ SetUtilityClientForTesting(utility_client_.get());
+ in_process_utility_thread_helper_.reset(new InProcessUtilityThreadHelper);
+ }
+
+ void TearDownOnMainThread() override {
+ in_process_utility_thread_helper_.reset();
+ }
+
+ static scoped_ptr<mojo::ApplicationDelegate> CreateTestApp() {
+ return scoped_ptr<mojo::ApplicationDelegate>(new TestApp);
+ }
+
+ scoped_ptr<InProcessUtilityThreadHelper> in_process_utility_thread_helper_;
+ scoped_ptr<MojoShellTestUtilityClient> utility_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoShellTest);
+};
+
+IN_PROC_BROWSER_TEST_F(MojoShellTest, TestBrowserConnection) {
+ auto test_app = MojoAppConnection::Create(
+ GURL("https://test.example.com/in-browser"));
+ TestServicePtr test_service;
+ test_app->ConnectToService(&test_service);
+
+ base::RunLoop run_loop;
+ test_service->DoSomething(run_loop.QuitClosure());
+ run_loop.Run();
+}
+
+IN_PROC_BROWSER_TEST_F(MojoShellTest, TestUtilityConnection) {
Ken Rockot(use gerrit already) 2015/05/27 00:12:23 I'm not terribly happy with the fact that this act
jam 2015/05/27 16:05:35 i think we want to test the production code path,
+ auto test_app = MojoAppConnection::Create(
+ GURL("https://test.example.com/in-utility"));
+ TestServicePtr test_service;
+ test_app->ConnectToService(&test_service);
+
+ base::RunLoop run_loop;
+ test_service->DoSomething(run_loop.QuitClosure());
+ run_loop.Run();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698