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

Side by Side Diff: mojo/fetcher/about_fetcher_unittest.cc

Issue 1342503003: Move fetching logic out of ApplicationManager, eliminate url mappings. (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/fetcher/about_fetcher.cc ('k') | mojo/fetcher/base_application_fetcher.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/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "mojo/application/public/cpp/application_connection.h" 11 #include "mojo/application/public/cpp/application_connection.h"
11 #include "mojo/application/public/cpp/application_delegate.h" 12 #include "mojo/application/public/cpp/application_delegate.h"
12 #include "mojo/application/public/cpp/application_impl.h" 13 #include "mojo/application/public/cpp/application_impl.h"
13 #include "mojo/application/public/cpp/interface_factory.h" 14 #include "mojo/application/public/cpp/interface_factory.h"
14 #include "mojo/application/public/interfaces/content_handler.mojom.h" 15 #include "mojo/application/public/interfaces/content_handler.mojom.h"
15 #include "mojo/common/weak_binding_set.h" 16 #include "mojo/common/weak_binding_set.h"
16 #include "mojo/runner/about_fetcher.h" 17 #include "mojo/fetcher/about_fetcher.h"
18 #include "mojo/fetcher/base_application_fetcher.h"
17 #include "mojo/runner/context.h" 19 #include "mojo/runner/context.h"
18 #include "mojo/shell/application_loader.h" 20 #include "mojo/shell/application_loader.h"
19 #include "mojo/shell/application_manager.h" 21 #include "mojo/shell/application_manager.h"
22 #include "mojo/util/filename_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
21 24
22 namespace mojo { 25 namespace mojo {
23 namespace runner { 26 namespace fetcher {
24 namespace { 27 namespace {
25 28
26 class TestContentHandler : public ApplicationDelegate, 29 class TestContentHandler : public ApplicationDelegate,
27 public InterfaceFactory<ContentHandler>, 30 public InterfaceFactory<ContentHandler>,
28 public ContentHandler { 31 public ContentHandler {
29 public: 32 public:
30 TestContentHandler() : response_number_(0) {} 33 TestContentHandler() : response_number_(0) {}
31 ~TestContentHandler() override {} 34 ~TestContentHandler() override {}
32 35
33 size_t response_number() const { return response_number_; } 36 size_t response_number() const { return response_number_; }
(...skipping 26 matching lines...) Expand all
60 // that StartApplication() has been called. 63 // that StartApplication() has been called.
61 } 64 }
62 65
63 size_t response_number_; 66 size_t response_number_;
64 URLResponsePtr latest_response_; 67 URLResponsePtr latest_response_;
65 WeakBindingSet<ContentHandler> bindings_; 68 WeakBindingSet<ContentHandler> bindings_;
66 69
67 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); 70 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
68 }; 71 };
69 72
70 class TestApplicationManagerDelegate
71 : public shell::ApplicationManager::Delegate {
72 public:
73 TestApplicationManagerDelegate() {}
74 ~TestApplicationManagerDelegate() override {}
75
76 private:
77 // Overridden from ApplicationManager::Delegate:
78 GURL ResolveMappings(const GURL& url) override { return url; }
79 GURL ResolveMojoURL(const GURL& url) override { return url; }
80 bool CreateFetcher(
81 const GURL& url,
82 const shell::Fetcher::FetchCallback& loader_callback) override {
83 if (url.SchemeIs(AboutFetcher::kAboutScheme)) {
84 AboutFetcher::Start(url, loader_callback);
85 return true;
86 }
87
88 return false;
89 }
90
91 DISALLOW_COPY_AND_ASSIGN(TestApplicationManagerDelegate);
92 };
93
94 class TestLoader : public shell::ApplicationLoader { 73 class TestLoader : public shell::ApplicationLoader {
95 public: 74 public:
96 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 75 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
97 ~TestLoader() override {} 76 ~TestLoader() override {}
98 77
99 private: 78 private:
100 // Overridden from ApplicationLoader: 79 // Overridden from ApplicationLoader:
101 void Load(const GURL& url, InterfaceRequest<Application> request) override { 80 void Load(const GURL& url, InterfaceRequest<Application> request) override {
102 app_.reset(new ApplicationImpl(delegate_, request.Pass())); 81 app_.reset(new ApplicationImpl(delegate_, request.Pass()));
103 } 82 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 application_manager_->ConnectToApplication( 115 application_manager_->ConnectToApplication(
137 nullptr, request.Pass(), std::string(), service_provider_request.Pass(), 116 nullptr, request.Pass(), std::string(), service_provider_request.Pass(),
138 nullptr, shell::CapabilityFilter(), base::Closure(), 117 nullptr, shell::CapabilityFilter(), base::Closure(),
139 shell::EmptyConnectCallback()); 118 shell::EmptyConnectCallback());
140 119
141 run_loop.Run(); 120 run_loop.Run();
142 } 121 }
143 122
144 // Overridden from testing::Test: 123 // Overridden from testing::Test:
145 void SetUp() override { 124 void SetUp() override {
146 Context::EnsureEmbedderIsInitialized(); 125 runner::Context::EnsureEmbedderIsInitialized();
147 application_manager_.reset(new shell::ApplicationManager(&test_delegate_)); 126 base::FilePath shell_dir;
127 PathService::Get(base::DIR_MODULE, &shell_dir);
128 application_manager_.reset(new shell::ApplicationManager(
129 make_scoped_ptr(new BaseApplicationFetcher(shell_dir))));
148 application_manager_->SetLoaderForURL( 130 application_manager_->SetLoaderForURL(
149 make_scoped_ptr(new TestLoader(&html_content_handler_)), 131 make_scoped_ptr(new TestLoader(&html_content_handler_)),
150 GURL("test:html_content_handler")); 132 GURL("test:html_content_handler"));
151 application_manager_->RegisterContentHandler( 133 application_manager_->RegisterContentHandler(
152 "text/html", GURL("test:html_content_handler")); 134 "text/html", GURL("test:html_content_handler"));
153 } 135 }
154 136
155 void TearDown() override { application_manager_.reset(); } 137 void TearDown() override { application_manager_.reset(); }
156 138
157 private: 139 private:
158 base::ShadowingAtExitManager at_exit_; 140 base::ShadowingAtExitManager at_exit_;
159 TestApplicationManagerDelegate test_delegate_;
160 TestContentHandler html_content_handler_; 141 TestContentHandler html_content_handler_;
161 base::MessageLoop loop_; 142 base::MessageLoop loop_;
162 scoped_ptr<shell::ApplicationManager> application_manager_; 143 scoped_ptr<shell::ApplicationManager> application_manager_;
163 144
164 DISALLOW_COPY_AND_ASSIGN(AboutFetcherTest); 145 DISALLOW_COPY_AND_ASSIGN(AboutFetcherTest);
165 }; 146 };
166 147
167 TEST_F(AboutFetcherTest, AboutBlank) { 148 TEST_F(AboutFetcherTest, AboutBlank) {
168 ConnectAndWait("about:blank"); 149 ConnectAndWait("about:blank");
169 150
170 ASSERT_EQ(1u, html_content_handler()->response_number()); 151 ASSERT_EQ(1u, html_content_handler()->response_number());
171 152
172 const URLResponse* response = html_content_handler()->latest_response(); 153 const URLResponse* response = html_content_handler()->latest_response();
173 EXPECT_EQ("about:blank", response->url); 154 EXPECT_EQ("about:blank", response->url);
174 EXPECT_EQ(200u, response->status_code); 155 EXPECT_EQ(200u, response->status_code);
175 EXPECT_EQ("text/html", response->mime_type); 156 EXPECT_EQ("text/html", response->mime_type);
176 EXPECT_FALSE(response->body.is_valid()); 157 EXPECT_FALSE(response->body.is_valid());
177 } 158 }
178 159
179 TEST_F(AboutFetcherTest, UnrecognizedURL) { 160 TEST_F(AboutFetcherTest, UnrecognizedURL) {
180 ConnectAndWait("about:some_unrecognized_url"); 161 ConnectAndWait("about:some_unrecognized_url");
181 162
182 ASSERT_EQ(0u, html_content_handler()->response_number()); 163 ASSERT_EQ(0u, html_content_handler()->response_number());
183 } 164 }
184 165
185 } // namespace 166 } // namespace
186 } // namespace runner 167 } // namespace fetcher
187 } // namespace mojo 168 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/about_fetcher.cc ('k') | mojo/fetcher/base_application_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698