Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Side by Side Diff: chrome/browser/google_apis/drive_api_requests_unittest.cc

Issue 19511002: Change google_api::RequestSender to take an AuthService instead of a Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/google_apis/auth_service.h"
14 #include "chrome/browser/google_apis/drive_api_parser.h" 13 #include "chrome/browser/google_apis/drive_api_parser.h"
15 #include "chrome/browser/google_apis/drive_api_requests.h" 14 #include "chrome/browser/google_apis/drive_api_requests.h"
16 #include "chrome/browser/google_apis/drive_api_url_generator.h" 15 #include "chrome/browser/google_apis/drive_api_url_generator.h"
16 #include "chrome/browser/google_apis/dummy_auth_service.h"
17 #include "chrome/browser/google_apis/request_sender.h" 17 #include "chrome/browser/google_apis/request_sender.h"
18 #include "chrome/browser/google_apis/test_util.h" 18 #include "chrome/browser/google_apis/test_util.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 19 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "net/test/embedded_test_server/http_request.h" 20 #include "net/test/embedded_test_server/http_request.h"
22 #include "net/test/embedded_test_server/http_response.h" 21 #include "net/test/embedded_test_server/http_response.h"
23 #include "net/url_request/url_request_test_util.h" 22 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
26 namespace google_apis { 25 namespace google_apis {
27 26
28 namespace { 27 namespace {
29 28
30 const char kTestDriveApiAuthToken[] = "testtoken";
31 const char kTestETag[] = "test_etag"; 29 const char kTestETag[] = "test_etag";
32 const char kTestUserAgent[] = "test-user-agent"; 30 const char kTestUserAgent[] = "test-user-agent";
33 31
34 const char kTestChildrenResponse[] = 32 const char kTestChildrenResponse[] =
35 "{\n" 33 "{\n"
36 "\"kind\": \"drive#childReference\",\n" 34 "\"kind\": \"drive#childReference\",\n"
37 "\"id\": \"resource_id\",\n" 35 "\"id\": \"resource_id\",\n"
38 "\"selfLink\": \"self_link\",\n" 36 "\"selfLink\": \"self_link\",\n"
39 "\"childLink\": \"child_link\",\n" 37 "\"childLink\": \"child_link\",\n"
40 "}\n"; 38 "}\n";
41 39
42 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path"; 40 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path";
43 const char kTestUploadNewFilePath[] = "/upload/newfile/path"; 41 const char kTestUploadNewFilePath[] = "/upload/newfile/path";
44 const char kTestDownloadPathPrefix[] = "/download/"; 42 const char kTestDownloadPathPrefix[] = "/download/";
45 43
46 } // namespace 44 } // namespace
47 45
48 class DriveApiRequestsTest : public testing::Test { 46 class DriveApiRequestsTest : public testing::Test {
49 public: 47 public:
50 DriveApiRequestsTest() 48 DriveApiRequestsTest()
51 : test_server_(message_loop_.message_loop_proxy()) { 49 : test_server_(message_loop_.message_loop_proxy()) {
52 } 50 }
53 51
54 virtual void SetUp() OVERRIDE { 52 virtual void SetUp() OVERRIDE {
55 profile_.reset(new TestingProfile);
56
57 request_context_getter_ = new net::TestURLRequestContextGetter( 53 request_context_getter_ = new net::TestURLRequestContextGetter(
58 message_loop_.message_loop_proxy()); 54 message_loop_.message_loop_proxy());
59 55
60 request_sender_.reset(new RequestSender(profile_.get(), 56 request_sender_.reset(new RequestSender(new DummyAuthService,
61 request_context_getter_.get(), 57 request_context_getter_.get(),
62 message_loop_.message_loop_proxy(), 58 message_loop_.message_loop_proxy(),
63 std::vector<std::string>(),
64 kTestUserAgent)); 59 kTestUserAgent));
65 request_sender_->auth_service()->set_access_token_for_testing(
66 kTestDriveApiAuthToken);
67 60
68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
69 62
70 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); 63 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
71 test_server_.RegisterRequestHandler( 64 test_server_.RegisterRequestHandler(
72 base::Bind(&DriveApiRequestsTest::HandleChildrenDeleteRequest, 65 base::Bind(&DriveApiRequestsTest::HandleChildrenDeleteRequest,
73 base::Unretained(this))); 66 base::Unretained(this)));
74 test_server_.RegisterRequestHandler( 67 test_server_.RegisterRequestHandler(
75 base::Bind(&DriveApiRequestsTest::HandleDataFileRequest, 68 base::Bind(&DriveApiRequestsTest::HandleDataFileRequest,
76 base::Unretained(this))); 69 base::Unretained(this)));
(...skipping 15 matching lines...) Expand all
92 test_base_url, test_base_url.Resolve(kTestDownloadPathPrefix))); 85 test_base_url, test_base_url.Resolve(kTestDownloadPathPrefix)));
93 86
94 // Reset the server's expected behavior just in case. 87 // Reset the server's expected behavior just in case.
95 ResetExpectedResponse(); 88 ResetExpectedResponse();
96 received_bytes_ = 0; 89 received_bytes_ = 0;
97 content_length_ = 0; 90 content_length_ = 0;
98 } 91 }
99 92
100 base::MessageLoopForIO message_loop_; // Test server needs IO thread. 93 base::MessageLoopForIO message_loop_; // Test server needs IO thread.
101 net::test_server::EmbeddedTestServer test_server_; 94 net::test_server::EmbeddedTestServer test_server_;
102 scoped_ptr<TestingProfile> profile_;
103 scoped_ptr<RequestSender> request_sender_; 95 scoped_ptr<RequestSender> request_sender_;
104 scoped_ptr<DriveApiUrlGenerator> url_generator_; 96 scoped_ptr<DriveApiUrlGenerator> url_generator_;
105 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; 97 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
106 base::ScopedTempDir temp_dir_; 98 base::ScopedTempDir temp_dir_;
107 99
108 // This is a path to the file which contains expected response from 100 // This is a path to the file which contains expected response from
109 // the server. See also HandleDataFileRequest below. 101 // the server. See also HandleDataFileRequest below.
110 base::FilePath expected_data_file_path_; 102 base::FilePath expected_data_file_path_;
111 103
112 // This is a path string in the expected response header from the server 104 // This is a path string in the expected response header from the server
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 EXPECT_EQ(HTTP_SUCCESS, result_code); 1381 EXPECT_EQ(HTTP_SUCCESS, result_code);
1390 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 1382 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
1391 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); 1383 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url);
1392 EXPECT_EQ(kDownloadedFilePath, temp_file); 1384 EXPECT_EQ(kDownloadedFilePath, temp_file);
1393 1385
1394 const std::string expected_contents = kTestId + kTestId + kTestId; 1386 const std::string expected_contents = kTestId + kTestId + kTestId;
1395 EXPECT_EQ(expected_contents, contents); 1387 EXPECT_EQ(expected_contents, contents);
1396 } 1388 }
1397 1389
1398 } // namespace google_apis 1390 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/base_requests_unittest.cc ('k') | chrome/browser/google_apis/dummy_auth_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698