| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/automation/url_request_mock_net_error_job.h" | 5 #include "chrome/browser/automation/url_request_mock_net_error_job.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 URLRequestJob* URLRequestMockNetErrorJob::Factory(URLRequest* request, | 41 URLRequestJob* URLRequestMockNetErrorJob::Factory(URLRequest* request, |
| 42 const std::string& scheme) { | 42 const std::string& scheme) { |
| 43 GURL url = request->url(); | 43 GURL url = request->url(); |
| 44 | 44 |
| 45 URLMockInfoMap::const_iterator iter = url_mock_info_map_.find(url); | 45 URLMockInfoMap::const_iterator iter = url_mock_info_map_.find(url); |
| 46 DCHECK(iter != url_mock_info_map_.end()); | 46 DCHECK(iter != url_mock_info_map_.end()); |
| 47 | 47 |
| 48 MockInfo mock_info = iter->second; | 48 MockInfo mock_info = iter->second; |
| 49 URLRequestMockNetErrorJob* job = | |
| 50 new URLRequestMockNetErrorJob(request, mock_info.errors, | |
| 51 mock_info.ssl_cert); | |
| 52 | 49 |
| 53 // URLRequestMockNetErrorJob derives from URLRequestFileJob. We set the | 50 // URLRequestMockNetErrorJob derives from URLRequestFileJob. We pass a |
| 54 // file_path_ of the job so that the URLRequestFileJob methods will do the | 51 // FilePath so that the URLRequestFileJob methods will do the loading from |
| 55 // loading from the files. | 52 // the files. |
| 56 std::wstring file_url(L"file:///"); | 53 std::wstring file_url(L"file:///"); |
| 57 file_url.append(mock_info.base); | 54 file_url.append(mock_info.base); |
| 58 file_url.append(UTF8ToWide(url.path())); | 55 file_url.append(UTF8ToWide(url.path())); |
| 59 // Convert the file:/// URL to a path on disk. | 56 // Convert the file:/// URL to a path on disk. |
| 60 std::wstring file_path; | 57 std::wstring file_path; |
| 61 net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path); | 58 net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path); |
| 62 job->file_path_ = FilePath::FromWStringHack(file_path); | 59 return new URLRequestMockNetErrorJob(request, mock_info.errors, |
| 63 return job; | 60 mock_info.ssl_cert, |
| 61 FilePath::FromWStringHack(file_path)); |
| 64 } | 62 } |
| 65 | 63 |
| 66 URLRequestMockNetErrorJob::URLRequestMockNetErrorJob(URLRequest* request, | 64 URLRequestMockNetErrorJob::URLRequestMockNetErrorJob(URLRequest* request, |
| 67 const std::vector<int>& errors, net::X509Certificate* cert) | 65 const std::vector<int>& errors, net::X509Certificate* cert, |
| 68 : URLRequestMockHTTPJob(request), | 66 const FilePath& file_path) |
| 67 : URLRequestMockHTTPJob(request, file_path), |
| 69 errors_(errors), | 68 errors_(errors), |
| 70 ssl_cert_(cert) { | 69 ssl_cert_(cert) { |
| 71 } | 70 } |
| 72 | 71 |
| 73 URLRequestMockNetErrorJob::~URLRequestMockNetErrorJob() { | 72 URLRequestMockNetErrorJob::~URLRequestMockNetErrorJob() { |
| 74 } | 73 } |
| 75 | 74 |
| 76 void URLRequestMockNetErrorJob::Start() { | 75 void URLRequestMockNetErrorJob::Start() { |
| 77 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 76 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 78 this, &URLRequestMockNetErrorJob::StartAsync)); | 77 this, &URLRequestMockNetErrorJob::StartAsync)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 } else { | 91 } else { |
| 93 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); | 92 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 } | 95 } |
| 97 | 96 |
| 98 void URLRequestMockNetErrorJob::ContinueDespiteLastError() { | 97 void URLRequestMockNetErrorJob::ContinueDespiteLastError() { |
| 99 Start(); | 98 Start(); |
| 100 } | 99 } |
| 101 | 100 |
| OLD | NEW |