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

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

Issue 1350023002: Revert of 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"
21 #include "mojo/shell/application_loader.h" 22 #include "mojo/shell/application_loader.h"
22 #include "mojo/shell/application_manager.h" 23 #include "mojo/shell/application_manager.h"
23 #include "mojo/shell/capability_filter_unittest.mojom.h" 24 #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 CFTestPackageManager : public TestPackageManager { 288 class TestApplicationFetcher : public ApplicationFetcher {
289 public: 289 public:
290 CFTestPackageManager() {} 290 TestApplicationFetcher() {}
291 ~CFTestPackageManager() override {} 291 ~TestApplicationFetcher() 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 TestPackageManager: 298 // Overridden from ApplicationFetcher:
299 void SetApplicationManager(ApplicationManager* manager) override {}
300 GURL ResolveURL(const GURL& url) override {
301 return url;
302 }
299 void FetchRequest(URLRequestPtr request, 303 void FetchRequest(URLRequestPtr request,
300 const Fetcher::FetchCallback& loader_callback) override { 304 const Fetcher::FetchCallback& loader_callback) override {
301 if (use_test_fetcher_) 305 if (use_test_fetcher_)
302 new TestFetcher(GURL(request->url), loader_callback); 306 new TestFetcher(GURL(request->url), loader_callback);
303 } 307 }
304 308
305 bool use_test_fetcher_; 309 bool use_test_fetcher_;
306 310
307 DISALLOW_COPY_AND_ASSIGN(CFTestPackageManager); 311 DISALLOW_COPY_AND_ASSIGN(TestApplicationFetcher);
308 }; 312 };
309 313
310 class TestLoader : public ApplicationLoader { 314 class TestLoader : public ApplicationLoader {
311 public: 315 public:
312 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 316 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
313 ~TestLoader() override {} 317 ~TestLoader() override {}
314 318
315 private: 319 private:
316 // Overridden from ApplicationLoader: 320 // Overridden from ApplicationLoader:
317 void Load(const GURL& url, InterfaceRequest<Application> request) override { 321 void Load(const GURL& url, InterfaceRequest<Application> request) override {
318 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass())); 322 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass()));
319 } 323 }
320 324
321 scoped_ptr<ApplicationDelegate> delegate_; 325 scoped_ptr<ApplicationDelegate> delegate_;
322 scoped_ptr<ApplicationImpl> app_; 326 scoped_ptr<ApplicationImpl> app_;
323 327
324 DISALLOW_COPY_AND_ASSIGN(TestLoader); 328 DISALLOW_COPY_AND_ASSIGN(TestLoader);
325 }; 329 };
326 330
327 class CapabilityFilterTest : public testing::Test { 331 class CapabilityFilterTest : public testing::Test {
328 public: 332 public:
329 CapabilityFilterTest() 333 CapabilityFilterTest()
330 : test_package_manager_(nullptr), 334 : test_application_fetcher_(nullptr),
331 validator_(nullptr) {} 335 validator_(nullptr) {}
332 ~CapabilityFilterTest() override {} 336 ~CapabilityFilterTest() override {}
333 337
334 protected: 338 protected:
335 void RunApplication(const std::string& url, const CapabilityFilter& filter) { 339 void RunApplication(const std::string& url, const CapabilityFilter& filter) {
336 ServiceProviderPtr services; 340 ServiceProviderPtr services;
337 341
338 // We expose Validator to the test application via ConnectToApplication 342 // We expose Validator to the test application via ConnectToApplication
339 // because we don't allow the test application to connect to test:validator. 343 // because we don't allow the test application to connect to test:validator.
340 // Adding it to the CapabilityFilter would interfere with the test. 344 // Adding it to the CapabilityFilter would interfere with the test.
(...skipping 24 matching lines...) Expand all
365 loop()->Run(); 369 loop()->Run();
366 EXPECT_TRUE(validator_->expectations_met()); 370 EXPECT_TRUE(validator_->expectations_met());
367 if (!validator_->expectations_met()) 371 if (!validator_->expectations_met())
368 validator_->PrintUnmetExpectations(); 372 validator_->PrintUnmetExpectations();
369 } 373 }
370 374
371 void RunContentHandlerTest() { 375 void RunContentHandlerTest() {
372 set_use_test_fetcher(); 376 set_use_test_fetcher();
373 377
374 GURL content_handler_url("test:content_handler"); 378 GURL content_handler_url("test:content_handler");
375 test_package_manager_->RegisterContentHandler(kTestMimeType, 379 application_manager()->RegisterContentHandler(kTestMimeType,
376 content_handler_url); 380 content_handler_url);
377 381
378 CreateLoader<TestContentHandler>(content_handler_url.spec()); 382 CreateLoader<TestContentHandler>(content_handler_url.spec());
379 RunTest(); 383 RunTest();
380 } 384 }
381 385
382 base::MessageLoop* loop() { return &loop_; } 386 base::MessageLoop* loop() { return &loop_; }
383 ApplicationManager* application_manager() { 387 ApplicationManager* application_manager() {
384 return application_manager_.get(); 388 return application_manager_.get();
385 } 389 }
386 ConnectionValidator* validator() { return validator_; } 390 ConnectionValidator* validator() { return validator_; }
387 void set_use_test_fetcher() { 391 void set_use_test_fetcher() {
388 test_package_manager_->set_use_test_fetcher(true); 392 test_application_fetcher_->set_use_test_fetcher(true);
389 } 393 }
390 394
391 // Overridden from testing::Test: 395 // Overridden from testing::Test:
392 void SetUp() override { 396 void SetUp() override {
393 test_package_manager_ = new CFTestPackageManager; 397 test_application_fetcher_ = new TestApplicationFetcher;
394 application_manager_.reset( 398 application_manager_.reset(
395 new ApplicationManager(make_scoped_ptr(test_package_manager_))); 399 new ApplicationManager(make_scoped_ptr(test_application_fetcher_)));
396 CreateLoader<ServiceApplication>("test:service"); 400 CreateLoader<ServiceApplication>("test:service");
397 CreateLoader<ServiceApplication>("test:service2"); 401 CreateLoader<ServiceApplication>("test:service2");
398 } 402 }
399 void TearDown() override { 403 void TearDown() override {
400 application_manager_.reset(); 404 application_manager_.reset();
401 test_package_manager_->set_use_test_fetcher(false); 405 test_application_fetcher_->set_use_test_fetcher(false);
402 } 406 }
403 407
404 private: 408 private:
405 template<class T> 409 template<class T>
406 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() { 410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() {
407 return scoped_ptr<ApplicationDelegate>(new T); 411 return scoped_ptr<ApplicationDelegate>(new T);
408 } 412 }
409 413
410 CFTestPackageManager* test_package_manager_; 414 TestApplicationFetcher* test_application_fetcher_;
411 base::ShadowingAtExitManager at_exit_; 415 base::ShadowingAtExitManager at_exit_;
412 base::MessageLoop loop_; 416 base::MessageLoop loop_;
413 scoped_ptr<ApplicationManager> application_manager_; 417 scoped_ptr<ApplicationManager> application_manager_;
414 ConnectionValidator* validator_; 418 ConnectionValidator* validator_;
415 419
416 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); 420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest);
417 }; 421 };
418 422
419 class CapabilityFilter_BlockingTest : public CapabilityFilterTest { 423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest {
420 public: 424 public:
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 RunTest(); 545 RunTest();
542 } 546 }
543 547
544 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { 548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) {
545 RunContentHandlerTest(); 549 RunContentHandlerTest();
546 } 550 }
547 551
548 } // namespace 552 } // namespace
549 } // namespace shell 553 } // namespace shell
550 } // namespace mojo 554 } // 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