OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/logging.h" |
| 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "content/browser/mojo_shell_context.h" |
| 11 #include "content/public/browser/mojo_app_connection.h" |
| 12 #include "content/public/common/application_registry.h" |
| 13 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/test_mojo_app.h" |
| 15 #include "content/public/test/test_mojo_service.mojom.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 const char kInProcessTestMojoApp[] = "system:content_in_process_test_app"; |
| 20 |
| 21 class MojoShellTest : public ContentBrowserTest { |
| 22 public: |
| 23 MojoShellTest() { |
| 24 MojoShellContext::SetApplicationRegistryInitializerForTesting(base::Bind( |
| 25 &MojoShellTest::SetUpBrowserApplications, base::Unretained(this))); |
| 26 } |
| 27 |
| 28 protected: |
| 29 virtual void SetUpBrowserApplications(ApplicationRegistry* registry) { |
| 30 registry->RegisterStaticAppForURL( |
| 31 GURL(kInProcessTestMojoApp), base::Bind(&CreateTestApp)); |
| 32 } |
| 33 |
| 34 private: |
| 35 static scoped_ptr<mojo::ApplicationDelegate> CreateTestApp() { |
| 36 return scoped_ptr<mojo::ApplicationDelegate>(new TestMojoApp); |
| 37 } |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(MojoShellTest); |
| 40 }; |
| 41 |
| 42 IN_PROC_BROWSER_TEST_F(MojoShellTest, TestBrowserConnection) { |
| 43 auto test_app = MojoAppConnection::Create(GURL(kInProcessTestMojoApp)); |
| 44 TestMojoServicePtr test_service; |
| 45 test_app->ConnectToService(&test_service); |
| 46 |
| 47 base::RunLoop run_loop; |
| 48 test_service->DoSomething(run_loop.QuitClosure()); |
| 49 run_loop.Run(); |
| 50 } |
| 51 |
| 52 IN_PROC_BROWSER_TEST_F(MojoShellTest, TestUtilityConnection) { |
| 53 // With no loader registered at this URL, the shell should spawn a utility |
| 54 // process and connect us to it. content_shell's utility process always hosts |
| 55 // a TestMojoApp at |kTestMojoAppUrl|. |
| 56 auto test_app = MojoAppConnection::Create(GURL(kTestMojoAppUrl)); |
| 57 TestMojoServicePtr test_service; |
| 58 test_app->ConnectToService(&test_service); |
| 59 |
| 60 base::RunLoop run_loop; |
| 61 test_service->DoSomething(run_loop.QuitClosure()); |
| 62 run_loop.Run(); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |