Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: mojo/shell/capability_filter_test.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/capability_filter_test.h ('k') | mojo/shell/fetcher/about_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/shell/capability_filter_test.h" 5 #include "mojo/shell/capability_filter_test.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 }; 106 };
107 107
108 // This class models a system service that exposes two interfaces, Safe and 108 // This class models a system service that exposes two interfaces, Safe and
109 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications. 109 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications.
110 class ServiceApplication : public ApplicationDelegate, 110 class ServiceApplication : public ApplicationDelegate,
111 public InterfaceFactory<Safe>, 111 public InterfaceFactory<Safe>,
112 public InterfaceFactory<Unsafe>, 112 public InterfaceFactory<Unsafe>,
113 public Safe, 113 public Safe,
114 public Unsafe { 114 public Unsafe {
115 public: 115 public:
116 ServiceApplication() : app_(nullptr) {} 116 ServiceApplication() : shell_(nullptr) {}
117 ~ServiceApplication() override {} 117 ~ServiceApplication() override {}
118 118
119 private: 119 private:
120 // Overridden from ApplicationDelegate: 120 // Overridden from ApplicationDelegate:
121 void Initialize(ApplicationImpl* app) override { 121 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {
122 app_ = app; 122 shell_ = shell;
123 // ServiceApplications have no capability filter and can thus connect 123 // ServiceApplications have no capability filter and can thus connect
124 // directly to the validator application. 124 // directly to the validator application.
125 app_->ConnectToService("test:validator", &validator_); 125 shell_->ConnectToService("test:validator", &validator_);
126 } 126 }
127 bool AcceptConnection(ApplicationConnection* connection) override { 127 bool AcceptConnection(ApplicationConnection* connection) override {
128 AddService<Safe>(connection); 128 AddService<Safe>(connection);
129 AddService<Unsafe>(connection); 129 AddService<Unsafe>(connection);
130 return true; 130 return true;
131 } 131 }
132 132
133 // Overridden from InterfaceFactory<Safe>: 133 // Overridden from InterfaceFactory<Safe>:
134 void Create(ApplicationConnection* connection, 134 void Create(ApplicationConnection* connection,
135 InterfaceRequest<Safe> request) override { 135 InterfaceRequest<Safe> request) override {
136 safe_bindings_.AddBinding(this, std::move(request)); 136 safe_bindings_.AddBinding(this, std::move(request));
137 } 137 }
138 138
139 // Overridden from InterfaceFactory<Unsafe>: 139 // Overridden from InterfaceFactory<Unsafe>:
140 void Create(ApplicationConnection* connection, 140 void Create(ApplicationConnection* connection,
141 InterfaceRequest<Unsafe> request) override { 141 InterfaceRequest<Unsafe> request) override {
142 unsafe_bindings_.AddBinding(this, std::move(request)); 142 unsafe_bindings_.AddBinding(this, std::move(request));
143 } 143 }
144 144
145 template <typename Interface> 145 template <typename Interface>
146 void AddService(ApplicationConnection* connection) { 146 void AddService(ApplicationConnection* connection) {
147 validator_->AddServiceCalled(connection->GetRemoteApplicationURL(), 147 validator_->AddServiceCalled(connection->GetRemoteApplicationURL(),
148 connection->GetConnectionURL(), 148 connection->GetConnectionURL(),
149 Interface::Name_, 149 Interface::Name_,
150 !connection->AddService<Interface>(this)); 150 !connection->AddService<Interface>(this));
151 } 151 }
152 152
153 ApplicationImpl* app_; 153 Shell* shell_;
154 ValidatorPtr validator_; 154 ValidatorPtr validator_;
155 WeakBindingSet<Safe> safe_bindings_; 155 WeakBindingSet<Safe> safe_bindings_;
156 WeakBindingSet<Unsafe> unsafe_bindings_; 156 WeakBindingSet<Unsafe> unsafe_bindings_;
157 157
158 DISALLOW_COPY_AND_ASSIGN(ServiceApplication); 158 DISALLOW_COPY_AND_ASSIGN(ServiceApplication);
159 }; 159 };
160 160
161 //////////////////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////////////////
162 // TestApplication: 162 // TestApplication:
163 163
164 TestApplication::TestApplication() : app_(nullptr) {} 164 TestApplication::TestApplication() : shell_(nullptr) {}
165 TestApplication::~TestApplication() {} 165 TestApplication::~TestApplication() {}
166 166
167 void TestApplication::Initialize(ApplicationImpl* app) { 167 void TestApplication::Initialize(Shell* shell, const std::string& url,
168 app_ = app; 168 uint32_t id) {
169 shell_ = shell;
170 url_ = url;
169 } 171 }
170 bool TestApplication::AcceptConnection( 172 bool TestApplication::AcceptConnection(
171 ApplicationConnection* connection) { 173 ApplicationConnection* connection) {
172 // TestApplications receive their Validator via the inbound connection. 174 // TestApplications receive their Validator via the inbound connection.
173 connection->ConnectToService(&validator_); 175 connection->ConnectToService(&validator_);
174 176
175 connection1_ = app_->ConnectToApplication("test:service"); 177 connection1_ = shell_->ConnectToApplication("test:service");
176 connection1_->SetRemoteServiceProviderConnectionErrorHandler( 178 connection1_->SetRemoteServiceProviderConnectionErrorHandler(
177 base::Bind(&TestApplication::ConnectionClosed, 179 base::Bind(&TestApplication::ConnectionClosed,
178 base::Unretained(this), "test:service")); 180 base::Unretained(this), "test:service"));
179 181
180 connection2_ = app_->ConnectToApplication("test:service2"); 182 connection2_ = shell_->ConnectToApplication("test:service2");
181 connection2_->SetRemoteServiceProviderConnectionErrorHandler( 183 connection2_->SetRemoteServiceProviderConnectionErrorHandler(
182 base::Bind(&TestApplication::ConnectionClosed, 184 base::Bind(&TestApplication::ConnectionClosed,
183 base::Unretained(this), "test:service2")); 185 base::Unretained(this), "test:service2"));
184 return true; 186 return true;
185 } 187 }
186 188
187 void TestApplication::ConnectionClosed(const std::string& service_url) { 189 void TestApplication::ConnectionClosed(const std::string& service_url) {
188 validator_->ConnectionClosed(app_->url(), service_url); 190 validator_->ConnectionClosed(url_, service_url);
189 } 191 }
190 192
191 //////////////////////////////////////////////////////////////////////////////// 193 ////////////////////////////////////////////////////////////////////////////////
192 // TestLoader: 194 // TestLoader:
193 195
194 TestLoader::TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 196 TestLoader::TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
195 TestLoader::~TestLoader() {} 197 TestLoader::~TestLoader() {}
196 198
197 void TestLoader::Load(const GURL& url, 199 void TestLoader::Load(const GURL& url,
198 InterfaceRequest<mojom::Application> request) { 200 InterfaceRequest<mojom::Application> request) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 void CapabilityFilterTest::RunTest() { 323 void CapabilityFilterTest::RunTest() {
322 loop()->Run(); 324 loop()->Run();
323 EXPECT_TRUE(validator_->expectations_met()); 325 EXPECT_TRUE(validator_->expectations_met());
324 if (!validator_->expectations_met()) 326 if (!validator_->expectations_met())
325 validator_->PrintUnmetExpectations(); 327 validator_->PrintUnmetExpectations();
326 } 328 }
327 329
328 } // namespace test 330 } // namespace test
329 } // namespace shell 331 } // namespace shell
330 } // namespace mojo 332 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/capability_filter_test.h ('k') | mojo/shell/fetcher/about_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698