| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 17 #include "mojo/shell/application_loader.h" | 17 #include "mojo/shell/application_loader.h" |
| 18 #include "mojo/shell/application_manager.h" | 18 #include "mojo/shell/application_manager.h" |
| 19 #include "mojo/shell/connect_util.h" | 19 #include "mojo/shell/connect_util.h" |
| 20 #include "mojo/shell/fetcher.h" | 20 #include "mojo/shell/fetcher.h" |
| 21 #include "mojo/shell/package_manager/package_manager_impl.h" | 21 #include "mojo/shell/package_manager/package_manager_impl.h" |
| 22 #include "mojo/shell/public/cpp/application_connection.h" | |
| 23 #include "mojo/shell/public/cpp/application_delegate.h" | |
| 24 #include "mojo/shell/public/cpp/application_impl.h" | 22 #include "mojo/shell/public/cpp/application_impl.h" |
| 25 #include "mojo/shell/public/cpp/interface_factory.h" | 23 #include "mojo/shell/public/cpp/interface_factory.h" |
| 24 #include "mojo/shell/public/cpp/shell_client.h" |
| 26 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | 25 #include "mojo/shell/public/interfaces/content_handler.mojom.h" |
| 27 #include "mojo/shell/public/interfaces/service_provider.mojom.h" | 26 #include "mojo/shell/public/interfaces/service_provider.mojom.h" |
| 28 #include "mojo/shell/test_package_manager.h" | 27 #include "mojo/shell/test_package_manager.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 namespace mojo { | 30 namespace mojo { |
| 32 namespace shell { | 31 namespace shell { |
| 33 namespace test { | 32 namespace test { |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 | 65 |
| 67 DISALLOW_COPY_AND_ASSIGN(TestFetcher); | 66 DISALLOW_COPY_AND_ASSIGN(TestFetcher); |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 void QuitClosure(bool* value) { | 69 void QuitClosure(bool* value) { |
| 71 *value = true; | 70 *value = true; |
| 72 base::MessageLoop::current()->QuitWhenIdle(); | 71 base::MessageLoop::current()->QuitWhenIdle(); |
| 73 } | 72 } |
| 74 | 73 |
| 75 class TestContentHandler : public mojom::ContentHandler, | 74 class TestContentHandler : public mojom::ContentHandler, |
| 76 public ApplicationDelegate { | 75 public ShellClient{ |
| 77 public: | 76 public: |
| 78 TestContentHandler(ApplicationConnection* connection, | 77 TestContentHandler(Connection* connection, |
| 79 InterfaceRequest<mojom::ContentHandler> request) | 78 InterfaceRequest<mojom::ContentHandler> request) |
| 80 : binding_(this, std::move(request)) {} | 79 : binding_(this, std::move(request)) {} |
| 81 | 80 |
| 82 // ContentHandler: | 81 // ContentHandler: |
| 83 void StartApplication( | 82 void StartApplication( |
| 84 InterfaceRequest<mojom::Application> application_request, | 83 InterfaceRequest<mojom::Application> application_request, |
| 85 URLResponsePtr response, | 84 URLResponsePtr response, |
| 86 const Callback<void()>& destruct_callback) override { | 85 const Callback<void()>& destruct_callback) override { |
| 87 apps_.push_back(new ApplicationImpl(this, std::move(application_request))); | 86 apps_.push_back(new ApplicationImpl(this, std::move(application_request))); |
| 88 destruct_callback.Run(); | 87 destruct_callback.Run(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 private: | 90 private: |
| 92 StrongBinding<mojom::ContentHandler> binding_; | 91 StrongBinding<mojom::ContentHandler> binding_; |
| 93 ScopedVector<ApplicationImpl> apps_; | 92 ScopedVector<ApplicationImpl> apps_; |
| 94 | 93 |
| 95 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); | 94 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 class TestApplicationLoader : public ApplicationLoader, | 97 class TestApplicationLoader : public ApplicationLoader, |
| 99 public ApplicationDelegate, | 98 public ShellClient, |
| 100 public InterfaceFactory<mojom::ContentHandler> { | 99 public InterfaceFactory<mojom::ContentHandler> { |
| 101 public: | 100 public: |
| 102 TestApplicationLoader() : num_loads_(0) {} | 101 TestApplicationLoader() : num_loads_(0) {} |
| 103 ~TestApplicationLoader() override {} | 102 ~TestApplicationLoader() override {} |
| 104 | 103 |
| 105 int num_loads() const { return num_loads_; } | 104 int num_loads() const { return num_loads_; } |
| 106 const GURL& last_requestor_url() const { return last_requestor_url_; } | 105 const GURL& last_requestor_url() const { return last_requestor_url_; } |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 // ApplicationLoader implementation. | 108 // ApplicationLoader implementation. |
| 110 void Load(const GURL& url, | 109 void Load(const GURL& url, |
| 111 InterfaceRequest<mojom::Application> application_request) override { | 110 InterfaceRequest<mojom::Application> application_request) override { |
| 112 ++num_loads_; | 111 ++num_loads_; |
| 113 test_app_.reset(new ApplicationImpl(this, std::move(application_request))); | 112 test_app_.reset(new ApplicationImpl(this, std::move(application_request))); |
| 114 } | 113 } |
| 115 | 114 |
| 116 // ApplicationDelegate implementation. | 115 // mojo::ShellClient implementation. |
| 117 bool AcceptConnection(ApplicationConnection* connection) override { | 116 bool AcceptConnection(Connection* connection) override { |
| 118 connection->AddService<mojom::ContentHandler>(this); | 117 connection->AddService<mojom::ContentHandler>(this); |
| 119 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); | 118 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); |
| 120 return true; | 119 return true; |
| 121 } | 120 } |
| 122 // InterfaceFactory<mojom::ContentHandler> implementation. | 121 // InterfaceFactory<mojom::ContentHandler> implementation. |
| 123 void Create(ApplicationConnection* connection, | 122 void Create(Connection* connection, |
| 124 InterfaceRequest<mojom::ContentHandler> request) override { | 123 InterfaceRequest<mojom::ContentHandler> request) override { |
| 125 new TestContentHandler(connection, std::move(request)); | 124 new TestContentHandler(connection, std::move(request)); |
| 126 } | 125 } |
| 127 | 126 |
| 128 scoped_ptr<ApplicationImpl> test_app_; | 127 scoped_ptr<ApplicationImpl> test_app_; |
| 129 int num_loads_; | 128 int num_loads_; |
| 130 GURL last_requestor_url_; | 129 GURL last_requestor_url_; |
| 131 | 130 |
| 132 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 131 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
| 133 }; | 132 }; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 params->SetTargetURL(GURL("test:test")); | 319 params->SetTargetURL(GURL("test:test")); |
| 321 params->set_connect_callback( | 320 params->set_connect_callback( |
| 322 [&content_handler_id](uint32_t, uint32_t t) { content_handler_id = t; }); | 321 [&content_handler_id](uint32_t, uint32_t t) { content_handler_id = t; }); |
| 323 application_manager_->ConnectToApplication(std::move(params)); | 322 application_manager_->ConnectToApplication(std::move(params)); |
| 324 EXPECT_EQ(0u, content_handler_id); | 323 EXPECT_EQ(0u, content_handler_id); |
| 325 } | 324 } |
| 326 | 325 |
| 327 } // namespace test | 326 } // namespace test |
| 328 } // namespace package_manager | 327 } // namespace package_manager |
| 329 } // namespace mojo | 328 } // namespace mojo |
| OLD | NEW |