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_impl.h" | |
23 #include "mojo/shell/public/cpp/interface_factory.h" | 22 #include "mojo/shell/public/cpp/interface_factory.h" |
24 #include "mojo/shell/public/cpp/shell_client.h" | 23 #include "mojo/shell/public/cpp/shell_client.h" |
| 24 #include "mojo/shell/public/cpp/shell_connection.h" |
25 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | 25 #include "mojo/shell/public/interfaces/content_handler.mojom.h" |
26 #include "mojo/shell/public/interfaces/service_provider.mojom.h" | 26 #include "mojo/shell/public/interfaces/service_provider.mojom.h" |
27 #include "mojo/shell/test_package_manager.h" | 27 #include "mojo/shell/test_package_manager.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
30 namespace mojo { | 30 namespace mojo { |
31 namespace shell { | 31 namespace shell { |
32 namespace test { | 32 namespace test { |
33 namespace { | 33 namespace { |
34 | 34 |
(...skipping 30 matching lines...) Expand all Loading... |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(TestFetcher); | 66 DISALLOW_COPY_AND_ASSIGN(TestFetcher); |
67 }; | 67 }; |
68 | 68 |
69 void QuitClosure(bool* value) { | 69 void QuitClosure(bool* value) { |
70 *value = true; | 70 *value = true; |
71 base::MessageLoop::current()->QuitWhenIdle(); | 71 base::MessageLoop::current()->QuitWhenIdle(); |
72 } | 72 } |
73 | 73 |
74 class TestContentHandler : public mojom::ContentHandler, | 74 class TestContentHandler : public mojom::ContentHandler, |
75 public ShellClient{ | 75 public ShellClient { |
76 public: | 76 public: |
77 TestContentHandler(Connection* connection, | 77 TestContentHandler(Connection* connection, |
78 InterfaceRequest<mojom::ContentHandler> request) | 78 InterfaceRequest<mojom::ContentHandler> request) |
79 : binding_(this, std::move(request)) {} | 79 : binding_(this, std::move(request)) {} |
80 | 80 |
81 // ContentHandler: | 81 // ContentHandler: |
82 void StartApplication( | 82 void StartApplication( |
83 InterfaceRequest<mojom::Application> application_request, | 83 InterfaceRequest<mojom::ShellClient> request, |
84 URLResponsePtr response, | 84 URLResponsePtr response, |
85 const Callback<void()>& destruct_callback) override { | 85 const Callback<void()>& destruct_callback) override { |
86 apps_.push_back(new ApplicationImpl(this, std::move(application_request))); | 86 shell_connections_.push_back(new ShellConnection(this, std::move(request))); |
87 destruct_callback.Run(); | 87 destruct_callback.Run(); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 StrongBinding<mojom::ContentHandler> binding_; | 91 StrongBinding<mojom::ContentHandler> binding_; |
92 ScopedVector<ApplicationImpl> apps_; | 92 ScopedVector<ShellConnection> shell_connections_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); | 94 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); |
95 }; | 95 }; |
96 | 96 |
97 class TestApplicationLoader : public ApplicationLoader, | 97 class TestApplicationLoader : public ApplicationLoader, |
98 public ShellClient, | 98 public ShellClient, |
99 public InterfaceFactory<mojom::ContentHandler> { | 99 public InterfaceFactory<mojom::ContentHandler> { |
100 public: | 100 public: |
101 TestApplicationLoader() : num_loads_(0) {} | 101 TestApplicationLoader() : num_loads_(0) {} |
102 ~TestApplicationLoader() override {} | 102 ~TestApplicationLoader() override {} |
103 | 103 |
104 int num_loads() const { return num_loads_; } | 104 int num_loads() const { return num_loads_; } |
105 const GURL& last_requestor_url() const { return last_requestor_url_; } | 105 const GURL& last_requestor_url() const { return last_requestor_url_; } |
106 | 106 |
107 private: | 107 private: |
108 // ApplicationLoader implementation. | 108 // ApplicationLoader implementation. |
109 void Load(const GURL& url, | 109 void Load(const GURL& url, |
110 InterfaceRequest<mojom::Application> application_request) override { | 110 InterfaceRequest<mojom::ShellClient> request) override { |
111 ++num_loads_; | 111 ++num_loads_; |
112 test_app_.reset(new ApplicationImpl(this, std::move(application_request))); | 112 shell_connection_.reset(new ShellConnection(this, std::move(request))); |
113 } | 113 } |
114 | 114 |
115 // mojo::ShellClient implementation. | 115 // mojo::ShellClient implementation. |
116 bool AcceptConnection(Connection* connection) override { | 116 bool AcceptConnection(Connection* connection) override { |
117 connection->AddService<mojom::ContentHandler>(this); | 117 connection->AddService<mojom::ContentHandler>(this); |
118 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); | 118 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); |
119 return true; | 119 return true; |
120 } | 120 } |
121 // InterfaceFactory<mojom::ContentHandler> implementation. | 121 // InterfaceFactory<mojom::ContentHandler> implementation. |
122 void Create(Connection* connection, | 122 void Create(Connection* connection, |
123 InterfaceRequest<mojom::ContentHandler> request) override { | 123 InterfaceRequest<mojom::ContentHandler> request) override { |
124 new TestContentHandler(connection, std::move(request)); | 124 new TestContentHandler(connection, std::move(request)); |
125 } | 125 } |
126 | 126 |
127 scoped_ptr<ApplicationImpl> test_app_; | 127 scoped_ptr<ShellConnection> shell_connection_; |
128 int num_loads_; | 128 int num_loads_; |
129 GURL last_requestor_url_; | 129 GURL last_requestor_url_; |
130 | 130 |
131 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 131 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
132 }; | 132 }; |
133 | 133 |
134 class TestPackageManagerImpl : public PackageManagerImpl { | 134 class TestPackageManagerImpl : public PackageManagerImpl { |
135 public: | 135 public: |
136 explicit TestPackageManagerImpl(const base::FilePath& package_path) | 136 explicit TestPackageManagerImpl(const base::FilePath& package_path) |
137 : PackageManagerImpl(package_path, nullptr, nullptr), | 137 : PackageManagerImpl(package_path, nullptr, nullptr), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 params->SetTargetURL(GURL("test:test")); | 319 params->SetTargetURL(GURL("test:test")); |
320 params->set_connect_callback( | 320 params->set_connect_callback( |
321 [&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; }); |
322 application_manager_->ConnectToApplication(std::move(params)); | 322 application_manager_->ConnectToApplication(std::move(params)); |
323 EXPECT_EQ(0u, content_handler_id); | 323 EXPECT_EQ(0u, content_handler_id); |
324 } | 324 } |
325 | 325 |
326 } // namespace test | 326 } // namespace test |
327 } // namespace package_manager | 327 } // namespace package_manager |
328 } // namespace mojo | 328 } // namespace mojo |
OLD | NEW |