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

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

Issue 1352663002: Extract some stuff into PackageManager (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/package_manager.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"
24 #include "mojo/shell/test_package_manager.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 namespace mojo { 27 namespace mojo {
28 namespace shell { 28 namespace shell {
29 namespace { 29 namespace {
30 30
31 const char kTestMimeType[] = "test/mime-type"; 31 const char kTestMimeType[] = "test/mime-type";
32 32
33 // Lives on the main thread of the test. 33 // Lives on the main thread of the test.
34 // Listens for services exposed/blocked and for application connections being 34 // Listens for services exposed/blocked and for application connections being
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::Callback<void(const base::FilePath&, bool)> callback) override {} 278 base::Callback<void(const base::FilePath&, bool)> callback) override {}
279 std::string MimeType() override { return kTestMimeType; } 279 std::string MimeType() override { return kTestMimeType; }
280 bool HasMojoMagic() override { return false; } 280 bool HasMojoMagic() override { return false; }
281 bool PeekFirstLine(std::string* line) override { return false; } 281 bool PeekFirstLine(std::string* line) override { return false; }
282 282
283 const GURL url_; 283 const GURL url_;
284 284
285 DISALLOW_COPY_AND_ASSIGN(TestFetcher); 285 DISALLOW_COPY_AND_ASSIGN(TestFetcher);
286 }; 286 };
287 287
288 class TestApplicationFetcher : public ApplicationFetcher { 288 class CFTestPackageManager : public TestPackageManager {
289 public: 289 public:
290 TestApplicationFetcher() {} 290 CFTestPackageManager() {}
291 ~TestApplicationFetcher() override {} 291 ~CFTestPackageManager() override {}
292 292
293 void set_use_test_fetcher(bool use_test_fetcher) { 293 void set_use_test_fetcher(bool use_test_fetcher) {
294 use_test_fetcher_ = use_test_fetcher; 294 use_test_fetcher_ = use_test_fetcher;
295 } 295 }
296 296
297 private: 297 private:
298 // Overridden from ApplicationFetcher: 298 // Overridden from TestPackageManager:
299 void SetApplicationManager(ApplicationManager* manager) override {}
300 GURL ResolveURL(const GURL& url) override {
301 return url;
302 }
303 void FetchRequest(URLRequestPtr request, 299 void FetchRequest(URLRequestPtr request,
304 const Fetcher::FetchCallback& loader_callback) override { 300 const Fetcher::FetchCallback& loader_callback) override {
305 if (use_test_fetcher_) 301 if (use_test_fetcher_)
306 new TestFetcher(GURL(request->url), loader_callback); 302 new TestFetcher(GURL(request->url), loader_callback);
307 } 303 }
308 304
309 bool use_test_fetcher_; 305 bool use_test_fetcher_;
310 306
311 DISALLOW_COPY_AND_ASSIGN(TestApplicationFetcher); 307 DISALLOW_COPY_AND_ASSIGN(CFTestPackageManager);
312 }; 308 };
313 309
314 class TestLoader : public ApplicationLoader { 310 class TestLoader : public ApplicationLoader {
315 public: 311 public:
316 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 312 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
317 ~TestLoader() override {} 313 ~TestLoader() override {}
318 314
319 private: 315 private:
320 // Overridden from ApplicationLoader: 316 // Overridden from ApplicationLoader:
321 void Load(const GURL& url, InterfaceRequest<Application> request) override { 317 void Load(const GURL& url, InterfaceRequest<Application> request) override {
322 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass())); 318 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass()));
323 } 319 }
324 320
325 scoped_ptr<ApplicationDelegate> delegate_; 321 scoped_ptr<ApplicationDelegate> delegate_;
326 scoped_ptr<ApplicationImpl> app_; 322 scoped_ptr<ApplicationImpl> app_;
327 323
328 DISALLOW_COPY_AND_ASSIGN(TestLoader); 324 DISALLOW_COPY_AND_ASSIGN(TestLoader);
329 }; 325 };
330 326
331 class CapabilityFilterTest : public testing::Test { 327 class CapabilityFilterTest : public testing::Test {
332 public: 328 public:
333 CapabilityFilterTest() 329 CapabilityFilterTest()
334 : test_application_fetcher_(nullptr), 330 : test_package_manager_(nullptr),
335 validator_(nullptr) {} 331 validator_(nullptr) {}
336 ~CapabilityFilterTest() override {} 332 ~CapabilityFilterTest() override {}
337 333
338 protected: 334 protected:
339 void RunApplication(const std::string& url, const CapabilityFilter& filter) { 335 void RunApplication(const std::string& url, const CapabilityFilter& filter) {
340 ServiceProviderPtr services; 336 ServiceProviderPtr services;
341 337
342 // We expose Validator to the test application via ConnectToApplication 338 // We expose Validator to the test application via ConnectToApplication
343 // because we don't allow the test application to connect to test:validator. 339 // because we don't allow the test application to connect to test:validator.
344 // Adding it to the CapabilityFilter would interfere with the test. 340 // Adding it to the CapabilityFilter would interfere with the test.
(...skipping 24 matching lines...) Expand all
369 loop()->Run(); 365 loop()->Run();
370 EXPECT_TRUE(validator_->expectations_met()); 366 EXPECT_TRUE(validator_->expectations_met());
371 if (!validator_->expectations_met()) 367 if (!validator_->expectations_met())
372 validator_->PrintUnmetExpectations(); 368 validator_->PrintUnmetExpectations();
373 } 369 }
374 370
375 void RunContentHandlerTest() { 371 void RunContentHandlerTest() {
376 set_use_test_fetcher(); 372 set_use_test_fetcher();
377 373
378 GURL content_handler_url("test:content_handler"); 374 GURL content_handler_url("test:content_handler");
379 application_manager()->RegisterContentHandler(kTestMimeType, 375 test_package_manager_->RegisterContentHandler(kTestMimeType,
380 content_handler_url); 376 content_handler_url);
381 377
382 CreateLoader<TestContentHandler>(content_handler_url.spec()); 378 CreateLoader<TestContentHandler>(content_handler_url.spec());
383 RunTest(); 379 RunTest();
384 } 380 }
385 381
386 base::MessageLoop* loop() { return &loop_; } 382 base::MessageLoop* loop() { return &loop_; }
387 ApplicationManager* application_manager() { 383 ApplicationManager* application_manager() {
388 return application_manager_.get(); 384 return application_manager_.get();
389 } 385 }
390 ConnectionValidator* validator() { return validator_; } 386 ConnectionValidator* validator() { return validator_; }
391 void set_use_test_fetcher() { 387 void set_use_test_fetcher() {
392 test_application_fetcher_->set_use_test_fetcher(true); 388 test_package_manager_->set_use_test_fetcher(true);
393 } 389 }
394 390
395 // Overridden from testing::Test: 391 // Overridden from testing::Test:
396 void SetUp() override { 392 void SetUp() override {
397 test_application_fetcher_ = new TestApplicationFetcher; 393 test_package_manager_ = new CFTestPackageManager;
398 application_manager_.reset( 394 application_manager_.reset(
399 new ApplicationManager(make_scoped_ptr(test_application_fetcher_))); 395 new ApplicationManager(make_scoped_ptr(test_package_manager_)));
400 CreateLoader<ServiceApplication>("test:service"); 396 CreateLoader<ServiceApplication>("test:service");
401 CreateLoader<ServiceApplication>("test:service2"); 397 CreateLoader<ServiceApplication>("test:service2");
402 } 398 }
403 void TearDown() override { 399 void TearDown() override {
404 application_manager_.reset(); 400 application_manager_.reset();
405 test_application_fetcher_->set_use_test_fetcher(false); 401 test_package_manager_->set_use_test_fetcher(false);
406 } 402 }
407 403
408 private: 404 private:
409 template<class T> 405 template<class T>
410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() { 406 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() {
411 return scoped_ptr<ApplicationDelegate>(new T); 407 return scoped_ptr<ApplicationDelegate>(new T);
412 } 408 }
413 409
414 TestApplicationFetcher* test_application_fetcher_; 410 CFTestPackageManager* test_package_manager_;
415 base::ShadowingAtExitManager at_exit_; 411 base::ShadowingAtExitManager at_exit_;
416 base::MessageLoop loop_; 412 base::MessageLoop loop_;
417 scoped_ptr<ApplicationManager> application_manager_; 413 scoped_ptr<ApplicationManager> application_manager_;
418 ConnectionValidator* validator_; 414 ConnectionValidator* validator_;
419 415
420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); 416 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest);
421 }; 417 };
422 418
423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest { 419 class CapabilityFilter_BlockingTest : public CapabilityFilterTest {
424 public: 420 public:
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 RunTest(); 541 RunTest();
546 } 542 }
547 543
548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { 544 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) {
549 RunContentHandlerTest(); 545 RunContentHandlerTest();
550 } 546 }
551 547
552 } // namespace 548 } // namespace
553 } // namespace shell 549 } // namespace shell
554 } // namespace mojo 550 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager_unittest.cc ('k') | mojo/shell/package_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698