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

Side by Side Diff: content/browser/utility_process_mojo_client_browsertest.cc

Issue 2049303002: Add the UtilityProcessMojoClient class and convert SafeJsonParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compilation 2 Created 4 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "content/public/browser/utility_process_mojo_client.h"
6
7 #include <memory>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/test_mojo_service.mojom.h"
15
16 namespace content {
17
18 // Test fixture used to make different Mojo calls to the utility process.
19 class UtilityProcessMojoClientBrowserTest : public ContentBrowserTest {
20 public:
21 void StartMojoService(bool disable_sandbox) {
22 mojo_client_.reset(new UtilityProcessMojoClient<mojom::TestMojoService>(
23 base::ASCIIToUTF16("TestMojoProcess"),
24 base::Bind(&UtilityProcessMojoClientBrowserTest::OnConnectionError,
25 base::Unretained(this))));
26
27 // This test case needs to have the sandbox disabled.
28 if (disable_sandbox)
29 mojo_client_->set_disable_sandbox();
30 mojo_client_->Start();
31 }
32
33 // Called when a response is received from a call to DoSomething() or
34 // DoTerminateProcess().
35 void OnResponseReceived() {
36 response_received_ = true;
37 done_closure_.Run();
38 }
39
40 // Called when a connection error happen between the test and the utility
41 // process.
42 void OnConnectionError() {
43 error_happened_ = true;
44 done_closure_.Run();
45 }
46
47 // Called when a responsed is received from a call to CreateFolder().
48 void OnCreateFolderFinished(bool succeeded) {
49 response_received_ = true;
50 sandbox_succeeded_ = succeeded;
51 done_closure_.Run();
52 }
53
54 protected:
55 std::unique_ptr<UtilityProcessMojoClient<mojom::TestMojoService>>
56 mojo_client_;
57 base::Closure done_closure_;
58
59 // The test result that is compared to the current test case.
60 bool response_received_ = false;
61 bool error_happened_ = false;
62 bool sandbox_succeeded_ = false;
63 };
64
65 // Successful call through the Mojo service with response back.
66 IN_PROC_BROWSER_TEST_F(UtilityProcessMojoClientBrowserTest, CallService) {
67 base::RunLoop run_loop;
68 done_closure_ = run_loop.QuitClosure();
69
70 StartMojoService(false);
71
72 mojo_client_->service()->DoSomething(
73 base::Bind(&UtilityProcessMojoClientBrowserTest::OnResponseReceived,
74 base::Unretained(this)));
75
76 run_loop.Run();
77 EXPECT_TRUE(response_received_);
78 EXPECT_FALSE(error_happened_);
79 }
80
81 // Call the Mojo service but the utility process terminates before getting
82 // the result back.
83 // TODO(pmonette): Re-enable when crbug.com/618206 is fixed.
84 IN_PROC_BROWSER_TEST_F(UtilityProcessMojoClientBrowserTest,
85 DISABLED_ConnectionError) {
86 base::RunLoop run_loop;
87 done_closure_ = run_loop.QuitClosure();
88
89 StartMojoService(false);
90
91 mojo_client_->service()->DoTerminateProcess(
92 base::Bind(&UtilityProcessMojoClientBrowserTest::OnResponseReceived,
93 base::Unretained(this)));
94
95 run_loop.Run();
96 EXPECT_FALSE(response_received_);
97 EXPECT_TRUE(error_happened_);
98 }
99
100 // Call a function that fails because the sandbox is still enabled.
101 IN_PROC_BROWSER_TEST_F(UtilityProcessMojoClientBrowserTest, SandboxFailure) {
102 base::RunLoop run_loop;
103 done_closure_ = run_loop.QuitClosure();
104
105 StartMojoService(false);
106
107 mojo_client_->service()->CreateFolder(
108 base::Bind(&UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished,
109 base::Unretained(this)));
110
111 run_loop.Run();
112 EXPECT_TRUE(response_received_);
113 EXPECT_FALSE(sandbox_succeeded_);
114 EXPECT_FALSE(error_happened_);
115 }
116
117 // Call a function that succeeds only when the sandbox is disabled.
118 IN_PROC_BROWSER_TEST_F(UtilityProcessMojoClientBrowserTest, SandboxSuccess) {
119 base::RunLoop run_loop;
120 done_closure_ = run_loop.QuitClosure();
121
122 StartMojoService(true);
123
124 mojo_client_->service()->CreateFolder(
125 base::Bind(&UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished,
126 base::Unretained(this)));
127
128 run_loop.Run();
129 EXPECT_TRUE(response_received_);
130 EXPECT_TRUE(sandbox_succeeded_);
131 EXPECT_FALSE(error_happened_);
132 }
133
134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698