| Index: chrome/browser/errorpage_browsertest.cc
|
| diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc
|
| index e2afcbf59b7c601ef1b81187426d68a6d2e86b55..091cbf529c9984de668f6e2f92d39e6069e8d744 100644
|
| --- a/chrome/browser/errorpage_browsertest.cc
|
| +++ b/chrome/browser/errorpage_browsertest.cc
|
| @@ -26,11 +26,55 @@
|
| #include "net/base/net_errors.h"
|
| #include "net/base/net_util.h"
|
| #include "net/url_request/url_request_filter.h"
|
| +#include "net/url_request/url_request_job.h"
|
| #include "net/url_request/url_request_job_factory.h"
|
| +#include "net/url_request/url_request_test_job.h"
|
| +#include "net/url_request/url_request_test_util.h"
|
|
|
| using content::BrowserThread;
|
| using content::NavigationController;
|
| using content::URLRequestFailedJob;
|
| +using net::URLRequestTestJob;
|
| +using net::TestJobInterceptor;
|
| +
|
| +class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
| + public:
|
| + TestProtocolHandler(const GURL& url, int failure_threshold)
|
| + : url_(url), requests_(0), failures_(0),
|
| + failure_threshold_(failure_threshold) {}
|
| + virtual ~TestProtocolHandler() {}
|
| +
|
| + virtual net::URLRequestJob* MaybeCreateJob(
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate) const {
|
| + if (request->url() != url_)
|
| + return NULL;
|
| + requests_++;
|
| + if (failures_ < failure_threshold_) {
|
| + failures_++;
|
| + return new URLRequestFailedJob(request,
|
| + network_delegate,
|
| + net::ERR_CONNECTION_RESET);
|
| + } else {
|
| + return new URLRequestTestJob(request, network_delegate,
|
| + URLRequestTestJob::test_headers(),
|
| + URLRequestTestJob::test_data_1(),
|
| + true);
|
| + }
|
| + }
|
| +
|
| + int requests() const { return requests_; }
|
| + int failures() const { return failures_; }
|
| + int threshold() const { return failure_threshold_; }
|
| +
|
| + private:
|
| + GURL url_;
|
| + // these are mutable because MaybeCreateJob is const but we want this state
|
| + // for testing.
|
| + mutable int requests_;
|
| + mutable int failures_;
|
| + int failure_threshold_;
|
| +};
|
|
|
| namespace {
|
|
|
| @@ -356,6 +400,75 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
|
| 1);
|
| }
|
|
|
| +class ErrorPageAutoReloadTest : public InProcessBrowserTest {
|
| + public:
|
| + virtual void SetUpOnMainThread() OVERRIDE {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&ErrorPageAutoReloadTest::AddFilters));
|
| + }
|
| +
|
| + virtual void CleanUpOnMainThread() OVERRIDE {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&ErrorPageAutoReloadTest::RemoveFilters));
|
| + }
|
| +
|
| + protected:
|
| + void NavigateToURLAndWaitForTitle(const GURL& url,
|
| + const std::string& expected_title,
|
| + int num_navigations) {
|
| + content::TitleWatcher title_watcher(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + base::ASCIIToUTF16(expected_title));
|
| +
|
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
|
| + browser(), url, num_navigations);
|
| +
|
| + EXPECT_EQ(base::ASCIIToUTF16(expected_title),
|
| + title_watcher.WaitAndGetTitle());
|
| + }
|
| +
|
| + static std::string test_schema() { return "http"; }
|
| + static std::string test_domain() { return "error.page.auto.reload"; }
|
| + static GURL test_url() {
|
| + return GURL(test_schema() + "://" + test_domain());
|
| + }
|
| + static TestProtocolHandler* protocol_handler() { return protocol_handler_; }
|
| +
|
| + private:
|
| + static void AddFilters() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| +
|
| + content::URLRequestFailedJob::AddUrlHandler();
|
| + protocol_handler_ = new TestProtocolHandler(test_url(), 2);
|
| + // pass ownership of the pointer to the URLRequestFilter, which outlives
|
| + // this object, but keep a copy of it so tests can query its state.
|
| + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
|
| + scoped_thing(protocol_handler_);
|
| +
|
| + net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
|
| + test_schema(), test_domain(), scoped_thing.Pass());
|
| + }
|
| +
|
| + static void RemoveFilters() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + net::URLRequestFilter::GetInstance()->ClearHandlers();
|
| + }
|
| +
|
| + static TestProtocolHandler* protocol_handler_;
|
| +
|
| +};
|
| +
|
| +TestProtocolHandler* ErrorPageAutoReloadTest::protocol_handler_ = NULL;
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, AutoReload) {
|
| + NavigateToURLAndWaitForTitle(test_url(), "Test One", 3);
|
| + EXPECT_EQ(protocol_handler()->failures(), protocol_handler()->threshold());
|
| + EXPECT_EQ(protocol_handler()->requests(),
|
| + protocol_handler()->threshold() + 1);
|
| +}
|
| +
|
| // Returns Javascript code that executes plain text search for the page.
|
| // Pass into content::ExecuteScriptAndExtractBool as |script| parameter.
|
| std::string GetTextContentContainsStringScript(
|
|
|