| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/at_exit.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/macros.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "mojo/shell/application_loader.h" | |
| 10 #include "mojo/shell/application_manager.h" | |
| 11 #include "mojo/shell/capability_filter_unittest.mojom.h" | |
| 12 #include "mojo/shell/public/cpp/shell_client.h" | |
| 13 #include "mojo/shell/public/cpp/shell_connection.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 namespace shell { | |
| 18 namespace test { | |
| 19 | |
| 20 class ConnectionValidator; | |
| 21 | |
| 22 // This class models an application who will use the shell to interact with a | |
| 23 // system service. The shell may limit this application's visibility of the full | |
| 24 // set of interfaces exposed by that service. | |
| 25 class TestApplication : public ShellClient { | |
| 26 public: | |
| 27 TestApplication(); | |
| 28 ~TestApplication() override; | |
| 29 | |
| 30 private: | |
| 31 // Overridden from ShellClient: | |
| 32 void Initialize(Shell* shell, const std::string& url, uint32_t id) override; | |
| 33 bool AcceptConnection(Connection* connection) override; | |
| 34 | |
| 35 void ConnectionClosed(const std::string& service_url); | |
| 36 | |
| 37 Shell* shell_; | |
| 38 std::string url_; | |
| 39 ValidatorPtr validator_; | |
| 40 scoped_ptr<Connection> connection1_; | |
| 41 scoped_ptr<Connection> connection2_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(TestApplication); | |
| 44 }; | |
| 45 | |
| 46 class TestLoader : public ApplicationLoader { | |
| 47 public: | |
| 48 explicit TestLoader(ShellClient* delegate); | |
| 49 ~TestLoader() override; | |
| 50 | |
| 51 private: | |
| 52 // Overridden from ApplicationLoader: | |
| 53 void Load(const GURL& url, | |
| 54 InterfaceRequest<mojom::ShellClient> request) override; | |
| 55 | |
| 56 scoped_ptr<ShellClient> delegate_; | |
| 57 scoped_ptr<ShellConnection> app_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(TestLoader); | |
| 60 }; | |
| 61 | |
| 62 class CapabilityFilterTest : public testing::Test { | |
| 63 public: | |
| 64 CapabilityFilterTest(); | |
| 65 ~CapabilityFilterTest() override; | |
| 66 | |
| 67 protected: | |
| 68 template <class T> | |
| 69 void CreateLoader(const std::string& url) { | |
| 70 application_manager_->SetLoaderForURL( | |
| 71 make_scoped_ptr(new TestLoader(new T)), GURL(url)); | |
| 72 } | |
| 73 | |
| 74 void RunBlockingTest(); | |
| 75 void RunWildcardTest(); | |
| 76 | |
| 77 // Overridden from testing::Test: | |
| 78 void SetUp() override; | |
| 79 void TearDown() override; | |
| 80 | |
| 81 base::MessageLoop* loop() { return &loop_; } | |
| 82 ApplicationManager* application_manager() { | |
| 83 return application_manager_.get(); | |
| 84 } | |
| 85 ConnectionValidator* validator() { return validator_; } | |
| 86 | |
| 87 private: | |
| 88 void RunApplication(const std::string& url, const CapabilityFilter& filter); | |
| 89 void InitValidator(const std::set<std::string>& expectations); | |
| 90 void RunTest(); | |
| 91 | |
| 92 template<class T> | |
| 93 scoped_ptr<ShellClient> CreateShellClient() { | |
| 94 return scoped_ptr<ShellClient>(new T); | |
| 95 } | |
| 96 | |
| 97 base::ShadowingAtExitManager at_exit_; | |
| 98 base::MessageLoop loop_; | |
| 99 scoped_ptr<ApplicationManager> application_manager_; | |
| 100 ConnectionValidator* validator_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); | |
| 103 }; | |
| 104 | |
| 105 } // namespace test | |
| 106 } // namespace shell | |
| 107 } // namespace mojo | |
| OLD | NEW |