| Index: chrome/renderer/net/net_error_helper_core_unittest.cc
|
| diff --git a/chrome/renderer/net/net_error_helper_core_unittest.cc b/chrome/renderer/net/net_error_helper_core_unittest.cc
|
| index bd451d6d876d34ac999d08f39c6e166ec80c5704..e7a8d820810bff44dcefb01cfe6241487f3e48f3 100644
|
| --- a/chrome/renderer/net/net_error_helper_core_unittest.cc
|
| +++ b/chrome/renderer/net/net_error_helper_core_unittest.cc
|
| @@ -64,12 +64,44 @@ std::string NetErrorString(net::Error net_error) {
|
| return ErrorToString(NetError(net_error), false);
|
| }
|
|
|
| +class MockOneShotTimer : public NetErrorHelperCore::MockableOneShotTimer {
|
| + public:
|
| + MockOneShotTimer() {}
|
| + virtual ~MockOneShotTimer() {}
|
| +
|
| + virtual void Start(const tracked_objects::Location& posted_from,
|
| + base::TimeDelta delay,
|
| + const base::Closure& user_task) {
|
| + user_task_ = user_task;
|
| + running_ = true;
|
| + delay_ = delay;
|
| + }
|
| +
|
| + virtual void Stop() {
|
| + running_ = false;
|
| + }
|
| +
|
| + virtual bool IsRunning() const {
|
| + return running_;
|
| + }
|
| +
|
| + virtual void Fire() {
|
| + running_ = false;
|
| + user_task_.Run();
|
| + }
|
| +
|
| + base::TimeDelta delay_;
|
| + base::Closure user_task_;
|
| + bool running_;
|
| +};
|
| +
|
| class NetErrorHelperCoreTest : public testing::Test,
|
| public NetErrorHelperCore::Delegate {
|
| public:
|
| NetErrorHelperCoreTest() : core_(this),
|
| update_count_(0),
|
| - error_html_update_count_(0) {
|
| + error_html_update_count_(0),
|
| + last_one_shot_timer_(NULL) {
|
| }
|
|
|
| virtual ~NetErrorHelperCoreTest() {
|
| @@ -82,12 +114,21 @@ class NetErrorHelperCoreTest : public testing::Test,
|
| const GURL& url_being_fetched() const { return url_being_fetched_; }
|
| bool is_url_being_fetched() const { return !url_being_fetched_.is_empty(); }
|
|
|
| + const GURL& url_being_auto_reloaded() const {
|
| + return url_being_auto_reloaded_;
|
| + }
|
| + bool is_url_being_auto_reloaded() const {
|
| + return !url_being_auto_reloaded_.is_empty();
|
| + }
|
| +
|
| const std::string& last_update_string() const { return last_update_string_; }
|
| int update_count() const { return update_count_; }
|
|
|
| const std::string& last_error_html() const { return last_error_html_; }
|
| int error_html_update_count() const { return error_html_update_count_; }
|
|
|
| + MockOneShotTimer* last_one_shot_timer() { return last_one_shot_timer_; }
|
| +
|
| void LinkDoctorLoadSuccess() {
|
| LinkDoctorLoadFinished(kLinkDoctorBody);
|
| }
|
| @@ -96,6 +137,29 @@ class NetErrorHelperCoreTest : public testing::Test,
|
| LinkDoctorLoadFinished("");
|
| }
|
|
|
| + protected:
|
| + void ErrorLoad(net::Error error) {
|
| + core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
|
| + NetErrorHelperCore::NON_ERROR_PAGE);
|
| + std::string html;
|
| + core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
|
| + NetError(error), false, &html);
|
| + EXPECT_FALSE(html.empty());
|
| + EXPECT_EQ(NetErrorString(error), html);
|
| +
|
| + core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
|
| + NetErrorHelperCore::ERROR_PAGE);
|
| + core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
|
| + core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
|
| + }
|
| +
|
| + void SuccessLoad() {
|
| + core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
|
| + NetErrorHelperCore::NON_ERROR_PAGE);
|
| + core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
|
| + core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
|
| + }
|
| +
|
| private:
|
| void LinkDoctorLoadFinished(const std::string& result) {
|
| url_being_fetched_ = GURL();
|
| @@ -133,9 +197,23 @@ class NetErrorHelperCoreTest : public testing::Test,
|
| url_being_fetched_ = GURL();
|
| }
|
|
|
| + virtual void FetchAutoReloadPage(const GURL& url) OVERRIDE {
|
| + url_being_auto_reloaded_ = url;
|
| + }
|
| +
|
| + virtual void CancelFetchAutoReloadPage() OVERRIDE {
|
| + url_being_auto_reloaded_ = GURL();
|
| + }
|
| +
|
| + virtual NetErrorHelperCore::MockableOneShotTimer* NewMockableOneShotTimer() {
|
| + last_one_shot_timer_ = new MockOneShotTimer();
|
| + return last_one_shot_timer_;
|
| + }
|
| +
|
| NetErrorHelperCore core_;
|
|
|
| GURL url_being_fetched_;
|
| + GURL url_being_auto_reloaded_;
|
|
|
| // Contains the information passed to the last call to UpdateErrorPage, as a
|
| // string.
|
| @@ -147,6 +225,8 @@ class NetErrorHelperCoreTest : public testing::Test,
|
| std::string last_error_html_;
|
| // Number of times |last_error_html_| has been changed.
|
| int error_html_update_count_;
|
| +
|
| + MockOneShotTimer* last_one_shot_timer_;
|
| };
|
|
|
| //------------------------------------------------------------------------------
|
| @@ -1302,3 +1382,104 @@ TEST_F(NetErrorHelperCoreTest, LinkDoctorStopped) {
|
| last_error_html());
|
| EXPECT_EQ(1, error_html_update_count());
|
| }
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadDisabled) {
|
| + core().set_auto_reload_enabled(false);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| +
|
| + EXPECT_EQ(NULL, last_one_shot_timer());
|
| + EXPECT_FALSE(is_url_being_auto_reloaded());
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadSucceeds) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| +
|
| + EXPECT_TRUE(last_one_shot_timer());
|
| + EXPECT_TRUE(last_one_shot_timer()->IsRunning());
|
| + EXPECT_FALSE(is_url_being_auto_reloaded());
|
| +
|
| + last_one_shot_timer()->Fire();
|
| + EXPECT_FALSE(last_one_shot_timer()->IsRunning());
|
| + EXPECT_TRUE(core().IsAutoReloading());
|
| + EXPECT_TRUE(is_url_being_auto_reloaded());
|
| + EXPECT_EQ(url_being_auto_reloaded(), GURL(kFailedUrl));
|
| +
|
| + SuccessLoad();
|
| +
|
| + EXPECT_FALSE(last_one_shot_timer()->IsRunning());
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadRetries) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| +
|
| + base::TimeDelta delay;
|
| + EXPECT_TRUE(last_one_shot_timer());
|
| + EXPECT_TRUE(last_one_shot_timer()->IsRunning());
|
| + delay = last_one_shot_timer()->delay_;
|
| + EXPECT_FALSE(is_url_being_auto_reloaded());
|
| +
|
| + last_one_shot_timer()->Fire();
|
| + EXPECT_FALSE(last_one_shot_timer()->IsRunning());
|
| + EXPECT_TRUE(is_url_being_auto_reloaded());
|
| + EXPECT_EQ(url_being_auto_reloaded(), GURL(kFailedUrl));
|
| +
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| +
|
| + EXPECT_TRUE(last_one_shot_timer()->IsRunning());
|
| + EXPECT_NE(last_one_shot_timer()->delay_, delay);
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadStopsOnSuccess) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + last_one_shot_timer()->Fire();
|
| + EXPECT_TRUE(is_url_being_auto_reloaded());
|
| + SuccessLoad();
|
| + EXPECT_FALSE(last_one_shot_timer()->IsRunning());
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadStopsTimerOnStop) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + EXPECT_TRUE(last_one_shot_timer()->IsRunning());
|
| + core().OnStop();
|
| + EXPECT_FALSE(last_one_shot_timer()->IsRunning());
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadStopsLoadingOnStop) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + last_one_shot_timer()->Fire();
|
| + EXPECT_TRUE(is_url_being_auto_reloaded());
|
| + core().OnStop();
|
| + EXPECT_FALSE(is_url_being_auto_reloaded());
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadResetsCountOnSuccess) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + base::TimeDelta delay = last_one_shot_timer()->delay_;
|
| + last_one_shot_timer()->Fire();
|
| + SuccessLoad();
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + EXPECT_EQ(last_one_shot_timer()->delay_, delay);
|
| +}
|
| +
|
| +TEST_F(NetErrorHelperCoreTest, AutoReloadStopsOnOtherLoadStart) {
|
| + core().set_auto_reload_enabled(true);
|
| + ErrorLoad(net::ERR_CONNECTION_RESET);
|
| + last_one_shot_timer()->Fire();
|
| + core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
|
| + NetErrorHelperCore::NON_ERROR_PAGE);
|
| + std::string html;
|
| + EXPECT_TRUE(core().IsAutoReloading());
|
| + core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
|
| + NetError(net::ERR_ABORTED), false, &html);
|
| +
|
| + EXPECT_FALSE(core().IsAutoReloading());
|
| + core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
|
| + NetErrorHelperCore::NON_ERROR_PAGE);
|
| + EXPECT_FALSE(core().IsAutoReloading());
|
| +}
|
|
|