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

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

Issue 1343823002: Revert of Move fetching logic out of ApplicationManager, eliminate url mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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/application_manager_unittest.cc ('k') | mojo/shell/local_fetcher.h » ('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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "mojo/application/public/cpp/application_connection.h" 12 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/application/public/cpp/application_delegate.h" 13 #include "mojo/application/public/cpp/application_delegate.h"
14 #include "mojo/application/public/cpp/application_impl.h" 14 #include "mojo/application/public/cpp/application_impl.h"
15 #include "mojo/application/public/cpp/connect.h" 15 #include "mojo/application/public/cpp/connect.h"
16 #include "mojo/application/public/cpp/interface_factory.h" 16 #include "mojo/application/public/cpp/interface_factory.h"
17 #include "mojo/application/public/cpp/service_provider_impl.h" 17 #include "mojo/application/public/cpp/service_provider_impl.h"
18 #include "mojo/application/public/interfaces/content_handler.mojom.h" 18 #include "mojo/application/public/interfaces/content_handler.mojom.h"
19 #include "mojo/common/weak_binding_set.h" 19 #include "mojo/common/weak_binding_set.h"
20 #include "mojo/public/cpp/bindings/strong_binding.h" 20 #include "mojo/public/cpp/bindings/strong_binding.h"
21 #include "mojo/shell/application_fetcher.h"
22 #include "mojo/shell/application_loader.h" 21 #include "mojo/shell/application_loader.h"
23 #include "mojo/shell/application_manager.h" 22 #include "mojo/shell/application_manager.h"
24 #include "mojo/shell/capability_filter_unittest.mojom.h" 23 #include "mojo/shell/capability_filter_unittest.mojom.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
26 25
27 namespace mojo { 26 namespace mojo {
28 namespace shell { 27 namespace shell {
29 namespace { 28 namespace {
30 29
31 const char kTestMimeType[] = "test/mime-type"; 30 const char kTestMimeType[] = "test/mime-type";
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::Callback<void(const base::FilePath&, bool)> callback) override {} 277 base::Callback<void(const base::FilePath&, bool)> callback) override {}
279 std::string MimeType() override { return kTestMimeType; } 278 std::string MimeType() override { return kTestMimeType; }
280 bool HasMojoMagic() override { return false; } 279 bool HasMojoMagic() override { return false; }
281 bool PeekFirstLine(std::string* line) override { return false; } 280 bool PeekFirstLine(std::string* line) override { return false; }
282 281
283 const GURL url_; 282 const GURL url_;
284 283
285 DISALLOW_COPY_AND_ASSIGN(TestFetcher); 284 DISALLOW_COPY_AND_ASSIGN(TestFetcher);
286 }; 285 };
287 286
288 class TestApplicationFetcher : public ApplicationFetcher { 287 class TestApplicationManagerDelegate : public ApplicationManager::Delegate {
289 public: 288 public:
290 TestApplicationFetcher() {} 289 TestApplicationManagerDelegate() {}
291 ~TestApplicationFetcher() override {} 290 ~TestApplicationManagerDelegate() override {}
292 291
293 void set_use_test_fetcher(bool use_test_fetcher) { 292 void set_use_test_fetcher(bool use_test_fetcher) {
294 use_test_fetcher_ = use_test_fetcher; 293 use_test_fetcher_ = use_test_fetcher;
295 } 294 }
296 295
297 private: 296 private:
298 // Overridden from ApplicationFetcher: 297 // Overridden from ApplicationManager::Delegate:
299 void SetApplicationManager(ApplicationManager* manager) override {} 298 GURL ResolveMappings(const GURL& url) override {
300 GURL ResolveURL(const GURL& url) override {
301 return url; 299 return url;
302 } 300 }
303 void FetchRequest(URLRequestPtr request, 301 GURL ResolveMojoURL(const GURL& url) override {
304 const Fetcher::FetchCallback& loader_callback) override { 302 return url;
305 if (use_test_fetcher_) 303 }
306 new TestFetcher(GURL(request->url), loader_callback); 304 bool CreateFetcher(const GURL& url,
305 const Fetcher::FetchCallback& loader_callback) override {
306 if (use_test_fetcher_) {
307 new TestFetcher(url, loader_callback);
308 return true;
309 }
310 return false;
307 } 311 }
308 312
309 bool use_test_fetcher_; 313 bool use_test_fetcher_;
310 314
311 DISALLOW_COPY_AND_ASSIGN(TestApplicationFetcher); 315 DISALLOW_COPY_AND_ASSIGN(TestApplicationManagerDelegate);
312 }; 316 };
313 317
314 class TestLoader : public ApplicationLoader { 318 class TestLoader : public ApplicationLoader {
315 public: 319 public:
316 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 320 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
317 ~TestLoader() override {} 321 ~TestLoader() override {}
318 322
319 private: 323 private:
320 // Overridden from ApplicationLoader: 324 // Overridden from ApplicationLoader:
321 void Load(const GURL& url, InterfaceRequest<Application> request) override { 325 void Load(const GURL& url, InterfaceRequest<Application> request) override {
322 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass())); 326 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass()));
323 } 327 }
324 328
325 scoped_ptr<ApplicationDelegate> delegate_; 329 scoped_ptr<ApplicationDelegate> delegate_;
326 scoped_ptr<ApplicationImpl> app_; 330 scoped_ptr<ApplicationImpl> app_;
327 331
328 DISALLOW_COPY_AND_ASSIGN(TestLoader); 332 DISALLOW_COPY_AND_ASSIGN(TestLoader);
329 }; 333 };
330 334
331 class CapabilityFilterTest : public testing::Test { 335 class CapabilityFilterTest : public testing::Test {
332 public: 336 public:
333 CapabilityFilterTest() 337 CapabilityFilterTest() : validator_(nullptr) {}
334 : test_application_fetcher_(nullptr),
335 validator_(nullptr) {}
336 ~CapabilityFilterTest() override {} 338 ~CapabilityFilterTest() override {}
337 339
338 protected: 340 protected:
339 void RunApplication(const std::string& url, const CapabilityFilter& filter) { 341 void RunApplication(const std::string& url, const CapabilityFilter& filter) {
340 ServiceProviderPtr services; 342 ServiceProviderPtr services;
341 343
342 // We expose Validator to the test application via ConnectToApplication 344 // We expose Validator to the test application via ConnectToApplication
343 // because we don't allow the test application to connect to test:validator. 345 // because we don't allow the test application to connect to test:validator.
344 // Adding it to the CapabilityFilter would interfere with the test. 346 // Adding it to the CapabilityFilter would interfere with the test.
345 ServiceProviderPtr exposed_services; 347 ServiceProviderPtr exposed_services;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 CreateLoader<TestContentHandler>(content_handler_url.spec()); 384 CreateLoader<TestContentHandler>(content_handler_url.spec());
383 RunTest(); 385 RunTest();
384 } 386 }
385 387
386 base::MessageLoop* loop() { return &loop_; } 388 base::MessageLoop* loop() { return &loop_; }
387 ApplicationManager* application_manager() { 389 ApplicationManager* application_manager() {
388 return application_manager_.get(); 390 return application_manager_.get();
389 } 391 }
390 ConnectionValidator* validator() { return validator_; } 392 ConnectionValidator* validator() { return validator_; }
391 void set_use_test_fetcher() { 393 void set_use_test_fetcher() {
392 test_application_fetcher_->set_use_test_fetcher(true); 394 test_delegate_.set_use_test_fetcher(true);
393 } 395 }
394 396
395 // Overridden from testing::Test: 397 // Overridden from testing::Test:
396 void SetUp() override { 398 void SetUp() override {
397 test_application_fetcher_ = new TestApplicationFetcher; 399 application_manager_.reset(new ApplicationManager(&test_delegate_));
398 application_manager_.reset(
399 new ApplicationManager(make_scoped_ptr(test_application_fetcher_)));
400 CreateLoader<ServiceApplication>("test:service"); 400 CreateLoader<ServiceApplication>("test:service");
401 CreateLoader<ServiceApplication>("test:service2"); 401 CreateLoader<ServiceApplication>("test:service2");
402 } 402 }
403 void TearDown() override { 403 void TearDown() override {
404 application_manager_.reset(); 404 application_manager_.reset();
405 test_application_fetcher_->set_use_test_fetcher(false); 405 test_delegate_.set_use_test_fetcher(false);
406 } 406 }
407 407
408 private: 408 private:
409 template<class T> 409 template<class T>
410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() { 410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() {
411 return scoped_ptr<ApplicationDelegate>(new T); 411 return scoped_ptr<ApplicationDelegate>(new T);
412 } 412 }
413 413
414 TestApplicationFetcher* test_application_fetcher_;
415 base::ShadowingAtExitManager at_exit_; 414 base::ShadowingAtExitManager at_exit_;
415 TestApplicationManagerDelegate test_delegate_;
416 base::MessageLoop loop_; 416 base::MessageLoop loop_;
417 scoped_ptr<ApplicationManager> application_manager_; 417 scoped_ptr<ApplicationManager> application_manager_;
418 ConnectionValidator* validator_; 418 ConnectionValidator* validator_;
419 419
420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); 420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest);
421 }; 421 };
422 422
423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest { 423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest {
424 public: 424 public:
425 CapabilityFilter_BlockingTest() {} 425 CapabilityFilter_BlockingTest() {}
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 RunTest(); 545 RunTest();
546 } 546 }
547 547
548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { 548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) {
549 RunContentHandlerTest(); 549 RunContentHandlerTest();
550 } 550 }
551 551
552 } // namespace 552 } // namespace
553 } // namespace shell 553 } // namespace shell
554 } // namespace mojo 554 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager_unittest.cc ('k') | mojo/shell/local_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698