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