[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | 4e7c042 | 2016-04-14 00:59:05 | [diff] [blame] | 5 | #include <memory> |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 6 | #include <set> |
| 7 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | b292d76 | 2013-07-17 21:22:09 | [diff] [blame] | 9 | #include "base/message_loop/message_loop.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 11 | #include "base/run_loop.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 12 | #include "base/threading/thread_restrictions.h" |
| 13 | #include "chrome/browser/browser_process.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 14 | #include "chrome/browser/io_thread.h" |
| 15 | #include "chrome/browser/net/dns_probe_test_util.h" |
| 16 | #include "chrome/browser/net/net_error_tab_helper.h" |
| 17 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 18 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 19 | #include "chrome/browser/ui/browser.h" |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 20 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 21 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 | #include "chrome/common/chrome_paths.h" |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 23 | #include "chrome/common/pref_names.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 24 | #include "chrome/test/base/in_process_browser_test.h" |
| 25 | #include "chrome/test/base/ui_test_utils.h" |
hashimoto | 9b160e2 | 2014-10-15 03:56:53 | [diff] [blame] | 26 | #include "components/error_page/common/net_error_info.h" |
[email protected] | 8e44a5b0 | 2014-06-19 19:03:24 | [diff] [blame] | 27 | #include "components/google/core/browser/google_util.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 28 | #include "components/prefs/pref_service.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 29 | #include "content/public/browser/browser_thread.h" |
| 30 | #include "content/public/browser/web_contents.h" |
| 31 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 32 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 33 | #include "net/base/net_errors.h" |
| 34 | #include "net/dns/dns_test_util.h" |
xunjieli | 2906f15 | 2014-09-12 00:08:23 | [diff] [blame] | 35 | #include "net/test/url_request/url_request_failed_job.h" |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 36 | #include "net/test/url_request/url_request_mock_http_job.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 37 | #include "net/url_request/url_request_filter.h" |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 38 | #include "net/url_request/url_request_interceptor.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 39 | #include "net/url_request/url_request_job.h" |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 40 | |
| 41 | using base::Bind; |
| 42 | using base::Callback; |
| 43 | using base::Closure; |
| 44 | using base::ConstRef; |
| 45 | using base::FilePath; |
| 46 | using base::MessageLoop; |
| 47 | using base::Unretained; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 48 | using content::BrowserThread; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 49 | using content::WebContents; |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 50 | using error_page::DnsProbeStatus; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 51 | using google_util::LinkDoctorBaseURL; |
| 52 | using net::MockDnsClientRule; |
| 53 | using net::NetworkDelegate; |
| 54 | using net::URLRequest; |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 55 | using net::URLRequestFailedJob; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 56 | using net::URLRequestFilter; |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 57 | using net::URLRequestInterceptor; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 58 | using net::URLRequestJob; |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 59 | using net::URLRequestMockHTTPJob; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 60 | using ui_test_utils::NavigateToURL; |
| 61 | using ui_test_utils::NavigateToURLBlockUntilNavigationsComplete; |
| 62 | |
| 63 | namespace chrome_browser_net { |
| 64 | |
| 65 | namespace { |
| 66 | |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 67 | // Postable function to run a Closure on the UI thread. Since |
| 68 | // BrowserThread::PostTask returns a bool, it can't directly be posted to |
| 69 | // another thread. |
| 70 | void RunClosureOnUIThread(const base::Closure& closure) { |
| 71 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure); |
| 72 | } |
| 73 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 74 | // Wraps DnsProbeService and delays callbacks until someone calls |
| 75 | // CallDelayedCallbacks. This allows the DnsProbeBrowserTest to enforce a |
| 76 | // stricter ordering of events. |
| 77 | class DelayingDnsProbeService : public DnsProbeService { |
| 78 | public: |
| 79 | DelayingDnsProbeService() {} |
| 80 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 81 | ~DelayingDnsProbeService() override { EXPECT_TRUE(delayed_probes_.empty()); } |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 82 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 83 | void ProbeDns(const ProbeCallback& callback) override { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 84 | delayed_probes_.push_back(callback); |
| 85 | } |
| 86 | |
| 87 | void StartDelayedProbes() { |
| 88 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 89 | |
| 90 | std::vector<ProbeCallback> probes; |
| 91 | probes.swap(delayed_probes_); |
| 92 | |
| 93 | for (std::vector<ProbeCallback>::const_iterator i = probes.begin(); |
| 94 | i != probes.end(); ++i) { |
| 95 | DnsProbeService::ProbeDns(*i); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | int delayed_probe_count() const { |
| 100 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 101 | return delayed_probes_.size(); |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | std::vector<ProbeCallback> delayed_probes_; |
| 106 | }; |
| 107 | |
| 108 | FilePath GetMockLinkDoctorFilePath() { |
| 109 | FilePath root_http; |
| 110 | PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 111 | return root_http.AppendASCII("mock-link-doctor.json"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 112 | } |
| 113 | |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 114 | // A request that can be delayed until Resume() is called. Can also run a |
| 115 | // callback if destroyed without being resumed. Resume can be called either |
| 116 | // before or after a the request is started. |
| 117 | class DelayableRequest { |
| 118 | public: |
| 119 | // Called by a DelayableRequest if it was set to be delayed, and has been |
| 120 | // destroyed without Undelay being called. |
| 121 | typedef base::Callback<void(DelayableRequest* request)> DestructionCallback; |
| 122 | |
| 123 | virtual void Resume() = 0; |
| 124 | |
| 125 | protected: |
| 126 | virtual ~DelayableRequest() {} |
| 127 | }; |
| 128 | |
| 129 | class DelayableURLRequestFailedJob : public URLRequestFailedJob, |
| 130 | public DelayableRequest { |
| 131 | public: |
| 132 | // |destruction_callback| is only called if a delayed request is destroyed |
| 133 | // without being resumed. |
| 134 | DelayableURLRequestFailedJob(net::URLRequest* request, |
| 135 | net::NetworkDelegate* network_delegate, |
| 136 | int net_error, |
| 137 | bool should_delay, |
| 138 | const DestructionCallback& destruction_callback) |
| 139 | : URLRequestFailedJob(request, network_delegate, net_error), |
| 140 | should_delay_(should_delay), |
| 141 | start_delayed_(false), |
| 142 | destruction_callback_(destruction_callback) {} |
| 143 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 144 | void Start() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 145 | if (should_delay_) { |
| 146 | DCHECK(!start_delayed_); |
| 147 | start_delayed_ = true; |
| 148 | return; |
| 149 | } |
| 150 | URLRequestFailedJob::Start(); |
| 151 | } |
| 152 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 153 | void Resume() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 154 | DCHECK(should_delay_); |
| 155 | should_delay_ = false; |
| 156 | if (start_delayed_) { |
| 157 | start_delayed_ = false; |
| 158 | Start(); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | private: |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 163 | ~DelayableURLRequestFailedJob() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 164 | if (should_delay_) |
| 165 | destruction_callback_.Run(this); |
| 166 | } |
| 167 | |
| 168 | bool should_delay_; |
| 169 | bool start_delayed_; |
| 170 | const DestructionCallback destruction_callback_; |
| 171 | }; |
| 172 | |
| 173 | class DelayableURLRequestMockHTTPJob : public URLRequestMockHTTPJob, |
| 174 | public DelayableRequest { |
| 175 | public: |
| 176 | DelayableURLRequestMockHTTPJob( |
| 177 | net::URLRequest* request, |
| 178 | net::NetworkDelegate* network_delegate, |
| 179 | const base::FilePath& file_path, |
| 180 | bool should_delay, |
| 181 | const DestructionCallback& destruction_callback) |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 182 | : URLRequestMockHTTPJob( |
| 183 | request, |
| 184 | network_delegate, |
| 185 | file_path, |
| 186 | BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 187 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 188 | should_delay_(should_delay), |
| 189 | start_delayed_(false), |
| 190 | destruction_callback_(destruction_callback) {} |
| 191 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 192 | void Start() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 193 | if (should_delay_) { |
| 194 | DCHECK(!start_delayed_); |
| 195 | start_delayed_ = true; |
| 196 | return; |
| 197 | } |
| 198 | URLRequestMockHTTPJob::Start(); |
| 199 | } |
| 200 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 201 | void Resume() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 202 | DCHECK(should_delay_); |
| 203 | should_delay_ = false; |
| 204 | if (start_delayed_) { |
| 205 | start_delayed_ = false; |
| 206 | Start(); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | private: |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 211 | ~DelayableURLRequestMockHTTPJob() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 212 | if (should_delay_) |
| 213 | destruction_callback_.Run(this); |
| 214 | } |
| 215 | |
| 216 | bool should_delay_; |
| 217 | bool start_delayed_; |
| 218 | const DestructionCallback destruction_callback_; |
| 219 | }; |
| 220 | |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 221 | // Interceptor for navigation correction requests. Can cause requests to |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 222 | // fail with an error, and/or delay a request until a test allows to continue. |
| 223 | // Also can run a callback when a delayed request is cancelled. |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 224 | class BreakableCorrectionInterceptor : public URLRequestInterceptor { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 225 | public: |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 226 | explicit BreakableCorrectionInterceptor( |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 227 | const FilePath& mock_corrections_file_path) |
| 228 | : mock_corrections_file_path_(mock_corrections_file_path), |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 229 | net_error_(net::OK), |
| 230 | delay_requests_(false), |
| 231 | on_request_destroyed_callback_( |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 232 | base::Bind(&BreakableCorrectionInterceptor::OnRequestDestroyed, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 233 | base::Unretained(this))) { |
| 234 | } |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 235 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 236 | ~BreakableCorrectionInterceptor() override { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 237 | // All delayed requests should have been resumed or cancelled by this point. |
| 238 | EXPECT_TRUE(delayed_requests_.empty()); |
| 239 | } |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 240 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 241 | URLRequestJob* MaybeInterceptRequest( |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 242 | URLRequest* request, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame] | 243 | NetworkDelegate* network_delegate) const override { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 244 | if (net_error_ != net::OK) { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 245 | DelayableURLRequestFailedJob* job = |
| 246 | new DelayableURLRequestFailedJob( |
| 247 | request, network_delegate, net_error_, delay_requests_, |
| 248 | on_request_destroyed_callback_); |
| 249 | if (delay_requests_) |
| 250 | delayed_requests_.insert(job); |
| 251 | return job; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 252 | } else { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 253 | DelayableURLRequestMockHTTPJob* job = |
| 254 | new DelayableURLRequestMockHTTPJob( |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 255 | request, network_delegate, mock_corrections_file_path_, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 256 | delay_requests_, on_request_destroyed_callback_); |
| 257 | if (delay_requests_) |
| 258 | delayed_requests_.insert(job); |
| 259 | return job; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
| 263 | void set_net_error(int net_error) { net_error_ = net_error; } |
| 264 | |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 265 | void SetDelayRequests(bool delay_requests) { |
| 266 | delay_requests_ = delay_requests; |
| 267 | |
| 268 | // Resume all delayed requests if no longer delaying requests. |
| 269 | if (!delay_requests) { |
| 270 | while (!delayed_requests_.empty()) { |
| 271 | DelayableRequest* request = *delayed_requests_.begin(); |
| 272 | delayed_requests_.erase(request); |
| 273 | request->Resume(); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Runs |callback| once all delayed requests have been destroyed. Does not |
| 279 | // wait for delayed requests that have been resumed. |
| 280 | void SetRequestDestructionCallback(const base::Closure& callback) { |
| 281 | ASSERT_TRUE(delayed_request_destruction_callback_.is_null()); |
| 282 | if (delayed_requests_.empty()) { |
| 283 | callback.Run(); |
| 284 | return; |
| 285 | } |
| 286 | delayed_request_destruction_callback_ = callback; |
| 287 | } |
| 288 | |
| 289 | void OnRequestDestroyed(DelayableRequest* request) { |
| 290 | ASSERT_EQ(1u, delayed_requests_.count(request)); |
| 291 | delayed_requests_.erase(request); |
| 292 | if (delayed_requests_.empty() && |
| 293 | !delayed_request_destruction_callback_.is_null()) { |
| 294 | delayed_request_destruction_callback_.Run(); |
| 295 | delayed_request_destruction_callback_.Reset(); |
| 296 | } |
| 297 | } |
| 298 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 299 | private: |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 300 | const FilePath mock_corrections_file_path_; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 301 | int net_error_; |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 302 | bool delay_requests_; |
| 303 | |
| 304 | // Called when a request is destroyed. Memeber variable because |
| 305 | // MaybeCreateJob is "const", so calling base::Bind in that function does |
| 306 | // not work well. |
| 307 | const DelayableRequest::DestructionCallback on_request_destroyed_callback_; |
| 308 | |
| 309 | // Mutable is needed because MaybeCreateJob is const. |
| 310 | mutable std::set<DelayableRequest*> delayed_requests_; |
| 311 | |
| 312 | base::Closure delayed_request_destruction_callback_; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | class DnsProbeBrowserTestIOThreadHelper { |
| 316 | public: |
| 317 | DnsProbeBrowserTestIOThreadHelper(); |
| 318 | |
| 319 | void SetUpOnIOThread(IOThread* io_thread); |
| 320 | void CleanUpOnIOThreadAndDeleteHelper(); |
| 321 | |
eroman | 1efc237c | 2016-12-14 00:00:45 | [diff] [blame] | 322 | void SetMockDnsClientRules(MockDnsClientRule::ResultType system_good_result, |
| 323 | MockDnsClientRule::ResultType public_good_result); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 324 | void SetCorrectionServiceNetError(int net_error); |
| 325 | void SetCorrectionServiceDelayRequests(bool delay_requests); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 326 | void SetRequestDestructionCallback(const base::Closure& callback); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 327 | void StartDelayedProbes(int expected_delayed_probe_count); |
| 328 | |
| 329 | private: |
| 330 | IOThread* io_thread_; |
| 331 | DnsProbeService* original_dns_probe_service_; |
| 332 | DelayingDnsProbeService* delaying_dns_probe_service_; |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 333 | BreakableCorrectionInterceptor* interceptor_; |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 334 | FilePath mock_corrections_file_path_; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | DnsProbeBrowserTestIOThreadHelper::DnsProbeBrowserTestIOThreadHelper() |
| 338 | : io_thread_(NULL), |
| 339 | original_dns_probe_service_(NULL), |
| 340 | delaying_dns_probe_service_(NULL), |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 341 | interceptor_(NULL), |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 342 | mock_corrections_file_path_(GetMockLinkDoctorFilePath()) {} |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 343 | |
| 344 | void DnsProbeBrowserTestIOThreadHelper::SetUpOnIOThread(IOThread* io_thread) { |
| 345 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 346 | CHECK(io_thread); |
| 347 | CHECK(!io_thread_); |
| 348 | CHECK(!original_dns_probe_service_); |
| 349 | CHECK(!delaying_dns_probe_service_); |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 350 | CHECK(!interceptor_); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 351 | |
| 352 | io_thread_ = io_thread; |
| 353 | |
| 354 | delaying_dns_probe_service_ = new DelayingDnsProbeService(); |
| 355 | |
| 356 | IOThread::Globals* globals = io_thread_->globals(); |
| 357 | original_dns_probe_service_ = globals->dns_probe_service.release(); |
| 358 | globals->dns_probe_service.reset(delaying_dns_probe_service_); |
| 359 | |
| 360 | URLRequestFailedJob::AddUrlHandler(); |
| 361 | |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 362 | interceptor_ = |
| 363 | new BreakableCorrectionInterceptor(mock_corrections_file_path_); |
| 364 | URLRequestFilter::GetInstance()->AddUrlInterceptor( |
dcheng | 4e7c042 | 2016-04-14 00:59:05 | [diff] [blame] | 365 | LinkDoctorBaseURL(), |
| 366 | std::unique_ptr<URLRequestInterceptor>(interceptor_)); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper() { |
| 370 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 371 | |
| 372 | URLRequestFilter::GetInstance()->ClearHandlers(); |
| 373 | |
| 374 | IOThread::Globals* globals = io_thread_->globals(); |
dcheng | 4e7c042 | 2016-04-14 00:59:05 | [diff] [blame] | 375 | std::unique_ptr<DnsProbeService> delaying_dns_probe_service( |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 376 | globals->dns_probe_service.release()); |
| 377 | globals->dns_probe_service.reset(original_dns_probe_service_); |
| 378 | |
| 379 | CHECK_EQ(delaying_dns_probe_service_, delaying_dns_probe_service.get()); |
| 380 | |
| 381 | delete this; |
| 382 | } |
| 383 | |
| 384 | void DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules( |
eroman | 1efc237c | 2016-12-14 00:00:45 | [diff] [blame] | 385 | MockDnsClientRule::ResultType system_result, |
| 386 | MockDnsClientRule::ResultType public_result) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 387 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 388 | |
| 389 | DnsProbeService* service = io_thread_->globals()->dns_probe_service.get(); |
| 390 | service->SetSystemClientForTesting( |
| 391 | CreateMockDnsClientForProbes(system_result)); |
| 392 | service->SetPublicClientForTesting( |
| 393 | CreateMockDnsClientForProbes(public_result)); |
| 394 | } |
| 395 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 396 | void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError( |
| 397 | int net_error) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 398 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 399 | |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 400 | interceptor_->set_net_error(net_error); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 403 | void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceDelayRequests( |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 404 | bool delay_requests) { |
| 405 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 406 | |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 407 | interceptor_->SetDelayRequests(delay_requests); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback( |
| 411 | const base::Closure& callback) { |
| 412 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 413 | |
[email protected] | c74b646 | 2014-06-06 17:45:55 | [diff] [blame] | 414 | interceptor_->SetRequestDestructionCallback(callback); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 417 | void DnsProbeBrowserTestIOThreadHelper::StartDelayedProbes( |
| 418 | int expected_delayed_probe_count) { |
| 419 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 420 | |
| 421 | CHECK(delaying_dns_probe_service_); |
| 422 | |
| 423 | int actual_delayed_probe_count = |
| 424 | delaying_dns_probe_service_->delayed_probe_count(); |
| 425 | EXPECT_EQ(expected_delayed_probe_count, actual_delayed_probe_count); |
| 426 | |
| 427 | delaying_dns_probe_service_->StartDelayedProbes(); |
| 428 | } |
| 429 | |
| 430 | class DnsProbeBrowserTest : public InProcessBrowserTest { |
| 431 | public: |
| 432 | DnsProbeBrowserTest(); |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 433 | ~DnsProbeBrowserTest() override; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 434 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 435 | void SetUpOnMainThread() override; |
| 436 | void TearDownOnMainThread() override; |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 437 | |
| 438 | protected: |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 439 | // Sets the browser object that other methods apply to, and that has the |
| 440 | // DnsProbeStatus messages of its currently active tab monitored. |
| 441 | void SetActiveBrowser(Browser* browser); |
| 442 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 443 | void SetCorrectionServiceBroken(bool broken); |
| 444 | void SetCorrectionServiceDelayRequests(bool delay_requests); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 445 | void WaitForDelayedRequestDestruction(); |
eroman | 1efc237c | 2016-12-14 00:00:45 | [diff] [blame] | 446 | void SetMockDnsClientRules(MockDnsClientRule::ResultType system_result, |
| 447 | MockDnsClientRule::ResultType public_result); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 448 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 449 | // These functions are often used to wait for two navigations because two |
| 450 | // pages are loaded when navigation corrections are enabled: a blank page, so |
| 451 | // the user stops seeing the previous page, and then the error page, either |
| 452 | // with navigation corrections or without them (If the request failed). |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 453 | void NavigateToDnsError(int num_navigations); |
| 454 | void NavigateToOtherError(int num_navigations); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 455 | |
| 456 | void StartDelayedProbes(int expected_delayed_probe_count); |
| 457 | DnsProbeStatus WaitForSentStatus(); |
| 458 | int pending_status_count() const { return dns_probe_status_queue_.size(); } |
| 459 | |
| 460 | std::string Title(); |
| 461 | bool PageContains(const std::string& expected); |
| 462 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 463 | // Checks that the local error page is being displayed, without navigation |
| 464 | // corrections, and with the specified status text. The status text should be |
| 465 | // either a network error or DNS probe status. |
| 466 | void ExpectDisplayingLocalErrorPage(const std::string& status_text); |
| 467 | |
| 468 | // Checks that an error page with mock navigation corrections is being |
| 469 | // displayed, with the specified status text. The status text should be either |
| 470 | // a network error or DNS probe status. |
| 471 | void ExpectDisplayingCorrections(const std::string& status_text); |
| 472 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 473 | private: |
| 474 | void OnDnsProbeStatusSent(DnsProbeStatus dns_probe_status); |
| 475 | |
| 476 | DnsProbeBrowserTestIOThreadHelper* helper_; |
| 477 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 478 | // Browser that methods apply to. |
| 479 | Browser* active_browser_; |
| 480 | // Helper that current has its DnsProbeStatus messages monitored. |
| 481 | NetErrorTabHelper* monitored_tab_helper_; |
| 482 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 483 | bool awaiting_dns_probe_status_; |
| 484 | // Queue of statuses received but not yet consumed by WaitForSentStatus(). |
| 485 | std::list<DnsProbeStatus> dns_probe_status_queue_; |
| 486 | }; |
| 487 | |
| 488 | DnsProbeBrowserTest::DnsProbeBrowserTest() |
| 489 | : helper_(new DnsProbeBrowserTestIOThreadHelper()), |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 490 | active_browser_(NULL), |
| 491 | monitored_tab_helper_(NULL), |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 492 | awaiting_dns_probe_status_(false) { |
| 493 | } |
| 494 | |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 495 | DnsProbeBrowserTest::~DnsProbeBrowserTest() { |
| 496 | // No tests should have any unconsumed probe statuses. |
| 497 | EXPECT_EQ(0, pending_status_count()); |
| 498 | } |
| 499 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 500 | void DnsProbeBrowserTest::SetUpOnMainThread() { |
| 501 | NetErrorTabHelper::set_state_for_testing( |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 502 | NetErrorTabHelper::TESTING_DEFAULT); |
| 503 | |
| 504 | browser()->profile()->GetPrefs()->SetBoolean( |
| 505 | prefs::kAlternateErrorPagesEnabled, true); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 506 | |
| 507 | BrowserThread::PostTask( |
| 508 | BrowserThread::IO, FROM_HERE, |
| 509 | Bind(&DnsProbeBrowserTestIOThreadHelper::SetUpOnIOThread, |
| 510 | Unretained(helper_), |
| 511 | g_browser_process->io_thread())); |
| 512 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 513 | SetActiveBrowser(browser()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | ad35497 | 2014-07-25 18:58:20 | [diff] [blame] | 516 | void DnsProbeBrowserTest::TearDownOnMainThread() { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 517 | BrowserThread::PostTask( |
| 518 | BrowserThread::IO, FROM_HERE, |
| 519 | Bind(&DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper, |
| 520 | Unretained(helper_))); |
| 521 | |
| 522 | NetErrorTabHelper::set_state_for_testing( |
| 523 | NetErrorTabHelper::TESTING_DEFAULT); |
| 524 | } |
| 525 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 526 | void DnsProbeBrowserTest::SetActiveBrowser(Browser* browser) { |
| 527 | // If currently watching a NetErrorTabHelper, stop doing so before start |
| 528 | // watching another. |
| 529 | if (monitored_tab_helper_) { |
| 530 | monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( |
| 531 | NetErrorTabHelper::DnsProbeStatusSnoopCallback()); |
| 532 | } |
| 533 | active_browser_ = browser; |
| 534 | monitored_tab_helper_ = NetErrorTabHelper::FromWebContents( |
| 535 | active_browser_->tab_strip_model()->GetActiveWebContents()); |
| 536 | monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( |
| 537 | Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this))); |
| 538 | } |
| 539 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 540 | void DnsProbeBrowserTest::SetCorrectionServiceBroken(bool broken) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 541 | int net_error = broken ? net::ERR_NAME_NOT_RESOLVED : net::OK; |
| 542 | |
| 543 | BrowserThread::PostTask( |
| 544 | BrowserThread::IO, FROM_HERE, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 545 | Bind(&DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 546 | Unretained(helper_), |
| 547 | net_error)); |
| 548 | } |
| 549 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 550 | void DnsProbeBrowserTest::SetCorrectionServiceDelayRequests( |
| 551 | bool delay_requests) { |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 552 | BrowserThread::PostTask( |
| 553 | BrowserThread::IO, FROM_HERE, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 554 | Bind(&DnsProbeBrowserTestIOThreadHelper:: |
| 555 | SetCorrectionServiceDelayRequests, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 556 | Unretained(helper_), |
| 557 | delay_requests)); |
| 558 | } |
| 559 | |
| 560 | void DnsProbeBrowserTest::WaitForDelayedRequestDestruction() { |
| 561 | base::RunLoop run_loop; |
| 562 | BrowserThread::PostTask( |
| 563 | BrowserThread::IO, FROM_HERE, |
| 564 | Bind(&DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback, |
| 565 | Unretained(helper_), |
| 566 | base::Bind(&RunClosureOnUIThread, |
| 567 | run_loop.QuitClosure()))); |
| 568 | run_loop.Run(); |
| 569 | } |
| 570 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 571 | void DnsProbeBrowserTest::NavigateToDnsError(int num_navigations) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 572 | NavigateToURLBlockUntilNavigationsComplete( |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 573 | active_browser_, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 574 | URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 575 | num_navigations); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 576 | } |
| 577 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 578 | void DnsProbeBrowserTest::NavigateToOtherError(int num_navigations) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 579 | NavigateToURLBlockUntilNavigationsComplete( |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 580 | active_browser_, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 581 | URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_REFUSED), |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 582 | num_navigations); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | void DnsProbeBrowserTest::SetMockDnsClientRules( |
eroman | 1efc237c | 2016-12-14 00:00:45 | [diff] [blame] | 586 | MockDnsClientRule::ResultType system_result, |
| 587 | MockDnsClientRule::ResultType public_result) { |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 588 | BrowserThread::PostTask( |
| 589 | BrowserThread::IO, FROM_HERE, |
| 590 | Bind(&DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules, |
| 591 | Unretained(helper_), |
| 592 | system_result, |
| 593 | public_result)); |
| 594 | } |
| 595 | |
| 596 | void DnsProbeBrowserTest::StartDelayedProbes( |
| 597 | int expected_delayed_probe_count) { |
| 598 | BrowserThread::PostTask( |
| 599 | BrowserThread::IO, FROM_HERE, |
| 600 | Bind(&DnsProbeBrowserTestIOThreadHelper::StartDelayedProbes, |
| 601 | Unretained(helper_), |
| 602 | expected_delayed_probe_count)); |
| 603 | } |
| 604 | |
| 605 | DnsProbeStatus DnsProbeBrowserTest::WaitForSentStatus() { |
| 606 | CHECK(!awaiting_dns_probe_status_); |
| 607 | while (dns_probe_status_queue_.empty()) { |
| 608 | awaiting_dns_probe_status_ = true; |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 609 | base::RunLoop().Run(); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 610 | awaiting_dns_probe_status_ = false; |
| 611 | } |
| 612 | |
| 613 | CHECK(!dns_probe_status_queue_.empty()); |
| 614 | DnsProbeStatus status = dns_probe_status_queue_.front(); |
| 615 | dns_probe_status_queue_.pop_front(); |
| 616 | return status; |
| 617 | } |
| 618 | |
| 619 | // Check title by roundtripping to renderer, to make sure any probe results |
| 620 | // sent before this have been applied. |
| 621 | std::string DnsProbeBrowserTest::Title() { |
| 622 | std::string title; |
| 623 | |
| 624 | WebContents* contents = |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 625 | active_browser_->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 626 | |
| 627 | bool rv = content::ExecuteScriptAndExtractString( |
| 628 | contents, |
| 629 | "domAutomationController.send(document.title);", |
| 630 | &title); |
| 631 | if (!rv) |
| 632 | return ""; |
| 633 | |
| 634 | return title; |
| 635 | } |
| 636 | |
| 637 | // Check text by roundtripping to renderer, to make sure any probe results |
| 638 | // sent before this have been applied. |
| 639 | bool DnsProbeBrowserTest::PageContains(const std::string& expected) { |
| 640 | std::string text_content; |
| 641 | |
| 642 | bool rv = content::ExecuteScriptAndExtractString( |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 643 | active_browser_->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 644 | "domAutomationController.send(document.body.textContent);", |
| 645 | &text_content); |
| 646 | if (!rv) |
| 647 | return false; |
| 648 | |
| 649 | return text_content.find(expected) != std::string::npos; |
| 650 | } |
| 651 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 652 | void DnsProbeBrowserTest::ExpectDisplayingLocalErrorPage( |
| 653 | const std::string& status_text) { |
edwardjung | f3d772c | 2016-02-26 02:38:36 | [diff] [blame] | 654 | EXPECT_FALSE(PageContains("http://mock.http/title2.html")); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 655 | EXPECT_TRUE(PageContains(status_text)); |
| 656 | } |
| 657 | |
| 658 | void DnsProbeBrowserTest::ExpectDisplayingCorrections( |
| 659 | const std::string& status_text) { |
edwardjung | f3d772c | 2016-02-26 02:38:36 | [diff] [blame] | 660 | EXPECT_TRUE(PageContains("http://mock.http/title2.html")); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 661 | EXPECT_TRUE(PageContains(status_text)); |
| 662 | } |
| 663 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 664 | void DnsProbeBrowserTest::OnDnsProbeStatusSent( |
| 665 | DnsProbeStatus dns_probe_status) { |
| 666 | dns_probe_status_queue_.push_back(dns_probe_status); |
| 667 | if (awaiting_dns_probe_status_) |
ki.stfu | c4f8e24 | 2015-10-09 20:40:20 | [diff] [blame] | 668 | MessageLoop::current()->QuitWhenIdle(); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 669 | } |
| 670 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 671 | // Make sure probes don't break non-DNS error pages when corrections load. |
| 672 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsSuccess) { |
| 673 | SetCorrectionServiceBroken(false); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 674 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 675 | NavigateToOtherError(2); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 676 | ExpectDisplayingCorrections("ERR_CONNECTION_REFUSED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 679 | // Make sure probes don't break non-DNS error pages when corrections failed to |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 680 | // load. |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 681 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsFailure) { |
| 682 | SetCorrectionServiceBroken(true); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 683 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 684 | NavigateToOtherError(2); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 685 | ExpectDisplayingLocalErrorPage("ERR_CONNECTION_REFUSED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 686 | } |
| 687 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 688 | // Make sure probes don't break DNS error pages when corrections load. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 689 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 690 | NxdomainProbeResultWithWorkingCorrections) { |
| 691 | SetCorrectionServiceBroken(false); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 692 | SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); |
| 693 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 694 | NavigateToDnsError(2); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 695 | ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 696 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 697 | // One status for committing a blank page before the corrections, and one for |
| 698 | // when the error page with corrections is committed. |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 699 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
| 700 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 701 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 702 | ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 703 | |
| 704 | StartDelayedProbes(1); |
| 705 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 706 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NXDOMAIN, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 707 | WaitForSentStatus()); |
| 708 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 709 | ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 710 | } |
| 711 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 712 | // Make sure probes don't break corrections when probes complete before the |
| 713 | // corrections load. |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 714 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 715 | NxdomainProbeResultWithWorkingSlowCorrections) { |
| 716 | SetCorrectionServiceBroken(false); |
| 717 | SetCorrectionServiceDelayRequests(true); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 718 | SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); |
| 719 | |
| 720 | NavigateToDnsError(1); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 721 | // A blank page should be displayed while the corrections are loaded. |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 722 | EXPECT_EQ("", Title()); |
| 723 | |
| 724 | // A single probe should be triggered by the error page load, and it should |
| 725 | // be ignored. |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 726 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 727 | EXPECT_EQ(0, pending_status_count()); |
| 728 | EXPECT_EQ("", Title()); |
| 729 | |
| 730 | StartDelayedProbes(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 731 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NXDOMAIN, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 732 | WaitForSentStatus()); |
| 733 | EXPECT_EQ(0, pending_status_count()); |
| 734 | EXPECT_EQ("", Title()); |
| 735 | |
| 736 | content::TestNavigationObserver observer( |
| 737 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 738 | // The corrections finish loading. |
| 739 | SetCorrectionServiceDelayRequests(false); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 740 | // Wait for it to commit. |
| 741 | observer.Wait(); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 742 | ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 743 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 744 | // Committing the corections page should trigger sending the probe result |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 745 | // again. |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 746 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NXDOMAIN, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 747 | WaitForSentStatus()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 748 | ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 751 | // Make sure probes update DNS error page properly when they're supposed to. |
| 752 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 753 | NoInternetProbeResultWithBrokenCorrections) { |
| 754 | SetCorrectionServiceBroken(true); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 755 | SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, |
| 756 | MockDnsClientRule::TIMEOUT); |
| 757 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 758 | NavigateToDnsError(2); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 759 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 760 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
| 761 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 762 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 763 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 764 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 765 | ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 766 | EXPECT_EQ(0, pending_status_count()); |
| 767 | |
| 768 | StartDelayedProbes(1); |
| 769 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 770 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NO_INTERNET, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 771 | WaitForSentStatus()); |
| 772 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 773 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 774 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 775 | ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 776 | } |
| 777 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 778 | // Make sure probes don't break corrections when probes complete before the |
| 779 | // corrections request returns an error. |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 780 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 781 | NoInternetProbeResultWithSlowBrokenCorrections) { |
| 782 | SetCorrectionServiceBroken(true); |
| 783 | SetCorrectionServiceDelayRequests(true); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 784 | SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, |
| 785 | MockDnsClientRule::TIMEOUT); |
| 786 | |
| 787 | NavigateToDnsError(1); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 788 | // A blank page should be displayed while the corrections load. |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 789 | EXPECT_EQ("", Title()); |
| 790 | |
| 791 | // A single probe should be triggered by the error page load, and it should |
| 792 | // be ignored. |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 793 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 794 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 795 | EXPECT_EQ("", Title()); |
| 796 | |
| 797 | StartDelayedProbes(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 798 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NO_INTERNET, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 799 | WaitForSentStatus()); |
| 800 | EXPECT_EQ("", Title()); |
| 801 | EXPECT_EQ(0, pending_status_count()); |
| 802 | |
| 803 | content::TestNavigationObserver observer( |
| 804 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 805 | // The corrections request fails. |
| 806 | SetCorrectionServiceDelayRequests(false); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 807 | // Wait for the DNS error page to load instead. |
| 808 | observer.Wait(); |
| 809 | // The page committing should result in sending the probe results again. |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 810 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NO_INTERNET, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 811 | WaitForSentStatus()); |
| 812 | |
| 813 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 814 | ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // Double-check to make sure sync failures don't explode. |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 818 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, SyncFailureWithBrokenCorrections) { |
| 819 | SetCorrectionServiceBroken(true); |
[email protected] | a210eef9 | 2013-07-19 19:06:12 | [diff] [blame] | 820 | SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 821 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 822 | NavigateToDnsError(2); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 823 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 824 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
| 825 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 826 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 827 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 828 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 829 | ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 830 | EXPECT_EQ(0, pending_status_count()); |
| 831 | |
| 832 | StartDelayedProbes(1); |
| 833 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 834 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_INCONCLUSIVE, |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 835 | WaitForSentStatus()); |
| 836 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 837 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 838 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 839 | ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 840 | EXPECT_EQ(0, pending_status_count()); |
| 841 | } |
| 842 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 843 | // Test that pressing the stop button cancels loading corrections. |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 844 | // TODO(mmenke): Add a test for the cross process navigation case. |
| 845 | // TODO(mmenke): This test could flakily pass due to the timeout on downloading |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 846 | // the corrections. Disable that timeout for browser tests. |
| 847 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStopped) { |
| 848 | SetCorrectionServiceDelayRequests(true); |
| 849 | SetCorrectionServiceBroken(true); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 850 | SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
| 851 | |
| 852 | NavigateToDnsError(1); |
| 853 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 854 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 855 | StartDelayedProbes(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 856 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NO_INTERNET, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 857 | WaitForSentStatus()); |
| 858 | |
| 859 | EXPECT_EQ("", Title()); |
| 860 | EXPECT_EQ(0, pending_status_count()); |
| 861 | |
| 862 | chrome::Stop(browser()); |
| 863 | WaitForDelayedRequestDestruction(); |
| 864 | |
| 865 | // End up displaying a blank page. |
| 866 | EXPECT_EQ("", Title()); |
| 867 | } |
| 868 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 869 | // Test that pressing the stop button cancels the load of corrections, and |
| 870 | // receiving a probe result afterwards does not swap in a DNS error page. |
| 871 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStoppedSlowProbe) { |
| 872 | SetCorrectionServiceDelayRequests(true); |
| 873 | SetCorrectionServiceBroken(true); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 874 | SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
| 875 | |
| 876 | NavigateToDnsError(1); |
| 877 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 878 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 879 | |
| 880 | EXPECT_EQ("", Title()); |
| 881 | EXPECT_EQ(0, pending_status_count()); |
| 882 | |
| 883 | chrome::Stop(browser()); |
| 884 | WaitForDelayedRequestDestruction(); |
| 885 | |
| 886 | EXPECT_EQ("", Title()); |
| 887 | EXPECT_EQ(0, pending_status_count()); |
| 888 | |
| 889 | StartDelayedProbes(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 890 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NO_INTERNET, |
[email protected] | 3a62199 | 2013-11-27 19:51:47 | [diff] [blame] | 891 | WaitForSentStatus()); |
| 892 | |
| 893 | EXPECT_EQ("", Title()); |
| 894 | } |
| 895 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 896 | // Make sure probes don't run for subframe DNS errors. |
| 897 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, NoProbeInSubframe) { |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 898 | SetCorrectionServiceBroken(false); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 899 | |
tfarina | 5e7b5723 | 2015-10-17 23:37:40 | [diff] [blame] | 900 | NavigateToURL(browser(), |
| 901 | URLRequestMockHTTPJob::GetMockUrl("iframe_dns_error.html")); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 902 | |
| 903 | // By the time NavigateToURL returns, the browser will have seen the failed |
| 904 | // provisional load. If a probe was started (or considered but not run), |
| 905 | // then the NetErrorTabHelper would have sent a NetErrorInfo message. Thus, |
| 906 | // if one hasn't been sent by now, the NetErrorTabHelper has not (and won't) |
| 907 | // start a probe for this DNS error. |
| 908 | EXPECT_EQ(0, pending_status_count()); |
| 909 | } |
| 910 | |
| 911 | // Make sure browser sends NOT_RUN properly when probes are disabled. |
| 912 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, ProbesDisabled) { |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 913 | // Disable probes (And corrections). |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 914 | browser()->profile()->GetPrefs()->SetBoolean( |
| 915 | prefs::kAlternateErrorPagesEnabled, false); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 916 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 917 | SetCorrectionServiceBroken(true); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 918 | SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 919 | |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 920 | NavigateToDnsError(1); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 921 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 922 | EXPECT_EQ(error_page::DNS_PROBE_NOT_RUN, WaitForSentStatus()); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 923 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 924 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 925 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 926 | ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 929 | // Test the case that corrections are disabled, but DNS probes are enabled. |
| 930 | // This is the case with Chromium builds. |
| 931 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsDisabled) { |
| 932 | // Disable corrections. |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 933 | browser()->profile()->GetPrefs()->SetBoolean( |
| 934 | prefs::kAlternateErrorPagesEnabled, false); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 935 | // Requests to the correction service should work if any are made, so the test |
| 936 | // fails if that happens unexpectedly. |
| 937 | SetCorrectionServiceBroken(false); |
| 938 | // Normally disabling corrections disables DNS probes, so force DNS probes |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 939 | // to be enabled. |
| 940 | NetErrorTabHelper::set_state_for_testing( |
| 941 | NetErrorTabHelper::TESTING_FORCE_ENABLED); |
| 942 | |
| 943 | SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
| 944 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 945 | // Just one commit and one sent status, since corrections are disabled. |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 946 | NavigateToDnsError(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 947 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 948 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 949 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 950 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 951 | ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 952 | EXPECT_EQ(0, pending_status_count()); |
| 953 | |
| 954 | StartDelayedProbes(1); |
| 955 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 956 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_INCONCLUSIVE, |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 957 | WaitForSentStatus()); |
| 958 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 959 | ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 960 | } |
| 961 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 962 | // Test incognito mode. Corrections should be disabled, but DNS probes are |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 963 | // still enabled. |
| 964 | IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, Incognito) { |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 965 | // Requests to the correction service should work if any are made, so the test |
| 966 | // will fail if one is requested unexpectedly. |
| 967 | SetCorrectionServiceBroken(false); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 968 | |
| 969 | Browser* incognito = CreateIncognitoBrowser(); |
| 970 | SetActiveBrowser(incognito); |
| 971 | |
| 972 | SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
| 973 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 974 | // Just one commit and one sent status, since the corrections are disabled. |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 975 | NavigateToDnsError(1); |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 976 | EXPECT_EQ(error_page::DNS_PROBE_STARTED, WaitForSentStatus()); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 977 | |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 978 | // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 979 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 980 | ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 981 | EXPECT_EQ(0, pending_status_count()); |
| 982 | |
| 983 | StartDelayedProbes(1); |
| 984 | |
thestig | 4b0b0165 | 2015-08-18 20:36:39 | [diff] [blame] | 985 | EXPECT_EQ(error_page::DNS_PROBE_FINISHED_INCONCLUSIVE, |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 986 | WaitForSentStatus()); |
| 987 | EXPECT_EQ(0, pending_status_count()); |
[email protected] | 26bd3893c | 2014-04-15 18:59:58 | [diff] [blame] | 988 | ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
[email protected] | d8574df | 2013-11-22 00:11:52 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | 2ea1efe | 2013-07-17 05:23:13 | [diff] [blame] | 991 | } // namespace |
| 992 | |
| 993 | } // namespace chrome_browser_net |