OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/error_page/renderer/net_error_helper_core.h" | 5 #include "components/error_page/renderer/net_error_helper_core.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return ErrorToString(NetError(net_error), false); | 144 return ErrorToString(NetError(net_error), false); |
145 } | 145 } |
146 | 146 |
147 class NetErrorHelperCoreTest : public testing::Test, | 147 class NetErrorHelperCoreTest : public testing::Test, |
148 public NetErrorHelperCore::Delegate { | 148 public NetErrorHelperCore::Delegate { |
149 public: | 149 public: |
150 NetErrorHelperCoreTest() : timer_(NULL), | 150 NetErrorHelperCoreTest() : timer_(NULL), |
151 update_count_(0), | 151 update_count_(0), |
152 error_html_update_count_(0), | 152 error_html_update_count_(0), |
153 reload_count_(0), | 153 reload_count_(0), |
154 load_stale_count_(0), | 154 show_saved_count_(0), |
155 enable_page_helper_functions_count_(0), | 155 enable_page_helper_functions_count_(0), |
156 default_url_(GURL(kFailedUrl)), | 156 default_url_(GURL(kFailedUrl)), |
157 error_url_(GURL(content::kUnreachableWebDataURL)), | 157 error_url_(GURL(content::kUnreachableWebDataURL)), |
158 tracking_request_count_(0) { | 158 tracking_request_count_(0) { |
159 SetUpCore(false, false, true); | 159 SetUpCore(false, false, true); |
160 } | 160 } |
161 | 161 |
162 ~NetErrorHelperCoreTest() override { | 162 ~NetErrorHelperCoreTest() override { |
163 // No test finishes while an error page is being fetched. | 163 // No test finishes while an error page is being fetched. |
164 EXPECT_FALSE(is_url_being_fetched()); | 164 EXPECT_FALSE(is_url_being_fetched()); |
(...skipping 16 matching lines...) Expand all Loading... |
181 | 181 |
182 NetErrorHelperCore* core() { return core_.get(); } | 182 NetErrorHelperCore* core() { return core_.get(); } |
183 | 183 |
184 const GURL& url_being_fetched() const { return url_being_fetched_; } | 184 const GURL& url_being_fetched() const { return url_being_fetched_; } |
185 bool is_url_being_fetched() const { return !url_being_fetched_.is_empty(); } | 185 bool is_url_being_fetched() const { return !url_being_fetched_.is_empty(); } |
186 | 186 |
187 int reload_count() const { | 187 int reload_count() const { |
188 return reload_count_; | 188 return reload_count_; |
189 } | 189 } |
190 | 190 |
191 int load_stale_count() const { | 191 int show_saved_count() const { |
192 return load_stale_count_; | 192 return show_saved_count_; |
193 } | 193 } |
194 | 194 |
195 const GURL& load_stale_url() const { | 195 const GURL& show_saved_url() const { |
196 return load_stale_url_; | 196 return show_saved_url_; |
197 } | 197 } |
198 | 198 |
199 const GURL& default_url() const { | 199 const GURL& default_url() const { |
200 return default_url_; | 200 return default_url_; |
201 } | 201 } |
202 | 202 |
203 const GURL& error_url() const { | 203 const GURL& error_url() const { |
204 return error_url_; | 204 return error_url_; |
205 } | 205 } |
206 | 206 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 core()->OnSetNavigationCorrectionInfo(navigation_correction_url, | 291 core()->OnSetNavigationCorrectionInfo(navigation_correction_url, |
292 kLanguage, kCountry, kApiKey, | 292 kLanguage, kCountry, kApiKey, |
293 GURL(kSearchUrl)); | 293 GURL(kSearchUrl)); |
294 } | 294 } |
295 | 295 |
296 // NetErrorHelperCore::Delegate implementation: | 296 // NetErrorHelperCore::Delegate implementation: |
297 void GenerateLocalizedErrorPage(const WebURLError& error, | 297 void GenerateLocalizedErrorPage(const WebURLError& error, |
298 bool is_failed_post, | 298 bool is_failed_post, |
299 scoped_ptr<ErrorPageParams> params, | 299 scoped_ptr<ErrorPageParams> params, |
300 bool* reload_button_shown, | 300 bool* reload_button_shown, |
301 bool* load_stale_button_shown, | 301 bool* show_saved_copy_button_shown, |
302 std::string* html) const override { | 302 std::string* html) const override { |
303 last_error_page_params_.reset(params.release()); | 303 last_error_page_params_.reset(params.release()); |
304 *reload_button_shown = false; | 304 *reload_button_shown = false; |
305 *load_stale_button_shown = false; | 305 *show_saved_copy_button_shown = false; |
306 *html = ErrorToString(error, is_failed_post); | 306 *html = ErrorToString(error, is_failed_post); |
307 } | 307 } |
308 | 308 |
309 void LoadErrorPageInMainFrame(const std::string& html, | 309 void LoadErrorPageInMainFrame(const std::string& html, |
310 const GURL& failed_url) override { | 310 const GURL& failed_url) override { |
311 error_html_update_count_++; | 311 error_html_update_count_++; |
312 last_error_html_ = html; | 312 last_error_html_ = html; |
313 } | 313 } |
314 | 314 |
315 void EnablePageHelperFunctions() override { | 315 void EnablePageHelperFunctions() override { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 | 349 |
350 void CancelFetchNavigationCorrections() override { | 350 void CancelFetchNavigationCorrections() override { |
351 url_being_fetched_ = GURL(); | 351 url_being_fetched_ = GURL(); |
352 request_body_.clear(); | 352 request_body_.clear(); |
353 } | 353 } |
354 | 354 |
355 void ReloadPage() override { reload_count_++; } | 355 void ReloadPage() override { reload_count_++; } |
356 | 356 |
357 void LoadPageFromCache(const GURL& error_url) override { | 357 void LoadPageFromCache(const GURL& error_url) override { |
358 load_stale_count_++; | 358 show_saved_count_++; |
359 load_stale_url_ = error_url; | 359 show_saved_url_ = error_url; |
360 } | 360 } |
361 | 361 |
362 void SendTrackingRequest(const GURL& tracking_url, | 362 void SendTrackingRequest(const GURL& tracking_url, |
363 const std::string& tracking_request_body) override { | 363 const std::string& tracking_request_body) override { |
364 last_tracking_url_ = tracking_url; | 364 last_tracking_url_ = tracking_url; |
365 last_tracking_request_body_ = tracking_request_body; | 365 last_tracking_request_body_ = tracking_request_body; |
366 tracking_request_count_++; | 366 tracking_request_count_++; |
367 | 367 |
368 // Check the body of the request. | 368 // Check the body of the request. |
369 | 369 |
(...skipping 25 matching lines...) Expand all Loading... |
395 | 395 |
396 // Contains the HTML set by the last call to LoadErrorPageInMainFrame. | 396 // Contains the HTML set by the last call to LoadErrorPageInMainFrame. |
397 std::string last_error_html_; | 397 std::string last_error_html_; |
398 // Number of times |last_error_html_| has been changed. | 398 // Number of times |last_error_html_| has been changed. |
399 int error_html_update_count_; | 399 int error_html_update_count_; |
400 | 400 |
401 // Mutable because GenerateLocalizedErrorPage is const. | 401 // Mutable because GenerateLocalizedErrorPage is const. |
402 mutable scoped_ptr<ErrorPageParams> last_error_page_params_; | 402 mutable scoped_ptr<ErrorPageParams> last_error_page_params_; |
403 | 403 |
404 int reload_count_; | 404 int reload_count_; |
405 int load_stale_count_; | 405 int show_saved_count_; |
406 GURL load_stale_url_; | 406 GURL show_saved_url_; |
407 | 407 |
408 int enable_page_helper_functions_count_; | 408 int enable_page_helper_functions_count_; |
409 | 409 |
410 const GURL default_url_; | 410 const GURL default_url_; |
411 const GURL error_url_; | 411 const GURL error_url_; |
412 | 412 |
413 GURL last_tracking_url_; | 413 GURL last_tracking_url_; |
414 std::string last_tracking_request_body_; | 414 std::string last_tracking_request_body_; |
415 int tracking_request_count_; | 415 int tracking_request_count_; |
416 }; | 416 }; |
(...skipping 2020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 } | 2437 } |
2438 | 2438 |
2439 | 2439 |
2440 TEST_F(NetErrorHelperCoreTest, ExplicitReloadSucceeds) { | 2440 TEST_F(NetErrorHelperCoreTest, ExplicitReloadSucceeds) { |
2441 DoErrorLoad(net::ERR_CONNECTION_RESET); | 2441 DoErrorLoad(net::ERR_CONNECTION_RESET); |
2442 EXPECT_EQ(0, reload_count()); | 2442 EXPECT_EQ(0, reload_count()); |
2443 core()->ExecuteButtonPress(NetErrorHelperCore::RELOAD_BUTTON); | 2443 core()->ExecuteButtonPress(NetErrorHelperCore::RELOAD_BUTTON); |
2444 EXPECT_EQ(1, reload_count()); | 2444 EXPECT_EQ(1, reload_count()); |
2445 } | 2445 } |
2446 | 2446 |
2447 TEST_F(NetErrorHelperCoreTest, ExplicitLoadStaleSucceeds) { | 2447 TEST_F(NetErrorHelperCoreTest, ExplicitShowSavedSucceeds) { |
2448 DoErrorLoad(net::ERR_CONNECTION_RESET); | 2448 DoErrorLoad(net::ERR_CONNECTION_RESET); |
2449 EXPECT_EQ(0, load_stale_count()); | 2449 EXPECT_EQ(0, show_saved_count()); |
2450 core()->ExecuteButtonPress(NetErrorHelperCore::LOAD_STALE_BUTTON); | 2450 core()->ExecuteButtonPress(NetErrorHelperCore::SHOW_SAVED_COPY_BUTTON); |
2451 EXPECT_EQ(1, load_stale_count()); | 2451 EXPECT_EQ(1, show_saved_count()); |
2452 EXPECT_EQ(GURL(kFailedUrl), load_stale_url()); | 2452 EXPECT_EQ(GURL(kFailedUrl), show_saved_url()); |
2453 } | 2453 } |
2454 | 2454 |
2455 } // namespace | 2455 } // namespace |
2456 } // namespace error_page | 2456 } // namespace error_page |
OLD | NEW |