| 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 "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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "mojo/common/weak_binding_set.h" | 12 #include "mojo/common/weak_binding_set.h" |
| 13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 14 #include "mojo/shell/application_loader.h" | 14 #include "mojo/shell/application_loader.h" |
| 15 #include "mojo/shell/package_manager.h" | 15 #include "mojo/shell/package_manager.h" |
| 16 #include "mojo/shell/public/cpp/application_impl.h" | |
| 17 #include "mojo/shell/public/cpp/connection.h" | 16 #include "mojo/shell/public/cpp/connection.h" |
| 18 #include "mojo/shell/public/cpp/interface_factory.h" | 17 #include "mojo/shell/public/cpp/interface_factory.h" |
| 18 #include "mojo/shell/public/cpp/shell_connection.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace shell { | 21 namespace shell { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 // Lives on the main thread of the test. | 24 // Lives on the main thread of the test. |
| 25 // Listens for services exposed/blocked and for application connections being | 25 // Listens for services exposed/blocked and for application connections being |
| 26 // closed. Quits |loop| when all expectations are met. | 26 // closed. Quits |loop| when all expectations are met. |
| 27 class ConnectionValidator : public ApplicationLoader, | 27 class ConnectionValidator : public ApplicationLoader, |
| 28 public ShellClient, | 28 public ShellClient, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 void PrintUnmetExpectations() { | 43 void PrintUnmetExpectations() { |
| 44 for (auto expectation : expectations_) | 44 for (auto expectation : expectations_) |
| 45 ADD_FAILURE() << "Unmet: " << expectation; | 45 ADD_FAILURE() << "Unmet: " << expectation; |
| 46 for (auto unexpected : unexpected_) | 46 for (auto unexpected : unexpected_) |
| 47 ADD_FAILURE() << "Unexpected: " << unexpected; | 47 ADD_FAILURE() << "Unexpected: " << unexpected; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Overridden from ApplicationLoader: | 51 // Overridden from ApplicationLoader: |
| 52 void Load(const GURL& url, | 52 void Load(const GURL& url, |
| 53 InterfaceRequest<mojom::Application> request) override { | 53 InterfaceRequest<mojom::ShellClient> request) override { |
| 54 app_.reset(new ApplicationImpl(this, std::move(request))); | 54 app_.reset(new ShellConnection(this, std::move(request))); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Overridden from ShellClient: | 57 // Overridden from ShellClient: |
| 58 bool AcceptConnection(Connection* connection) override { | 58 bool AcceptConnection(Connection* connection) override { |
| 59 connection->AddService<Validator>(this); | 59 connection->AddService<Validator>(this); |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Overridden from InterfaceFactory<Validator>: | 63 // Overridden from InterfaceFactory<Validator>: |
| 64 void Create(Connection* connection, | 64 void Create(Connection* connection, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 87 if (expectations_.empty()) | 87 if (expectations_.empty()) |
| 88 loop_->QuitWhenIdle(); | 88 loop_->QuitWhenIdle(); |
| 89 } else { | 89 } else { |
| 90 // This is a test failure, and will result in PrintUnexpectedExpecations() | 90 // This is a test failure, and will result in PrintUnexpectedExpecations() |
| 91 // being called. | 91 // being called. |
| 92 unexpected_.insert(result); | 92 unexpected_.insert(result); |
| 93 loop_->QuitWhenIdle(); | 93 loop_->QuitWhenIdle(); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_ptr<ApplicationImpl> app_; | 97 scoped_ptr<ShellConnection> app_; |
| 98 std::set<std::string> expectations_; | 98 std::set<std::string> expectations_; |
| 99 std::set<std::string> unexpected_; | 99 std::set<std::string> unexpected_; |
| 100 base::MessageLoop* loop_; | 100 base::MessageLoop* loop_; |
| 101 WeakBindingSet<Validator> validator_bindings_; | 101 WeakBindingSet<Validator> validator_bindings_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(ConnectionValidator); | 103 DISALLOW_COPY_AND_ASSIGN(ConnectionValidator); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // This class models a system service that exposes two interfaces, Safe and | 106 // This class models a system service that exposes two interfaces, Safe and |
| 107 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications. | 107 // Unsafe. The interface Unsafe is not to be exposed to untrusted applications. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 validator_->ConnectionClosed(url_, service_url); | 187 validator_->ConnectionClosed(url_, service_url); |
| 188 } | 188 } |
| 189 | 189 |
| 190 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
| 191 // TestLoader: | 191 // TestLoader: |
| 192 | 192 |
| 193 TestLoader::TestLoader(ShellClient* delegate) : delegate_(delegate) {} | 193 TestLoader::TestLoader(ShellClient* delegate) : delegate_(delegate) {} |
| 194 TestLoader::~TestLoader() {} | 194 TestLoader::~TestLoader() {} |
| 195 | 195 |
| 196 void TestLoader::Load(const GURL& url, | 196 void TestLoader::Load(const GURL& url, |
| 197 InterfaceRequest<mojom::Application> request) { | 197 InterfaceRequest<mojom::ShellClient> request) { |
| 198 app_.reset(new ApplicationImpl(delegate_.get(), std::move(request))); | 198 app_.reset(new ShellConnection(delegate_.get(), std::move(request))); |
| 199 } | 199 } |
| 200 | 200 |
| 201 //////////////////////////////////////////////////////////////////////////////// | 201 //////////////////////////////////////////////////////////////////////////////// |
| 202 // CapabilityFilterTest: | 202 // CapabilityFilterTest: |
| 203 | 203 |
| 204 CapabilityFilterTest::CapabilityFilterTest() : validator_(nullptr) {} | 204 CapabilityFilterTest::CapabilityFilterTest() : validator_(nullptr) {} |
| 205 CapabilityFilterTest::~CapabilityFilterTest() {} | 205 CapabilityFilterTest::~CapabilityFilterTest() {} |
| 206 | 206 |
| 207 void CapabilityFilterTest::RunBlockingTest() { | 207 void CapabilityFilterTest::RunBlockingTest() { |
| 208 std::set<std::string> expectations; | 208 std::set<std::string> expectations; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 void CapabilityFilterTest::RunTest() { | 344 void CapabilityFilterTest::RunTest() { |
| 345 loop()->Run(); | 345 loop()->Run(); |
| 346 EXPECT_TRUE(validator_->expectations_met()); | 346 EXPECT_TRUE(validator_->expectations_met()); |
| 347 if (!validator_->expectations_met()) | 347 if (!validator_->expectations_met()) |
| 348 validator_->PrintUnmetExpectations(); | 348 validator_->PrintUnmetExpectations(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 } // namespace test | 351 } // namespace test |
| 352 } // namespace shell | 352 } // namespace shell |
| 353 } // namespace mojo | 353 } // namespace mojo |
| OLD | NEW |