OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/google_apis/base_requests.h" | 5 #include "chrome/browser/google_apis/base_requests.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "chrome/browser/google_apis/auth_service.h" | 12 #include "chrome/browser/google_apis/auth_service.h" |
12 #include "chrome/browser/google_apis/request_sender.h" | 13 #include "chrome/browser/google_apis/request_sender.h" |
13 #include "chrome/browser/google_apis/task_util.h" | 14 #include "chrome/browser/google_apis/task_util.h" |
14 #include "chrome/browser/google_apis/test_util.h" | 15 #include "chrome/browser/google_apis/test_util.h" |
15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
16 #include "content/public/browser/browser_thread.h" | |
17 #include "content/public/test/test_browser_thread_bundle.h" | |
18 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
19 #include "net/test/embedded_test_server/http_request.h" | 18 #include "net/test/embedded_test_server/http_request.h" |
20 #include "net/test/embedded_test_server/http_response.h" | 19 #include "net/test/embedded_test_server/http_response.h" |
21 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 namespace google_apis { | 23 namespace google_apis { |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 const char kTestAuthToken[] = "testtoken"; | 27 const char kTestAuthToken[] = "testtoken"; |
29 const char kTestUserAgent[] = "test-user-agent"; | 28 const char kTestUserAgent[] = "test-user-agent"; |
30 | 29 |
31 } // namespace | 30 } // namespace |
32 | 31 |
33 class BaseRequestsServerTest : public testing::Test { | 32 class BaseRequestsServerTest : public testing::Test { |
34 protected: | 33 protected: |
35 BaseRequestsServerTest() | 34 BaseRequestsServerTest() |
36 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), | 35 : test_server_(message_loop_.message_loop_proxy()) { |
37 test_server_(content::BrowserThread::GetMessageLoopProxyForThread( | |
38 content::BrowserThread::IO)) { | |
39 } | 36 } |
40 | 37 |
41 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() OVERRIDE { |
42 profile_.reset(new TestingProfile); | 39 profile_.reset(new TestingProfile); |
43 | 40 |
44 request_context_getter_ = new net::TestURLRequestContextGetter( | 41 request_context_getter_ = new net::TestURLRequestContextGetter( |
45 content::BrowserThread::GetMessageLoopProxyForThread( | 42 message_loop_.message_loop_proxy()); |
46 content::BrowserThread::IO)); | |
47 | 43 |
48 request_sender_.reset(new RequestSender(profile_.get(), | 44 request_sender_.reset(new RequestSender(profile_.get(), |
49 request_context_getter_.get(), | 45 request_context_getter_.get(), |
50 std::vector<std::string>(), | 46 std::vector<std::string>(), |
51 kTestUserAgent)); | 47 kTestUserAgent)); |
52 request_sender_->auth_service()->set_access_token_for_testing( | 48 request_sender_->auth_service()->set_access_token_for_testing( |
53 kTestAuthToken); | 49 kTestAuthToken); |
54 | 50 |
55 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); | 51 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); |
56 test_server_.RegisterRequestHandler( | 52 test_server_.RegisterRequestHandler( |
57 base::Bind(&test_util::HandleDownloadFileRequest, | 53 base::Bind(&test_util::HandleDownloadFileRequest, |
58 test_server_.base_url(), | 54 test_server_.base_url(), |
59 base::Unretained(&http_request_))); | 55 base::Unretained(&http_request_))); |
60 } | 56 } |
61 | 57 |
62 // Returns a temporary file path suitable for storing the cache file. | 58 // Returns a temporary file path suitable for storing the cache file. |
63 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { | 59 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { |
64 return profile_->GetPath().Append(file_name); | 60 return profile_->GetPath().Append(file_name); |
65 } | 61 } |
66 | 62 |
67 content::TestBrowserThreadBundle thread_bundle_; | 63 base::MessageLoopForIO message_loop_; // Test server needs IO thread. |
68 net::test_server::EmbeddedTestServer test_server_; | 64 net::test_server::EmbeddedTestServer test_server_; |
69 scoped_ptr<TestingProfile> profile_; | 65 scoped_ptr<TestingProfile> profile_; |
70 scoped_ptr<RequestSender> request_sender_; | 66 scoped_ptr<RequestSender> request_sender_; |
71 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 67 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
72 | 68 |
73 // The incoming HTTP request is saved so tests can verify the request | 69 // The incoming HTTP request is saved so tests can verify the request |
74 // parameters like HTTP method (ex. some requests should use DELETE | 70 // parameters like HTTP method (ex. some requests should use DELETE |
75 // instead of GET). | 71 // instead of GET). |
76 net::test_server::HttpRequest http_request_; | 72 net::test_server::HttpRequest http_request_; |
77 }; | 73 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 run_loop.Run(); | 125 run_loop.Run(); |
130 } | 126 } |
131 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 127 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
132 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 128 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
133 EXPECT_EQ("/files/gdata/no-such-file.txt", | 129 EXPECT_EQ("/files/gdata/no-such-file.txt", |
134 http_request_.relative_url); | 130 http_request_.relative_url); |
135 // Do not verify the not found message. | 131 // Do not verify the not found message. |
136 } | 132 } |
137 | 133 |
138 } // namespace google_apis | 134 } // namespace google_apis |
OLD | NEW |