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