Chromium Code Reviews| Index: content/browser/utility_process_mojo_client_browsertest.cc |
| diff --git a/content/browser/utility_process_mojo_client_browsertest.cc b/content/browser/utility_process_mojo_client_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b84bfe77ffbf5c1ef7e5042fdd0a79bf6ab235d0 |
| --- /dev/null |
| +++ b/content/browser/utility_process_mojo_client_browsertest.cc |
| @@ -0,0 +1,108 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/public/browser/utility_process_mojo_client.h" |
| + |
| +#include <memory> |
| + |
| +#include "base/bind.h" |
| +#include "base/run_loop.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/test_mojo_service.mojom.h" |
| + |
| +namespace content { |
| + |
| +enum class TestCase { |
| + // Value of result_test_case_ before assignment. |
| + NONE, |
| + // Successful call through the Mojo service with response back. |
| + CALL_SERVICE, |
| + // Call the Mojo service but the utility process terminates before getting |
| + // the result back. |
| + CONNECTION_ERROR, |
| + // Call a function that fails because the sandbox is still enabled. |
| + SANDBOX_FAILURE, |
| + // Call a function that succeeds only when the sandbox is disabled. |
| + SANDBOX_SUCCESS, |
| +}; |
| + |
| +// Test fixture used to make different Mojo calls to the utility process. |
| +// Depending on the test parameter, a different function on the Mojo service |
| +// will be invoked. |
| +class UtilityProcessMojoClientBrowserTest |
| + : public ContentBrowserTest, |
| + public ::testing::WithParamInterface<TestCase> { |
| + public: |
| + void StartTest() { |
| + mojo_client_.reset(new UtilityProcessMojoClient<mojom::TestMojoService>( |
| + L"TestMojoProcess", |
| + base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest, |
| + base::Unretained(this), TestCase::CONNECTION_ERROR))); |
| + |
| + TestCase test_case = GetParam(); |
| + // This test case needs to have the sandbox disabled. |
| + if (test_case == TestCase::SANDBOX_SUCCESS) |
| + mojo_client_->set_disable_sandbox(); |
| + mojo_client_->Start(); |
| + |
| + switch (test_case) { |
| + case TestCase::CALL_SERVICE: |
| + mojo_client_->service()->DoSomething( |
| + base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest, |
| + base::Unretained(this), TestCase::CALL_SERVICE)); |
| + break; |
| + case TestCase::CONNECTION_ERROR: |
| + mojo_client_->service()->DoTerminateProcess( |
| + base::Bind(&UtilityProcessMojoClientBrowserTest::EndTest, |
| + base::Unretained(this), TestCase::CALL_SERVICE)); |
| + break; |
| + case TestCase::SANDBOX_FAILURE: |
| + case TestCase::SANDBOX_SUCCESS: |
| + mojo_client_->service()->CreateFolder(base::Bind( |
| + &UtilityProcessMojoClientBrowserTest::OnCreateFolderFinished, |
| + base::Unretained(this))); |
| + break; |
| + case TestCase::NONE: |
| + FAIL(); |
| + break; |
| + } |
| + } |
| + |
| + protected: |
| + void EndTest(TestCase result_test_case) { |
| + result_test_case_ = result_test_case; |
| + mojo_client_.reset(); |
| + done_closure_.Run(); |
| + } |
| + |
| + void OnCreateFolderFinished(bool succeeded) { |
| + EndTest(succeeded ? TestCase::SANDBOX_SUCCESS : TestCase::SANDBOX_FAILURE); |
| + } |
| + |
| + std::unique_ptr<UtilityProcessMojoClient<mojom::TestMojoService>> |
| + mojo_client_; |
| + base::Closure done_closure_; |
| + |
| + // The test result that is compared to the current test case. |
| + TestCase result_test_case_ = TestCase::NONE; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_P(UtilityProcessMojoClientBrowserTest, UtilityProcess) { |
| + base::RunLoop run_loop; |
| + done_closure_ = run_loop.QuitClosure(); |
| + |
| + StartTest(); |
| + |
| + run_loop.Run(); |
| + EXPECT_EQ(GetParam(), result_test_case_); |
| +} |
| + |
| +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.
|
| + UtilityProcessMojoClientBrowserTest, |
| + ::testing::Values(TestCase::CALL_SERVICE, |
| + TestCase::CONNECTION_ERROR, |
| + TestCase::SANDBOX_FAILURE, |
| + TestCase::SANDBOX_SUCCESS)); |
| + |
| +} // namespace content |