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

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: bauerb@ comment 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/run_loop.h"
11 #include "content/public/test/content_browser_test.h"
12 #include "content/public/test/test_mojo_service.mojom.h"
13
14 namespace content {
15
16 enum class TestCase {
17 // Value of result_test_case_ before assignment.
18 NONE,
19 // Successful call through the Mojo service with response back.
20 CALL_SERVICE,
21 // Call the Mojo service but the utility process terminates before getting
22 // the result back.
23 CONNECTION_ERROR,
24 // Call a function that fails because the sandbox is still enabled.
25 SANDBOX_FAILURE,
26 // Call a function that succeeds only when the sandbox is disabled.
27 SANDBOX_SUCCESS,
28 };
29
30 // Test fixture used to make different Mojo calls to the utility process.
31 // Depending on the test parameter, a different function on the Mojo service
32 // will be invoked.
33 class UtilityProcessMojoClientBrowserTest
34 : public ContentBrowserTest,
35 public ::testing::WithParamInterface<TestCase> {
36 public:
37 void StartTest() {
38 mojo_client_.reset(new UtilityProcessMojoClient<mojom::TestMojoService>(
39 L"TestMojoProcess",
40 base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest,
41 base::Unretained(this), TestCase::CONNECTION_ERROR)));
42
43 TestCase test_case = GetParam();
44 // This test case needs to have the sandbox disabled.
45 if (test_case == TestCase::SANDBOX_SUCCESS)
46 mojo_client_->set_disable_sandbox();
47 mojo_client_->Start();
48
49 switch (test_case) {
50 case TestCase::CALL_SERVICE:
51 mojo_client_->service()->DoSomething(
52 base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest,
53 base::Unretained(this), TestCase::CALL_SERVICE));
54 break;
55 case TestCase::CONNECTION_ERROR:
56 mojo_client_->service()->DoTerminateProcess(
57 base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest,
58 base::Unretained(this), TestCase::CALL_SERVICE));
59 break;
60 case TestCase::SANDBOX_FAILURE:
61 case TestCase::SANDBOX_SUCCESS:
62 mojo_client_->service()->CreateFolder(base::Bind(
63 &UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished,
64 base::Unretained(this)));
65 break;
66 case TestCase::NONE:
67 FAIL();
68 break;
69 }
70 }
71
72 protected:
73 void EndTest(TestCase result_test_case) {
74 result_test_case_ = result_test_case;
75 mojo_client_.reset();
76 done_closure_.Run();
77 }
78
79 void OnCreateFolderFinished(bool succeeded) {
80 EndTest(succeeded ? TestCase::SANDBOX_SUCCESS : TestCase::SANDBOX_FAILURE);
81 }
82
83 std::unique_ptr<UtilityProcessMojoClient<mojom::TestMojoService>>
84 mojo_client_;
85 base::Closure done_closure_;
86
87 // The test result that is compared to the current test case.
88 TestCase result_test_case_ = TestCase::NONE;
89 };
90
91 IN_PROC_BROWSER_TEST_P(UtilityProcessMojoClientBrowserTest, UtilityProcess) {
92 base::RunLoop run_loop;
93 done_closure_ = run_loop.QuitClosure();
94
95 StartTest();
96
97 run_loop.Run();
98 EXPECT_EQ(GetParam(), result_test_case_);
99 }
100
101 INSTANTIATE_TEST_CASE_P(TestCases,
Anand Mistry (off Chromium) 2016/06/14 00:32:29 I think this is an abuse of parametertised tests.
Patrick Monette 2016/06/14 21:23:32 I've switched out of parameterized tests.
102 UtilityProcessMojoClientBrowserTest,
103 ::testing::Values(TestCase::CALL_SERVICE,
104 TestCase::CONNECTION_ERROR,
105 TestCase::SANDBOX_FAILURE,
106 TestCase::SANDBOX_SUCCESS));
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698