| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/component_updater/component_updater_interceptor.h" | 4 #include "chrome/browser/component_updater/component_updater_interceptor.h" |
| 5 | 5 |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/threading/thread_restrictions.h" | 7 #include "base/threading/thread_restrictions.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "net/url_request/url_request.h" |
| 10 #include "net/url_request/url_request_context.h" |
| 9 #include "net/url_request/url_request_test_job.h" | 11 #include "net/url_request/url_request_test_job.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 using content::BrowserThread; | 14 using content::BrowserThread; |
| 13 | 15 |
| 14 ComponentUpdateInterceptor::ComponentUpdateInterceptor() | 16 ComponentUpdateInterceptor::ComponentUpdateInterceptor() |
| 15 : hit_count_(0) { | 17 : hit_count_(0) { |
| 16 net::URLRequest::Deprecated::RegisterRequestInterceptor(this); | 18 net::URLRequest::Deprecated::RegisterRequestInterceptor(this); |
| 17 } | 19 } |
| 18 | 20 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 36 if (it == responses_.end()) { | 38 if (it == responses_.end()) { |
| 37 return NULL; | 39 return NULL; |
| 38 } | 40 } |
| 39 const Response& response = it->second; | 41 const Response& response = it->second; |
| 40 ++hit_count_; | 42 ++hit_count_; |
| 41 | 43 |
| 42 std::string contents; | 44 std::string contents; |
| 43 EXPECT_TRUE(file_util::ReadFileToString(response.data_path, &contents)); | 45 EXPECT_TRUE(file_util::ReadFileToString(response.data_path, &contents)); |
| 44 | 46 |
| 45 return new net::URLRequestTestJob(request, | 47 return new net::URLRequestTestJob(request, |
| 48 request->context()->network_delegate(), |
| 46 response.headers, | 49 response.headers, |
| 47 contents, | 50 contents, |
| 48 true); | 51 true); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void ComponentUpdateInterceptor::SetResponse(const std::string& url, | 54 void ComponentUpdateInterceptor::SetResponse(const std::string& url, |
| 52 const std::string& headers, | 55 const std::string& headers, |
| 53 const FilePath& path) { | 56 const FilePath& path) { |
| 54 // It's ok to do a blocking disk access on this thread; this class | 57 // It's ok to do a blocking disk access on this thread; this class |
| 55 // is just used for tests. | 58 // is just used for tests. |
| 56 base::ThreadRestrictions::ScopedAllowIO allow_io; | 59 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 57 GURL gurl(url); | 60 GURL gurl(url); |
| 58 EXPECT_EQ("http", gurl.scheme()); | 61 EXPECT_EQ("http", gurl.scheme()); |
| 59 EXPECT_EQ("localhost", gurl.host()); | 62 EXPECT_EQ("localhost", gurl.host()); |
| 60 EXPECT_TRUE(file_util::PathExists(path)); | 63 EXPECT_TRUE(file_util::PathExists(path)); |
| 61 Response response = { path, headers }; | 64 Response response = { path, headers }; |
| 62 responses_[gurl] = response; | 65 responses_[gurl] = response; |
| 63 } | 66 } |
| OLD | NEW |