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/two_phase_uploader.h" | 5 #include "chrome/browser/safe_browsing/two_phase_uploader.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/safe_browsing/local_two_phase_testserver.h" | 9 #include "chrome/browser/safe_browsing/local_two_phase_testserver.h" |
10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
14 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 using content::MessageLoopRunner; | 18 using content::MessageLoopRunner; |
19 | 19 |
20 namespace { | 20 namespace { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 file_path = file_path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 52 file_path = file_path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
53 file_path = file_path.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); | 53 file_path = file_path.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); |
54 return file_path; | 54 return file_path; |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 class TwoPhaseUploaderTest : public testing::Test { | 59 class TwoPhaseUploaderTest : public testing::Test { |
60 public: | 60 public: |
61 TwoPhaseUploaderTest() | 61 TwoPhaseUploaderTest() |
62 : db_thread_(BrowserThread::DB), | 62 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
63 io_thread_(BrowserThread::IO, &message_loop_), | |
64 url_request_context_getter_(new net::TestURLRequestContextGetter( | 63 url_request_context_getter_(new net::TestURLRequestContextGetter( |
65 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { | 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { |
66 } | 65 } |
67 | 66 |
68 virtual void SetUp() { | |
69 db_thread_.Start(); | |
70 } | |
71 | |
72 protected: | 67 protected: |
73 base::MessageLoopForIO message_loop_; | 68 content::TestBrowserThreadBundle thread_bundle_; |
74 content::TestBrowserThread db_thread_; | |
75 content::TestBrowserThread io_thread_; | |
76 | 69 |
77 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 70 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
78 }; | 71 }; |
79 | 72 |
80 TEST_F(TwoPhaseUploaderTest, UploadFile) { | 73 TEST_F(TwoPhaseUploaderTest, UploadFile) { |
81 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; | 74 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; |
82 LocalTwoPhaseTestServer test_server; | 75 LocalTwoPhaseTestServer test_server; |
83 ASSERT_TRUE(test_server.Start()); | 76 ASSERT_TRUE(test_server.Start()); |
84 Delegate delegate; | 77 Delegate delegate; |
85 scoped_ptr<TwoPhaseUploader> uploader(TwoPhaseUploader::Create( | 78 scoped_ptr<TwoPhaseUploader> uploader(TwoPhaseUploader::Create( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), | 180 base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), |
188 base::Bind( | 181 base::Bind( |
189 &Delegate::FinishCallback, base::Unretained(&delegate), runner))); | 182 &Delegate::FinishCallback, base::Unretained(&delegate), runner))); |
190 uploader->Start(); | 183 uploader->Start(); |
191 runner->Run(); | 184 runner->Run(); |
192 EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_); | 185 EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_); |
193 EXPECT_EQ(net::ERR_EMPTY_RESPONSE, delegate.net_error_); | 186 EXPECT_EQ(net::ERR_EMPTY_RESPONSE, delegate.net_error_); |
194 EXPECT_EQ(net::URLFetcher::RESPONSE_CODE_INVALID, delegate.response_code_); | 187 EXPECT_EQ(net::URLFetcher::RESPONSE_CODE_INVALID, delegate.response_code_); |
195 EXPECT_EQ("", delegate.response_); | 188 EXPECT_EQ("", delegate.response_); |
196 } | 189 } |
OLD | NEW |