| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "mojo/public/cpp/environment/environment.h" | 10 #include "mojo/public/cpp/environment/environment.h" |
| 11 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 #include "mojo/shell/public/cpp/application_impl.h" | 12 #include "mojo/shell/public/cpp/application_impl.h" |
| 13 #include "mojo/shell/public/cpp/application_test_base.h" | 13 #include "mojo/shell/public/cpp/application_test_base.h" |
| 14 #include "mojo/shell/public/interfaces/application.mojom.h" | 14 #include "mojo/shell/public/interfaces/application.mojom.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace test { | 17 namespace test { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 // Share the application URL with multiple application tests. | 20 // Share the application URL with multiple application tests. |
| 21 String g_url; | 21 String g_url; |
| 22 uint32_t g_id = Shell::kInvalidApplicationID; | 22 uint32_t g_id = shell::mojom::Shell::kInvalidApplicationID; |
| 23 | 23 |
| 24 // Application request handle passed from the shell in MojoMain, stored in | 24 // Application request handle passed from the shell in MojoMain, stored in |
| 25 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. | 25 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. |
| 26 InterfaceRequest<Application> g_application_request; | 26 InterfaceRequest<shell::mojom::Application> g_application_request; |
| 27 | 27 |
| 28 // Shell pointer passed in the initial mojo.Application.Initialize() call, | 28 // Shell pointer passed in the initial mojo.Application.Initialize() call, |
| 29 // stored in between initial setup and the first test and between SetUp/TearDown | 29 // stored in between initial setup and the first test and between SetUp/TearDown |
| 30 // calls so we can (re-)initialize new ApplicationImpls. | 30 // calls so we can (re-)initialize new ApplicationImpls. |
| 31 ShellPtr g_shell; | 31 shell::mojom::ShellPtr g_shell; |
| 32 | 32 |
| 33 class ShellGrabber : public Application { | 33 class ShellGrabber : public shell::mojom::Application { |
| 34 public: | 34 public: |
| 35 explicit ShellGrabber(InterfaceRequest<Application> application_request) | 35 explicit ShellGrabber( |
| 36 InterfaceRequest<shell::mojom::Application> application_request) |
| 36 : binding_(this, std::move(application_request)) {} | 37 : binding_(this, std::move(application_request)) {} |
| 37 | 38 |
| 38 void WaitForInitialize() { | 39 void WaitForInitialize() { |
| 39 // Initialize is always the first call made on Application. | 40 // Initialize is always the first call made on Application. |
| 40 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); | 41 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 // Application implementation. | 45 // Application implementation. |
| 45 void Initialize(ShellPtr shell, | 46 void Initialize(shell::mojom::ShellPtr shell, |
| 46 const mojo::String& url, | 47 const mojo::String& url, |
| 47 uint32_t id) override { | 48 uint32_t id) override { |
| 48 g_url = url; | 49 g_url = url; |
| 49 g_id = id; | 50 g_id = id; |
| 50 g_application_request = binding_.Unbind(); | 51 g_application_request = binding_.Unbind(); |
| 51 g_shell = std::move(shell); | 52 g_shell = std::move(shell); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void AcceptConnection(const String& requestor_url, | 55 void AcceptConnection(const String& requestor_url, |
| 55 uint32_t requestor_id, | 56 uint32_t requestor_id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 69 | 70 |
| 70 } // namespace | 71 } // namespace |
| 71 | 72 |
| 72 MojoResult RunAllTests(MojoHandle application_request_handle) { | 73 MojoResult RunAllTests(MojoHandle application_request_handle) { |
| 73 { | 74 { |
| 74 // This loop is used for init, and then destroyed before running tests. | 75 // This loop is used for init, and then destroyed before running tests. |
| 75 Environment::InstantiateDefaultRunLoop(); | 76 Environment::InstantiateDefaultRunLoop(); |
| 76 | 77 |
| 77 // Grab the shell handle. | 78 // Grab the shell handle. |
| 78 ShellGrabber grabber( | 79 ShellGrabber grabber( |
| 79 MakeRequest<Application>(MakeScopedHandle( | 80 MakeRequest<shell::mojom::Application>(MakeScopedHandle( |
| 80 MessagePipeHandle(application_request_handle)))); | 81 MessagePipeHandle(application_request_handle)))); |
| 81 grabber.WaitForInitialize(); | 82 grabber.WaitForInitialize(); |
| 82 MOJO_CHECK(g_shell); | 83 MOJO_CHECK(g_shell); |
| 83 MOJO_CHECK(g_application_request.is_pending()); | 84 MOJO_CHECK(g_application_request.is_pending()); |
| 84 | 85 |
| 85 int argc = 0; | 86 int argc = 0; |
| 86 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 87 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 87 const char** argv = new const char* [cmd_line->argv().size() + 1]; | 88 const char** argv = new const char* [cmd_line->argv().size() + 1]; |
| 88 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
| 89 std::vector<std::string> local_strings; | 90 std::vector<std::string> local_strings; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 110 g_shell.reset(); | 111 g_shell.reset(); |
| 111 | 112 |
| 112 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 113 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
| 113 } | 114 } |
| 114 | 115 |
| 115 TestHelper::TestHelper(ApplicationDelegate* delegate) | 116 TestHelper::TestHelper(ApplicationDelegate* delegate) |
| 116 : application_impl_(new ApplicationImpl( | 117 : application_impl_(new ApplicationImpl( |
| 117 delegate == nullptr ? &default_application_delegate_ : delegate, | 118 delegate == nullptr ? &default_application_delegate_ : delegate, |
| 118 std::move(g_application_request))) { | 119 std::move(g_application_request))) { |
| 119 // Fake application initialization. | 120 // Fake application initialization. |
| 120 Application* application = application_impl_.get(); | 121 shell::mojom::Application* application = application_impl_.get(); |
| 121 application->Initialize(std::move(g_shell), g_url, g_id); | 122 application->Initialize(std::move(g_shell), g_url, g_id); |
| 122 } | 123 } |
| 123 | 124 |
| 124 TestHelper::~TestHelper() { | 125 TestHelper::~TestHelper() { |
| 125 // TODO: commented out until http://crbug.com/533107 is solved. | 126 // TODO: commented out until http://crbug.com/533107 is solved. |
| 126 // { | 127 // { |
| 127 // ApplicationImpl::TestApi test_api(application_impl_); | 128 // ApplicationImpl::TestApi test_api(application_impl_); |
| 128 // test_api.UnbindConnections(&g_application_request, &g_shell); | 129 // test_api.UnbindConnections(&g_application_request, &g_shell); |
| 129 // } | 130 // } |
| 130 // We may have supplied a member as the delegate. Delete |application_impl_| | 131 // We may have supplied a member as the delegate. Delete |application_impl_| |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (ShouldCreateDefaultRunLoop()) | 164 if (ShouldCreateDefaultRunLoop()) |
| 164 Environment::DestroyDefaultRunLoop(); | 165 Environment::DestroyDefaultRunLoop(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 168 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 168 return true; | 169 return true; |
| 169 } | 170 } |
| 170 | 171 |
| 171 } // namespace test | 172 } // namespace test |
| 172 } // namespace mojo | 173 } // namespace mojo |
| OLD | NEW |