| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/browser/utility_process_host_impl.h" | 12 #include "content/browser/utility_process_host_impl.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/utility_process_host_client.h" | 14 #include "content/public/browser/utility_process_host_client.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_mojo_service.mojom.h" | 16 #include "content/public/test/test_service.mojom.h" |
| 17 #include "services/shell/public/cpp/interface_provider.h" | 17 #include "services/shell/public/cpp/interface_provider.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const std::string kTestMessage = "My hovercraft is full of eels!"; | 22 const std::string kTestMessage = "My hovercraft is full of eels!"; |
| 23 | 23 |
| 24 class MojoSandboxTest : public ContentBrowserTest { | 24 class MojoSandboxTest : public ContentBrowserTest { |
| 25 public: | 25 public: |
| 26 MojoSandboxTest() {} | 26 MojoSandboxTest() {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 void StopUtilityProcessOnIoThread() { host_.reset(); } | 57 void StopUtilityProcessOnIoThread() { host_.reset(); } |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(MojoSandboxTest); | 59 DISALLOW_COPY_AND_ASSIGN(MojoSandboxTest); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 IN_PROC_BROWSER_TEST_F(MojoSandboxTest, SubprocessSharedBuffer) { | 62 IN_PROC_BROWSER_TEST_F(MojoSandboxTest, SubprocessSharedBuffer) { |
| 63 // Ensures that a shared buffer can be created within a sandboxed process. | 63 // Ensures that a shared buffer can be created within a sandboxed process. |
| 64 | 64 |
| 65 mojom::TestMojoServicePtr test_service; | 65 mojom::TestServicePtr test_service; |
| 66 host_->GetRemoteInterfaces()->GetInterface(&test_service); | 66 host_->GetRemoteInterfaces()->GetInterface(&test_service); |
| 67 | 67 |
| 68 bool got_response = false; | 68 bool got_response = false; |
| 69 base::RunLoop run_loop; | 69 base::RunLoop run_loop; |
| 70 test_service.set_connection_error_handler(run_loop.QuitClosure()); | 70 test_service.set_connection_error_handler(run_loop.QuitClosure()); |
| 71 test_service->CreateSharedBuffer( | 71 test_service->CreateSharedBuffer( |
| 72 kTestMessage, | 72 kTestMessage, |
| 73 base::Bind( | 73 base::Bind( |
| 74 [](const base::Closure& quit_closure, bool* got_response, | 74 [](const base::Closure& quit_closure, bool* got_response, |
| 75 mojo::ScopedSharedBufferHandle buffer) { | 75 mojo::ScopedSharedBufferHandle buffer) { |
| 76 ASSERT_TRUE(buffer.is_valid()); | 76 ASSERT_TRUE(buffer.is_valid()); |
| 77 mojo::ScopedSharedBufferMapping mapping = | 77 mojo::ScopedSharedBufferMapping mapping = |
| 78 buffer->Map(kTestMessage.size()); | 78 buffer->Map(kTestMessage.size()); |
| 79 ASSERT_TRUE(mapping); | 79 ASSERT_TRUE(mapping); |
| 80 std::string contents(static_cast<const char*>(mapping.get()), | 80 std::string contents(static_cast<const char*>(mapping.get()), |
| 81 kTestMessage.size()); | 81 kTestMessage.size()); |
| 82 EXPECT_EQ(kTestMessage, contents); | 82 EXPECT_EQ(kTestMessage, contents); |
| 83 *got_response = true; | 83 *got_response = true; |
| 84 quit_closure.Run(); | 84 quit_closure.Run(); |
| 85 }, | 85 }, |
| 86 run_loop.QuitClosure(), &got_response)); | 86 run_loop.QuitClosure(), &got_response)); |
| 87 run_loop.Run(); | 87 run_loop.Run(); |
| 88 EXPECT_TRUE(got_response); | 88 EXPECT_TRUE(got_response); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace | 91 } // namespace |
| 92 } // namespace content | 92 } // namespace content |
| OLD | NEW |