| 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/fetcher/about_fetcher.h" | 5 #include "mojo/shell/fetcher/about_fetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "mojo/common/weak_binding_set.h" | 17 #include "mojo/common/weak_binding_set.h" |
| 18 #include "mojo/shell/application_loader.h" | 18 #include "mojo/shell/application_loader.h" |
| 19 #include "mojo/shell/application_manager.h" | 19 #include "mojo/shell/application_manager.h" |
| 20 #include "mojo/shell/package_manager/package_manager_impl.h" | 20 #include "mojo/shell/package_manager/package_manager_impl.h" |
| 21 #include "mojo/shell/public/cpp/application_connection.h" | |
| 22 #include "mojo/shell/public/cpp/application_delegate.h" | |
| 23 #include "mojo/shell/public/cpp/application_impl.h" | 21 #include "mojo/shell/public/cpp/application_impl.h" |
| 24 #include "mojo/shell/public/cpp/interface_factory.h" | 22 #include "mojo/shell/public/cpp/interface_factory.h" |
| 23 #include "mojo/shell/public/cpp/shell_client.h" |
| 25 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | 24 #include "mojo/shell/public/interfaces/content_handler.mojom.h" |
| 26 #include "mojo/util/filename_util.h" | 25 #include "mojo/util/filename_util.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 27 |
| 29 namespace mojo { | 28 namespace mojo { |
| 30 namespace shell { | 29 namespace shell { |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 class TestContentHandler : public ApplicationDelegate, | 32 class TestContentHandler : public ShellClient, |
| 34 public InterfaceFactory<mojom::ContentHandler>, | 33 public InterfaceFactory<mojom::ContentHandler>, |
| 35 public mojom::ContentHandler { | 34 public mojom::ContentHandler { |
| 36 public: | 35 public: |
| 37 TestContentHandler() : response_number_(0) {} | 36 TestContentHandler() : response_number_(0) {} |
| 38 ~TestContentHandler() override {} | 37 ~TestContentHandler() override {} |
| 39 | 38 |
| 40 size_t response_number() const { return response_number_; } | 39 size_t response_number() const { return response_number_; } |
| 41 const URLResponse* latest_response() const { return latest_response_.get(); } | 40 const URLResponse* latest_response() const { return latest_response_.get(); } |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 // Overridden from ApplicationDelegate: | 43 // Overridden from ShellClient: |
| 45 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} | 44 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} |
| 46 bool AcceptConnection(ApplicationConnection* connection) override { | 45 bool AcceptConnection(Connection* connection) override { |
| 47 connection->AddService<mojom::ContentHandler>(this); | 46 connection->AddService<mojom::ContentHandler>(this); |
| 48 return true; | 47 return true; |
| 49 } | 48 } |
| 50 | 49 |
| 51 // Overridden from InterfaceFactory<mojom::ContentHandler>: | 50 // Overridden from InterfaceFactory<mojom::ContentHandler>: |
| 52 void Create(ApplicationConnection* connection, | 51 void Create(Connection* connection, |
| 53 InterfaceRequest<mojom::ContentHandler> request) override { | 52 InterfaceRequest<mojom::ContentHandler> request) override { |
| 54 bindings_.AddBinding(this, std::move(request)); | 53 bindings_.AddBinding(this, std::move(request)); |
| 55 } | 54 } |
| 56 | 55 |
| 57 // Overridden from mojom::ContentHandler: | 56 // Overridden from mojom::ContentHandler: |
| 58 void StartApplication( | 57 void StartApplication( |
| 59 InterfaceRequest<mojom::Application> application, | 58 InterfaceRequest<mojom::Application> application, |
| 60 URLResponsePtr response, | 59 URLResponsePtr response, |
| 61 const Callback<void()>& destruct_callback) override { | 60 const Callback<void()>& destruct_callback) override { |
| 62 response_number_++; | 61 response_number_++; |
| 63 latest_response_ = std::move(response); | 62 latest_response_ = std::move(response); |
| 64 destruct_callback.Run(); | 63 destruct_callback.Run(); |
| 65 | 64 |
| 66 // Drop |application| request. This results in the application manager | 65 // Drop |application| request. This results in the application manager |
| 67 // dropping the ServiceProvider interface request provided by the client | 66 // dropping the ServiceProvider interface request provided by the client |
| 68 // who made the ConnectToApplication() call. Therefore the client could | 67 // who made the ConnectToApplication() call. Therefore the client could |
| 69 // listen for connection error of the ServiceProvider interface to learn | 68 // listen for connection error of the ServiceProvider interface to learn |
| 70 // that StartApplication() has been called. | 69 // that StartApplication() has been called. |
| 71 } | 70 } |
| 72 | 71 |
| 73 size_t response_number_; | 72 size_t response_number_; |
| 74 URLResponsePtr latest_response_; | 73 URLResponsePtr latest_response_; |
| 75 WeakBindingSet<mojom::ContentHandler> bindings_; | 74 WeakBindingSet<mojom::ContentHandler> bindings_; |
| 76 | 75 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); | 76 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 class TestLoader : public ApplicationLoader { | 79 class TestLoader : public ApplicationLoader { |
| 81 public: | 80 public: |
| 82 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} | 81 explicit TestLoader(ShellClient* delegate) : delegate_(delegate) {} |
| 83 ~TestLoader() override {} | 82 ~TestLoader() override {} |
| 84 | 83 |
| 85 private: | 84 private: |
| 86 // Overridden from ApplicationLoader: | 85 // Overridden from ApplicationLoader: |
| 87 void Load(const GURL& url, | 86 void Load(const GURL& url, |
| 88 InterfaceRequest<mojom::Application> request) override { | 87 InterfaceRequest<mojom::Application> request) override { |
| 89 app_.reset(new ApplicationImpl(delegate_, std::move(request))); | 88 app_.reset(new ApplicationImpl(delegate_, std::move(request))); |
| 90 } | 89 } |
| 91 | 90 |
| 92 ApplicationDelegate* delegate_; | 91 ShellClient* delegate_; |
| 93 scoped_ptr<ApplicationImpl> app_; | 92 scoped_ptr<ApplicationImpl> app_; |
| 94 | 93 |
| 95 DISALLOW_COPY_AND_ASSIGN(TestLoader); | 94 DISALLOW_COPY_AND_ASSIGN(TestLoader); |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 class AboutFetcherTest : public testing::Test { | 97 class AboutFetcherTest : public testing::Test { |
| 99 public: | 98 public: |
| 100 AboutFetcherTest() {} | 99 AboutFetcherTest() {} |
| 101 ~AboutFetcherTest() override {} | 100 ~AboutFetcherTest() override {} |
| 102 | 101 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const URLResponse* response = html_content_handler()->latest_response(); | 172 const URLResponse* response = html_content_handler()->latest_response(); |
| 174 EXPECT_EQ("about:some_unrecognized_url", response->url); | 173 EXPECT_EQ("about:some_unrecognized_url", response->url); |
| 175 EXPECT_EQ(404u, response->status_code); | 174 EXPECT_EQ(404u, response->status_code); |
| 176 EXPECT_EQ("text/html", response->mime_type); | 175 EXPECT_EQ("text/html", response->mime_type); |
| 177 EXPECT_FALSE(response->body.is_valid()); | 176 EXPECT_FALSE(response->body.is_valid()); |
| 178 } | 177 } |
| 179 | 178 |
| 180 } // namespace | 179 } // namespace |
| 181 } // namespace shell | 180 } // namespace shell |
| 182 } // namespace mojo | 181 } // namespace mojo |
| OLD | NEW |