OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/google_apis/auth_service.h" | 19 #include "chrome/browser/google_apis/dummy_auth_service.h" |
20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
21 #include "chrome/browser/google_apis/gdata_wapi_requests.h" | 21 #include "chrome/browser/google_apis/gdata_wapi_requests.h" |
22 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 22 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
23 #include "chrome/browser/google_apis/request_sender.h" | 23 #include "chrome/browser/google_apis/request_sender.h" |
24 #include "chrome/browser/google_apis/test_util.h" | 24 #include "chrome/browser/google_apis/test_util.h" |
25 #include "chrome/test/base/testing_profile.h" | |
26 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 27 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 28 #include "net/test/embedded_test_server/http_response.h" |
30 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
32 | 31 |
33 namespace google_apis { | 32 namespace google_apis { |
34 | 33 |
35 namespace { | 34 namespace { |
36 | 35 |
37 const char kTestGDataAuthToken[] = "testtoken"; | |
38 const char kTestUserAgent[] = "test-user-agent"; | 36 const char kTestUserAgent[] = "test-user-agent"; |
39 const char kTestETag[] = "test_etag"; | 37 const char kTestETag[] = "test_etag"; |
40 const char kTestDownloadPathPrefix[] = "/download/"; | 38 const char kTestDownloadPathPrefix[] = "/download/"; |
41 | 39 |
42 class GDataWapiRequestsTest : public testing::Test { | 40 class GDataWapiRequestsTest : public testing::Test { |
43 public: | 41 public: |
44 GDataWapiRequestsTest() | 42 GDataWapiRequestsTest() |
45 : test_server_(message_loop_.message_loop_proxy()) { | 43 : test_server_(message_loop_.message_loop_proxy()) { |
46 } | 44 } |
47 | 45 |
48 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
49 profile_.reset(new TestingProfile); | |
50 | |
51 request_context_getter_ = new net::TestURLRequestContextGetter( | 47 request_context_getter_ = new net::TestURLRequestContextGetter( |
52 message_loop_.message_loop_proxy()); | 48 message_loop_.message_loop_proxy()); |
53 | 49 |
54 request_sender_.reset(new RequestSender(profile_.get(), | 50 request_sender_.reset(new RequestSender(new DummyAuthService, |
55 request_context_getter_.get(), | 51 request_context_getter_.get(), |
56 message_loop_.message_loop_proxy(), | 52 message_loop_.message_loop_proxy(), |
57 std::vector<std::string>(), | |
58 kTestUserAgent)); | 53 kTestUserAgent)); |
59 request_sender_->auth_service()->set_access_token_for_testing( | |
60 kTestGDataAuthToken); | |
61 | 54 |
62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 55 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
63 | 56 |
64 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); | 57 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); |
65 test_server_.RegisterRequestHandler( | 58 test_server_.RegisterRequestHandler( |
66 base::Bind(&test_util::HandleDownloadFileRequest, | 59 base::Bind(&test_util::HandleDownloadFileRequest, |
67 test_server_.base_url(), | 60 test_server_.base_url(), |
68 base::Unretained(&http_request_))); | 61 base::Unretained(&http_request_))); |
69 test_server_.RegisterRequestHandler( | 62 test_server_.RegisterRequestHandler( |
70 base::Bind(&GDataWapiRequestsTest::HandleResourceFeedRequest, | 63 base::Bind(&GDataWapiRequestsTest::HandleResourceFeedRequest, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 scoped_ptr<net::test_server::BasicHttpResponse> response( | 319 scoped_ptr<net::test_server::BasicHttpResponse> response( |
327 new net::test_server::BasicHttpResponse); | 320 new net::test_server::BasicHttpResponse); |
328 response->set_code(net::HTTP_OK); | 321 response->set_code(net::HTTP_OK); |
329 response->set_content(id + id + id); | 322 response->set_content(id + id + id); |
330 response->set_content_type("text/plain"); | 323 response->set_content_type("text/plain"); |
331 return response.PassAs<net::test_server::HttpResponse>(); | 324 return response.PassAs<net::test_server::HttpResponse>(); |
332 } | 325 } |
333 | 326 |
334 base::MessageLoopForIO message_loop_; // Test server needs IO thread. | 327 base::MessageLoopForIO message_loop_; // Test server needs IO thread. |
335 net::test_server::EmbeddedTestServer test_server_; | 328 net::test_server::EmbeddedTestServer test_server_; |
336 scoped_ptr<TestingProfile> profile_; | |
337 scoped_ptr<RequestSender> request_sender_; | 329 scoped_ptr<RequestSender> request_sender_; |
338 scoped_ptr<GDataWapiUrlGenerator> url_generator_; | 330 scoped_ptr<GDataWapiUrlGenerator> url_generator_; |
339 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 331 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
340 base::ScopedTempDir temp_dir_; | 332 base::ScopedTempDir temp_dir_; |
341 | 333 |
342 // These fields are used to keep the current upload state during a | 334 // These fields are used to keep the current upload state during a |
343 // test case. These values are updated by the request from | 335 // test case. These values are updated by the request from |
344 // ResumeUploadRequest, and used to construct the response for | 336 // ResumeUploadRequest, and used to construct the response for |
345 // both ResumeUploadRequest and GetUploadStatusRequest, to emulate | 337 // both ResumeUploadRequest and GetUploadStatusRequest, to emulate |
346 // the WAPI server. | 338 // the WAPI server. |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1584 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1593 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 1585 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
1594 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); | 1586 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); |
1595 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1587 EXPECT_EQ(kDownloadedFilePath, temp_file); |
1596 | 1588 |
1597 const std::string expected_contents = kTestId + kTestId + kTestId; | 1589 const std::string expected_contents = kTestId + kTestId + kTestId; |
1598 EXPECT_EQ(expected_contents, contents); | 1590 EXPECT_EQ(expected_contents, contents); |
1599 } | 1591 } |
1600 | 1592 |
1601 } // namespace google_apis | 1593 } // namespace google_apis |
OLD | NEW |