OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "content/public/browser/utility_process_mojo_client.h" | 5 #include "content/public/browser/utility_process_mojo_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
16 #include "content/public/test/test_service.mojom.h" | 16 #include "content/public/test/test_service.mojom.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 // Test fixture used to make different Mojo calls to the utility process. | 20 // Test fixture used to make different Mojo calls to the utility process. |
21 class UtilityProcessMojoClientBrowserTest : public ContentBrowserTest { | 21 class UtilityProcessMojoClientBrowserTest : public ContentBrowserTest { |
22 public: | 22 public: |
23 void StartMojoService(bool disable_sandbox) { | 23 void StartMojoService(bool disable_sandbox, bool run_elevated = false) { |
Sam McNally
2017/01/16 04:16:20
This would be nicer as an enum {SANDBOXED, UNSANDB
Noel Gordon
2017/01/16 11:09:58
Acknowledged.
Noel Gordon
2017/01/18 06:02:03
... but somewhat unrelated to this change: maybe b
| |
24 mojo_client_.reset(new UtilityProcessMojoClient<mojom::TestService>( | 24 mojo_client_.reset(new UtilityProcessMojoClient<mojom::TestService>( |
25 base::ASCIIToUTF16("TestMojoProcess"))); | 25 base::ASCIIToUTF16("TestMojoProcess"))); |
26 | 26 |
27 mojo_client_->set_error_callback( | 27 mojo_client_->set_error_callback( |
28 base::Bind(&UtilityProcessMojoClientBrowserTest::OnConnectionError, | 28 base::Bind(&UtilityProcessMojoClientBrowserTest::OnConnectionError, |
29 base::Unretained(this))); | 29 base::Unretained(this))); |
30 | 30 |
31 // This test case needs to have the sandbox disabled. | 31 // This test case needs to have the sandbox disabled. |
32 if (disable_sandbox) | 32 if (disable_sandbox) |
33 mojo_client_->set_disable_sandbox(); | 33 mojo_client_->set_disable_sandbox(); |
34 #if defined(OS_WIN) | |
35 // This test case needs utility process privilege elevation. | |
36 if (run_elevated) { | |
37 CHECK(disable_sandbox); | |
38 mojo_client_->set_run_elevated(); | |
39 } | |
40 #endif // defined(OS_WIN) | |
41 | |
34 mojo_client_->Start(); | 42 mojo_client_->Start(); |
35 } | 43 } |
36 | 44 |
37 // Called when a response is received from a call to DoSomething() or | 45 // Called when a response is received from a call to DoSomething() or |
38 // DoTerminateProcess(). | 46 // DoTerminateProcess(). |
39 void OnResponseReceived() { | 47 void OnResponseReceived() { |
40 response_received_ = true; | 48 response_received_ = true; |
41 done_closure_.Run(); | 49 done_closure_.Run(); |
42 } | 50 } |
43 | 51 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 137 |
130 mojo_client_->service()->CreateFolder( | 138 mojo_client_->service()->CreateFolder( |
131 base::Bind(&UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished, | 139 base::Bind(&UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished, |
132 base::Unretained(this))); | 140 base::Unretained(this))); |
133 | 141 |
134 run_loop.Run(); | 142 run_loop.Run(); |
135 EXPECT_TRUE(response_received_); | 143 EXPECT_TRUE(response_received_); |
136 EXPECT_TRUE(sandbox_succeeded_); | 144 EXPECT_TRUE(sandbox_succeeded_); |
137 EXPECT_FALSE(error_happened_); | 145 EXPECT_FALSE(error_happened_); |
138 } | 146 } |
139 #endif | 147 #endif // !defined(OS_ANDROID) |
148 | |
149 #if defined(OS_WIN) | |
150 // Call a function that succeeds with process elevation. Elevation is only | |
151 // available on WIN, and is used to permit UAC prompts for operations that | |
152 // need user approval before proceeding. | |
153 IN_PROC_BROWSER_TEST_F(UtilityProcessMojoClientBrowserTest, ElevatedSuccess) { | |
154 base::RunLoop run_loop; | |
155 done_closure_ = run_loop.QuitClosure(); | |
156 | |
157 bool elevated_utility_process = true; | |
158 StartMojoService(true, elevated_utility_process); | |
159 | |
160 mojo_client_->service()->CreateFolder( | |
161 base::Bind(&UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished, | |
162 base::Unretained(this))); | |
163 | |
164 run_loop.Run(); | |
165 EXPECT_TRUE(response_received_); | |
166 EXPECT_TRUE(sandbox_succeeded_); | |
167 EXPECT_FALSE(error_happened_); | |
168 } | |
169 #endif // defined(OS_WIN) | |
140 | 170 |
141 } // namespace content | 171 } // namespace content |
OLD | NEW |