| OLD | NEW | 
|    1 // Copyright 2013 The Chromium Authors. All rights reserved. |    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 |    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/safe_browsing/download_feedback_service.h" |    5 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 
|    6  |    6  | 
|    7 #include <vector> |    7 #include <vector> | 
|    8  |    8  | 
|    9 #include "base/files/file_util.h" |    9 #include "base/files/file_util.h" | 
|   10 #include "base/files/scoped_temp_dir.h" |   10 #include "base/files/scoped_temp_dir.h" | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|   37       : ping_request_(ping_request), |   37       : ping_request_(ping_request), | 
|   38         ping_response_(ping_response), |   38         ping_response_(ping_response), | 
|   39         deletion_callback_(deletion_callback), |   39         deletion_callback_(deletion_callback), | 
|   40         start_called_(false) { |   40         start_called_(false) { | 
|   41   } |   41   } | 
|   42  |   42  | 
|   43   virtual ~FakeDownloadFeedback() { |   43   virtual ~FakeDownloadFeedback() { | 
|   44     deletion_callback_.Run(); |   44     deletion_callback_.Run(); | 
|   45   } |   45   } | 
|   46  |   46  | 
|   47   virtual void Start(const base::Closure& finish_callback) OVERRIDE { |   47   virtual void Start(const base::Closure& finish_callback) override { | 
|   48     start_called_ = true; |   48     start_called_ = true; | 
|   49     finish_callback_ = finish_callback; |   49     finish_callback_ = finish_callback; | 
|   50   } |   50   } | 
|   51  |   51  | 
|   52   virtual const std::string& GetPingRequestForTesting() const OVERRIDE { |   52   virtual const std::string& GetPingRequestForTesting() const override { | 
|   53     return ping_request_; |   53     return ping_request_; | 
|   54   } |   54   } | 
|   55  |   55  | 
|   56   virtual const std::string& GetPingResponseForTesting() const OVERRIDE { |   56   virtual const std::string& GetPingResponseForTesting() const override { | 
|   57     return ping_response_; |   57     return ping_response_; | 
|   58   } |   58   } | 
|   59  |   59  | 
|   60   base::Closure finish_callback() const { |   60   base::Closure finish_callback() const { | 
|   61     return finish_callback_; |   61     return finish_callback_; | 
|   62   } |   62   } | 
|   63  |   63  | 
|   64   bool start_called() const { |   64   bool start_called() const { | 
|   65     return start_called_; |   65     return start_called_; | 
|   66   } |   66   } | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   79  |   79  | 
|   80 class FakeDownloadFeedbackFactory : public DownloadFeedbackFactory { |   80 class FakeDownloadFeedbackFactory : public DownloadFeedbackFactory { | 
|   81  public: |   81  public: | 
|   82   virtual ~FakeDownloadFeedbackFactory() {} |   82   virtual ~FakeDownloadFeedbackFactory() {} | 
|   83  |   83  | 
|   84   virtual DownloadFeedback* CreateDownloadFeedback( |   84   virtual DownloadFeedback* CreateDownloadFeedback( | 
|   85       net::URLRequestContextGetter* request_context_getter, |   85       net::URLRequestContextGetter* request_context_getter, | 
|   86       base::TaskRunner* file_task_runner, |   86       base::TaskRunner* file_task_runner, | 
|   87       const base::FilePath& file_path, |   87       const base::FilePath& file_path, | 
|   88       const std::string& ping_request, |   88       const std::string& ping_request, | 
|   89       const std::string& ping_response) OVERRIDE { |   89       const std::string& ping_response) override { | 
|   90     FakeDownloadFeedback* feedback = new FakeDownloadFeedback( |   90     FakeDownloadFeedback* feedback = new FakeDownloadFeedback( | 
|   91         request_context_getter, |   91         request_context_getter, | 
|   92         file_task_runner, |   92         file_task_runner, | 
|   93         file_path, |   93         file_path, | 
|   94         ping_request, |   94         ping_request, | 
|   95         ping_response, |   95         ping_response, | 
|   96         base::Bind(&FakeDownloadFeedbackFactory::DownloadFeedbackDeleted, |   96         base::Bind(&FakeDownloadFeedbackFactory::DownloadFeedbackDeleted, | 
|   97                    base::Unretained(this), |   97                    base::Unretained(this), | 
|   98                    feedbacks_.size())); |   98                    feedbacks_.size())); | 
|   99     feedbacks_.push_back(feedback); |   99     feedbacks_.push_back(feedback); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  132  public: |  132  public: | 
|  133   DownloadFeedbackServiceTest() |  133   DownloadFeedbackServiceTest() | 
|  134       : file_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |  134       : file_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | 
|  135             content::BrowserThread::FILE)), |  135             content::BrowserThread::FILE)), | 
|  136         io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |  136         io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | 
|  137             content::BrowserThread::IO)), |  137             content::BrowserThread::IO)), | 
|  138         request_context_getter_( |  138         request_context_getter_( | 
|  139             new net::TestURLRequestContextGetter(io_task_runner_)) { |  139             new net::TestURLRequestContextGetter(io_task_runner_)) { | 
|  140   } |  140   } | 
|  141  |  141  | 
|  142   virtual void SetUp() OVERRIDE { |  142   virtual void SetUp() override { | 
|  143     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |  143     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 
|  144     DownloadFeedback::RegisterFactory(&download_feedback_factory_); |  144     DownloadFeedback::RegisterFactory(&download_feedback_factory_); | 
|  145   } |  145   } | 
|  146  |  146  | 
|  147   virtual void TearDown() OVERRIDE { |  147   virtual void TearDown() override { | 
|  148     DownloadFeedback::RegisterFactory(NULL); |  148     DownloadFeedback::RegisterFactory(NULL); | 
|  149   } |  149   } | 
|  150  |  150  | 
|  151   base::FilePath CreateTestFile(int n) const { |  151   base::FilePath CreateTestFile(int n) const { | 
|  152     base::FilePath upload_file_path( |  152     base::FilePath upload_file_path( | 
|  153         temp_dir_.path().AppendASCII("test file " + base::IntToString(n))); |  153         temp_dir_.path().AppendASCII("test file " + base::IntToString(n))); | 
|  154     const std::string upload_file_data = "data"; |  154     const std::string upload_file_data = "data"; | 
|  155     int wrote = base::WriteFile( |  155     int wrote = base::WriteFile( | 
|  156         upload_file_path, upload_file_data.data(), upload_file_data.size()); |  156         upload_file_path, upload_file_data.data(), upload_file_data.size()); | 
|  157     EXPECT_EQ(static_cast<int>(upload_file_data.size()), wrote); |  157     EXPECT_EQ(static_cast<int>(upload_file_data.size()), wrote); | 
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  366   // was deleted. |  366   // was deleted. | 
|  367   EXPECT_FALSE(base::PathExists(file_path[2])); |  367   EXPECT_FALSE(base::PathExists(file_path[2])); | 
|  368  |  368  | 
|  369   // These files should still exist since the FakeDownloadFeedback does not |  369   // These files should still exist since the FakeDownloadFeedback does not | 
|  370   // delete them. |  370   // delete them. | 
|  371   EXPECT_TRUE(base::PathExists(file_path[0])); |  371   EXPECT_TRUE(base::PathExists(file_path[0])); | 
|  372   EXPECT_TRUE(base::PathExists(file_path[1])); |  372   EXPECT_TRUE(base::PathExists(file_path[1])); | 
|  373 } |  373 } | 
|  374  |  374  | 
|  375 }  // namespace safe_browsing |  375 }  // namespace safe_browsing | 
| OLD | NEW |