This source file includes following definitions.
- SuggestionsToResponse
- ErrorToString
- ProbeError
- NetError
- HttpError
- ProbeErrorString
- NetErrorString
- enable_stale_load_bindings_count_
- core
- url_being_fetched
- is_url_being_fetched
- reload_count
- enable_stale_load_bindings_count
- last_update_string
- update_count
- last_error_html
- error_html_update_count
- last_error_page_params
- timer
- NavigationCorrectionsLoadSuccess
- NavigationCorrectionsLoadFailure
- NavigationCorrectionsLoadFinished
- DoErrorLoad
- DoSuccessLoad
- DoDnsProbe
- EnableNavigationCorrections
- DisableNavigationCorrections
- ExpectDefaultNavigationCorrections
- SetNavigationCorrectionURL
- GenerateLocalizedErrorPage
- LoadErrorPageInMainFrame
- EnableStaleLoadBindings
- UpdateErrorPage
- FetchNavigationCorrections
- CancelFetchNavigationCorrections
- ReloadPage
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/renderer/net/net_error_helper_core.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/timer/mock_timer.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "chrome/common/net/net_error_info.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
using blink::WebURLError;
using chrome_common_net::DnsProbeStatus;
using chrome_common_net::DnsProbeStatusToString;
const char kFailedUrl[] = "http://failed/";
const char kFailedHttpsUrl[] = "https://failed/";
const char kNavigationCorrectionUrl[] = "http://navigation.corrections/";
const char kSearchUrl[] = "http://www.google.com/search";
const char kSuggestedSearchTerms[] = "Happy Goats";
struct NavigationCorrection {
const char* correction_type;
const char* url_correction;
bool is_porn;
bool is_soft_porn;
base::Value* ToValue() const {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("correctionType", correction_type);
dict->SetString("urlCorrection", url_correction);
dict->SetBoolean("isPorn", is_porn);
dict->SetBoolean("isSoftPorn", is_soft_porn);
return dict;
}
};
const NavigationCorrection kDefaultCorrections[] = {
{"reloadPage", kFailedUrl, false, false},
{"urlCorrection", "http://somewhere_else/", false, false},
{"contentOverlap", "http://somewhere_else_entirely/", false, false},
{"emphasizedUrlCorrection", "http://porn/", true, false},
{"sitemap", "http://more_porn/", false, true},
{"webSearchQuery", kSuggestedSearchTerms, false, false},
};
std::string SuggestionsToResponse(const NavigationCorrection* corrections,
int num_corrections) {
base::ListValue* url_corrections = new base::ListValue();
for (int i = 0; i < num_corrections; ++i)
url_corrections->Append(corrections[i].ToValue());
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
response->Set("result.UrlCorrections", url_corrections);
std::string json;
base::JSONWriter::Write(response.get(), &json);
return json;
}
std::string ErrorToString(const WebURLError& error, bool is_failed_post) {
return base::StringPrintf("(%s, %s, %i, %s)",
error.unreachableURL.string().utf8().c_str(),
error.domain.utf8().c_str(), error.reason,
is_failed_post ? "POST" : "NOT POST");
}
WebURLError ProbeError(DnsProbeStatus status) {
WebURLError error;
error.unreachableURL = GURL(kFailedUrl);
error.domain = blink::WebString::fromUTF8(
chrome_common_net::kDnsProbeErrorDomain);
error.reason = status;
return error;
}
WebURLError NetError(net::Error net_error) {
WebURLError error;
error.unreachableURL = GURL(kFailedUrl);
error.domain = blink::WebString::fromUTF8(net::kErrorDomain);
error.reason = net_error;
return error;
}
WebURLError HttpError(int status_code) {
WebURLError error;
error.unreachableURL = GURL(kFailedUrl);
error.domain = blink::WebString::fromUTF8("http");
error.reason = status_code;
return error;
}
std::string ProbeErrorString(DnsProbeStatus status) {
return ErrorToString(ProbeError(status), false);
}
std::string NetErrorString(net::Error net_error) {
return ErrorToString(NetError(net_error), false);
}
class NetErrorHelperCoreTest : public testing::Test,
public NetErrorHelperCore::Delegate {
public:
NetErrorHelperCoreTest() : timer_(new base::MockTimer(false, false)),
core_(this),
update_count_(0),
error_html_update_count_(0),
reload_count_(0),
enable_stale_load_bindings_count_(0) {
core_.set_auto_reload_enabled(false);
core_.set_timer_for_testing(scoped_ptr<base::Timer>(timer_));
}
virtual ~NetErrorHelperCoreTest() {
EXPECT_FALSE(is_url_being_fetched());
}
NetErrorHelperCore& core() { return core_; }
const GURL& url_being_fetched() const { return url_being_fetched_; }
bool is_url_being_fetched() const { return !url_being_fetched_.is_empty(); }
int reload_count() const {
return reload_count_;
}
int enable_stale_load_bindings_count() const {
return enable_stale_load_bindings_count_;
}
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_; }
const LocalizedError::ErrorPageParams* last_error_page_params() const {
return last_error_page_params_.get();
}
base::MockTimer* timer() { return timer_; }
void NavigationCorrectionsLoadSuccess(
const NavigationCorrection* corrections, int num_corrections) {
NavigationCorrectionsLoadFinished(
SuggestionsToResponse(corrections, num_corrections));
}
void NavigationCorrectionsLoadFailure() {
NavigationCorrectionsLoadFinished("");
}
void NavigationCorrectionsLoadFinished(const std::string& result) {
url_being_fetched_ = GURL();
core().OnNavigationCorrectionsFetched(result, "en", false);
}
void DoErrorLoad(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 DoSuccessLoad() {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
}
void DoDnsProbe(chrome_common_net::DnsProbeStatus final_status) {
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(final_status);
}
void EnableNavigationCorrections() {
SetNavigationCorrectionURL(GURL(kNavigationCorrectionUrl));
}
void DisableNavigationCorrections() {
SetNavigationCorrectionURL(GURL());
}
void ExpectDefaultNavigationCorrections() const {
ASSERT_TRUE(last_error_page_params());
EXPECT_TRUE(last_error_page_params()->suggest_reload);
EXPECT_EQ(2u, last_error_page_params()->override_suggestions->GetSize());
EXPECT_EQ(GURL(kSearchUrl), last_error_page_params()->search_url);
EXPECT_EQ(kSuggestedSearchTerms, last_error_page_params()->search_terms);
}
private:
void SetNavigationCorrectionURL(const GURL& navigation_correction_url) {
core().OnSetNavigationCorrectionInfo(navigation_correction_url,
"en", "us", "api_key",
GURL(kSearchUrl));
}
virtual void GenerateLocalizedErrorPage(
const WebURLError& error,
bool is_failed_post,
scoped_ptr<LocalizedError::ErrorPageParams> params,
std::string* html) const OVERRIDE {
last_error_page_params_.reset(params.release());
*html = ErrorToString(error, is_failed_post);
}
virtual void LoadErrorPageInMainFrame(const std::string& html,
const GURL& failed_url) OVERRIDE {
error_html_update_count_++;
last_error_html_ = html;
}
virtual void EnableStaleLoadBindings(const GURL& page_url) OVERRIDE {
enable_stale_load_bindings_count_++;
}
virtual void UpdateErrorPage(const WebURLError& error,
bool is_failed_post) OVERRIDE {
update_count_++;
last_error_page_params_.reset(NULL);
last_error_html_ = ErrorToString(error, is_failed_post);
}
virtual void FetchNavigationCorrections(
const GURL& navigation_correction_url,
const std::string& navigation_correction_request_body) OVERRIDE {
EXPECT_TRUE(url_being_fetched_.is_empty());
EXPECT_TRUE(request_body_.empty());
EXPECT_EQ(GURL(kNavigationCorrectionUrl), navigation_correction_url);
url_being_fetched_ = navigation_correction_url;
request_body_ = navigation_correction_request_body;
}
virtual void CancelFetchNavigationCorrections() OVERRIDE {
url_being_fetched_ = GURL();
request_body_.clear();
}
virtual void ReloadPage() OVERRIDE {
reload_count_++;
}
base::MockTimer* timer_;
NetErrorHelperCore core_;
GURL url_being_fetched_;
std::string request_body_;
std::string last_update_string_;
int update_count_;
std::string last_error_html_;
int error_html_update_count_;
mutable scoped_ptr<LocalizedError::ErrorPageParams> last_error_page_params_;
int reload_count_;
int enable_stale_load_bindings_count_;
};
TEST_F(NetErrorHelperCoreTest, Null) {
}
TEST_F(NetErrorHelperCoreTest, SuccessfulPageLoad) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, SuccessfulPageLoadWithNavigationCorrections) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, MainFrameNonDnsError) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
EXPECT_FALSE(html.empty());
EXPECT_EQ(NetErrorString(net::ERR_CONNECTION_RESET), html);
EXPECT_EQ(0, enable_stale_load_bindings_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
EXPECT_EQ(1, enable_stale_load_bindings_count());
}
TEST_F(NetErrorHelperCoreTest, MainFrameNonDnsErrorWithCorrections) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
EXPECT_FALSE(html.empty());
EXPECT_EQ(NetErrorString(net::ERR_CONNECTION_RESET), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, MainFrameNonDnsErrorSpuriousStatus) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET),
false, &html);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_FALSE(html.empty());
EXPECT_EQ(NetErrorString(net::ERR_CONNECTION_RESET), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, SubFrameDnsError) {
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::SUB_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), html);
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::SUB_FRAME);
core().OnFinishLoad(NetErrorHelperCore::SUB_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, SubFrameDnsErrorWithCorrections) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::SUB_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), html);
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::SUB_FRAME);
core().OnFinishLoad(NetErrorHelperCore::SUB_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, SubFrameDnsErrorSpuriousStatus) {
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::SUB_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), html);
core().OnStartLoad(NetErrorHelperCore::SUB_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
core().OnCommitLoad(NetErrorHelperCore::SUB_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
core().OnFinishLoad(NetErrorHelperCore::SUB_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbe) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbeNotRun) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_NOT_RUN);
EXPECT_EQ(1, update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(1, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbeInconclusive) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE);
EXPECT_EQ(2, update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE);
EXPECT_EQ(2, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbeNoInternet) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET);
EXPECT_EQ(2, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbeBadConfig) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG);
EXPECT_EQ(2, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedAfterStartProbe) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(0, update_count());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_NOT_RUN);
EXPECT_EQ(2, update_count());
}
TEST_F(NetErrorHelperCoreTest, FinishedBeforeProbePost) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
true, &html);
EXPECT_EQ(ErrorToString(
ProbeError(chrome_common_net::DNS_PROBE_POSSIBLE),
true),
html);
EXPECT_EQ(0, enable_stale_load_bindings_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, enable_stale_load_bindings_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ErrorToString(
ProbeError(chrome_common_net::DNS_PROBE_STARTED), true),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ErrorToString(
ProbeError(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
true),
last_error_html());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, ProbeFinishesEarly) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(0, update_count());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(1, update_count());
}
TEST_F(NetErrorHelperCoreTest, TwoErrorsWithProbes) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(2, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(3, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET);
EXPECT_EQ(4, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET),
last_error_html());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, TwoErrorsWithProbesAfterSecondStarts) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(3, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET);
EXPECT_EQ(3, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, ErrorPageLoadInterrupted) {
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE), html);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET),
last_error_html());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, NoCorrectionsForHttps) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
blink::WebURLError error = NetError(net::ERR_NAME_NOT_RESOLVED);
error.unreachableURL = GURL(kFailedHttpsUrl);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME, error, false, &html);
blink::WebURLError probe_error =
ProbeError(chrome_common_net::DNS_PROBE_POSSIBLE);
probe_error.unreachableURL = GURL(kFailedHttpsUrl);
EXPECT_EQ(ErrorToString(probe_error, false), html);
EXPECT_FALSE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
EXPECT_EQ(0, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_FALSE(last_error_page_params());
blink::WebURLError final_probe_error =
ProbeError(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
final_probe_error.unreachableURL = GURL(kFailedHttpsUrl);
EXPECT_EQ(ErrorToString(final_probe_error, false), last_error_html());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsReceivedBeforeProbe) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
EXPECT_FALSE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
NavigationCorrectionsLoadSuccess(kDefaultCorrections,
arraysize(kDefaultCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
ExpectDefaultNavigationCorrections();
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_EQ(1, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsRetrievedAfterProbes) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
EXPECT_FALSE(last_error_page_params());
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadSuccess(kDefaultCorrections,
arraysize(kDefaultCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
ExpectDefaultNavigationCorrections();
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsFailLoadNoProbes) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_FAILED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFailure();
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(), NetErrorString(net::ERR_CONNECTION_FAILED));
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
EXPECT_FALSE(last_error_page_params());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_EQ(1, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsFailLoadBeforeProbe) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFailure();
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(),
ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE));
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(1, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsFailAfterProbe) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFailure();
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(),
ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE));
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(1, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
EXPECT_EQ(1, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsInterruptedBeforeCommit) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(is_url_being_fetched());
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsInterruptedBeforeLoad) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(is_url_being_fetched());
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
EXPECT_EQ(0, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsInterrupted) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(is_url_being_fetched());
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(is_url_being_fetched());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadSuccess(kDefaultCorrections,
arraysize(kDefaultCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
ExpectDefaultNavigationCorrections();
EXPECT_FALSE(is_url_being_fetched());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsStopped) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
core().OnStop();
EXPECT_FALSE(is_url_being_fetched());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(0, update_count());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFailure();
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(),
ProbeErrorString(chrome_common_net::DNS_PROBE_POSSIBLE));
EXPECT_FALSE(is_url_being_fetched());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_STARTED);
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_STARTED),
last_error_html());
EXPECT_EQ(1, update_count());
core().OnNetErrorInfo(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
EXPECT_EQ(2, update_count());
EXPECT_EQ(ProbeErrorString(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN),
last_error_html());
EXPECT_EQ(1, error_html_update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsDisabledBeforeFetch) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
DisableNavigationCorrections();
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
NavigationCorrectionsLoadSuccess(kDefaultCorrections,
arraysize(kDefaultCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
EXPECT_FALSE(is_url_being_fetched());
ExpectDefaultNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsDisabledDuringFetch) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
DisableNavigationCorrections();
NavigationCorrectionsLoadSuccess(kDefaultCorrections,
arraysize(kDefaultCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
EXPECT_FALSE(is_url_being_fetched());
ExpectDefaultNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsWithoutSearch) {
const NavigationCorrection kCorrections[] = {
{"urlCorrection", "http://somewhere_else/", false, false},
};
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
NavigationCorrectionsLoadSuccess(kCorrections, arraysize(kCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
EXPECT_FALSE(is_url_being_fetched());
ASSERT_TRUE(last_error_page_params());
EXPECT_FALSE(last_error_page_params()->suggest_reload);
EXPECT_EQ(1u, last_error_page_params()->override_suggestions->GetSize());
EXPECT_FALSE(last_error_page_params()->search_url.is_valid());
EXPECT_EQ("", last_error_page_params()->search_terms);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionsOnlySearchSuggestion) {
const NavigationCorrection kCorrections[] = {
{"webSearchQuery", kSuggestedSearchTerms, false, false},
};
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_NAME_NOT_RESOLVED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
EXPECT_FALSE(last_error_page_params());
NavigationCorrectionsLoadSuccess(kCorrections, arraysize(kCorrections));
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(NetErrorString(net::ERR_NAME_NOT_RESOLVED), last_error_html());
EXPECT_FALSE(is_url_being_fetched());
ASSERT_TRUE(last_error_page_params());
EXPECT_FALSE(last_error_page_params()->suggest_reload);
EXPECT_EQ(0u, last_error_page_params()->override_suggestions->GetSize());
EXPECT_EQ(GURL(kSearchUrl), last_error_page_params()->search_url);
EXPECT_EQ(kSuggestedSearchTerms, last_error_page_params()->search_terms);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(0, update_count());
}
TEST_F(NetErrorHelperCoreTest, CorrectionServiceReturnsNonJsonResult) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_FAILED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFinished("Weird Response");
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(), NetErrorString(net::ERR_CONNECTION_FAILED));
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
EXPECT_FALSE(last_error_page_params());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
}
TEST_F(NetErrorHelperCoreTest, CorrectionServiceReturnsInvalidJsonResult) {
EnableNavigationCorrections();
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_FAILED),
false, &html);
EXPECT_TRUE(html.empty());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_TRUE(is_url_being_fetched());
NavigationCorrectionsLoadFinished("{\"result\": 42}");
EXPECT_EQ(1, error_html_update_count());
EXPECT_EQ(last_error_html(), NetErrorString(net::ERR_CONNECTION_FAILED));
EXPECT_FALSE(is_url_being_fetched());
EXPECT_EQ(0, update_count());
EXPECT_FALSE(last_error_page_params());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
}
TEST_F(NetErrorHelperCoreTest, AutoReloadDisabled) {
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(0, reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadSucceeds) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
EXPECT_EQ(0, reload_count());
timer()->Fire();
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(1, reload_count());
DoSuccessLoad();
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadRetries) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
base::TimeDelta first_delay = timer()->GetCurrentDelay();
EXPECT_EQ(0, reload_count());
timer()->Fire();
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(1, reload_count());
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
EXPECT_GT(timer()->GetCurrentDelay(), first_delay);
}
TEST_F(NetErrorHelperCoreTest, AutoReloadStopsTimerOnStop) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
core().OnStop();
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadStopsLoadingOnStop) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_EQ(1, core().auto_reload_count());
timer()->Fire();
EXPECT_EQ(1, reload_count());
core().OnStop();
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(0, core().auto_reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadStopsOnOtherLoadStart) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(1, core().auto_reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadResetsCountOnSuccess) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
base::TimeDelta delay = timer()->GetCurrentDelay();
EXPECT_EQ(1, core().auto_reload_count());
timer()->Fire();
EXPECT_EQ(1, reload_count());
DoSuccessLoad();
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_EQ(1, core().auto_reload_count());
EXPECT_EQ(timer()->GetCurrentDelay(), delay);
timer()->Fire();
EXPECT_EQ(2, reload_count());
DoSuccessLoad();
EXPECT_EQ(0, core().auto_reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadRestartsOnOnline) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
base::TimeDelta delay = timer()->GetCurrentDelay();
timer()->Fire();
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
EXPECT_NE(delay, timer()->GetCurrentDelay());
core().NetworkStateChanged(true);
EXPECT_TRUE(timer()->IsRunning());
EXPECT_EQ(delay, timer()->GetCurrentDelay());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadDoesNotStartOnOnline) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
timer()->Fire();
DoSuccessLoad();
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadStopsOnOffline) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
core().NetworkStateChanged(false);
EXPECT_FALSE(timer()->IsRunning());
EXPECT_EQ(0, core().auto_reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadStopsOnOfflineThenRestartsOnOnline) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
core().NetworkStateChanged(false);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_TRUE(timer()->IsRunning());
EXPECT_EQ(1, core().auto_reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadDoesNotRestartOnOnlineAfterStop) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
timer()->Fire();
core().OnStop();
core().NetworkStateChanged(true);
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadWithDnsProbes) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
DoDnsProbe(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN);
timer()->Fire();
EXPECT_EQ(1, reload_count());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadExponentialBackoffLevelsOff) {
core().set_auto_reload_enabled(true);
base::TimeDelta previous = base::TimeDelta::FromMilliseconds(0);
const int kMaxTries = 50;
int tries = 0;
for (tries = 0; tries < kMaxTries; tries++) {
DoErrorLoad(net::ERR_CONNECTION_RESET);
EXPECT_TRUE(timer()->IsRunning());
if (previous == timer()->GetCurrentDelay())
break;
previous = timer()->GetCurrentDelay();
timer()->Fire();
}
EXPECT_LT(tries, kMaxTries);
}
TEST_F(NetErrorHelperCoreTest, AutoReloadSlowError) {
core().set_auto_reload_enabled(true);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
EXPECT_FALSE(timer()->IsRunning());
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadOnlineSlowError) {
core().set_auto_reload_enabled(true);
core().NetworkStateChanged(false);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(false);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_TRUE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadOnlinePendingError) {
core().set_auto_reload_enabled(true);
core().NetworkStateChanged(false);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(false);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_TRUE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, AutoReloadOnlinePartialErrorReplacement) {
core().set_auto_reload_enabled(true);
core().NetworkStateChanged(false);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
std::string html;
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
core().OnCommitLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::NON_ERROR_PAGE);
core().GetErrorHTML(NetErrorHelperCore::MAIN_FRAME,
NetError(net::ERR_CONNECTION_RESET), false, &html);
core().OnStartLoad(NetErrorHelperCore::MAIN_FRAME,
NetErrorHelperCore::ERROR_PAGE);
EXPECT_FALSE(timer()->IsRunning());
core().NetworkStateChanged(true);
EXPECT_FALSE(timer()->IsRunning());
}
TEST_F(NetErrorHelperCoreTest, ShouldSuppressErrorPage) {
core().set_auto_reload_enabled(true);
DoErrorLoad(net::ERR_CONNECTION_RESET);
timer()->Fire();
EXPECT_FALSE(core().ShouldSuppressErrorPage(NetErrorHelperCore::SUB_FRAME,
GURL(kFailedUrl)));
EXPECT_FALSE(core().ShouldSuppressErrorPage(NetErrorHelperCore::MAIN_FRAME,
GURL("http://some.other.url")));
EXPECT_TRUE(core().ShouldSuppressErrorPage(NetErrorHelperCore::MAIN_FRAME,
GURL(kFailedUrl)));
}