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 "chrome/browser/chromeos/contacts/gdata_contacts_service.h" | 5 #include "chrome/browser/chromeos/contacts/gdata_contacts_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 12 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
13 #include "chrome/browser/chromeos/contacts/contact_test_util.h" | 13 #include "chrome/browser/chromeos/contacts/contact_test_util.h" |
14 #include "chrome/browser/google_apis/auth_service.h" | 14 #include "chrome/browser/google_apis/dummy_auth_service.h" |
15 #include "chrome/browser/google_apis/test_util.h" | 15 #include "chrome/browser/google_apis/test_util.h" |
16 #include "chrome/browser/google_apis/time_util.h" | 16 #include "chrome/browser/google_apis/time_util.h" |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/testing_profile.h" | |
21 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
23 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
24 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
25 #include "net/test/embedded_test_server/http_request.h" | 23 #include "net/test/embedded_test_server/http_request.h" |
26 #include "net/test/embedded_test_server/http_response.h" | 24 #include "net/test/embedded_test_server/http_response.h" |
27 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
30 | 28 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 class GDataContactsServiceTest : public testing::Test { | 69 class GDataContactsServiceTest : public testing::Test { |
72 public: | 70 public: |
73 GDataContactsServiceTest() | 71 GDataContactsServiceTest() |
74 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 72 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
75 io_thread_(content::BrowserThread::IO), | 73 io_thread_(content::BrowserThread::IO), |
76 download_was_successful_(false) { | 74 download_was_successful_(false) { |
77 } | 75 } |
78 | 76 |
79 virtual void SetUp() OVERRIDE { | 77 virtual void SetUp() OVERRIDE { |
80 io_thread_.StartIOThread(); | 78 io_thread_.StartIOThread(); |
81 profile_.reset(new TestingProfile); | |
82 request_context_getter_ = new net::TestURLRequestContextGetter( | 79 request_context_getter_ = new net::TestURLRequestContextGetter( |
83 content::BrowserThread::GetMessageLoopProxyForThread( | 80 content::BrowserThread::GetMessageLoopProxyForThread( |
84 content::BrowserThread::IO)); | 81 content::BrowserThread::IO)); |
85 | 82 |
86 test_server_.reset( | 83 test_server_.reset( |
87 new net::test_server::EmbeddedTestServer( | 84 new net::test_server::EmbeddedTestServer( |
88 content::BrowserThread::GetMessageLoopProxyForThread( | 85 content::BrowserThread::GetMessageLoopProxyForThread( |
89 content::BrowserThread::IO))); | 86 content::BrowserThread::IO))); |
90 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); | 87 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); |
91 test_server_->RegisterRequestHandler( | 88 test_server_->RegisterRequestHandler( |
92 base::Bind(&GDataContactsServiceTest::HandleDownloadRequest, | 89 base::Bind(&GDataContactsServiceTest::HandleDownloadRequest, |
93 base::Unretained(this))); | 90 base::Unretained(this))); |
94 service_.reset(new GDataContactsService(request_context_getter_.get(), | 91 service_.reset(new GDataContactsService(request_context_getter_.get(), |
95 profile_.get())); | 92 new google_apis::DummyAuthService)); |
96 service_->Initialize(); | |
97 service_->auth_service_for_testing()->set_access_token_for_testing( | |
98 kTestGDataAuthToken); | |
99 service_->set_rewrite_photo_url_callback_for_testing( | 93 service_->set_rewrite_photo_url_callback_for_testing( |
100 base::Bind(&GDataContactsServiceTest::RewritePhotoUrl, | 94 base::Bind(&GDataContactsServiceTest::RewritePhotoUrl, |
101 base::Unretained(this))); | 95 base::Unretained(this))); |
102 service_->set_groups_feed_url_for_testing( | 96 service_->set_groups_feed_url_for_testing( |
103 test_server_->GetURL(kGroupsFeedFilename)); | 97 test_server_->GetURL(kGroupsFeedFilename)); |
104 service_->set_photo_download_timer_interval_for_testing( | 98 service_->set_photo_download_timer_interval_for_testing( |
105 base::TimeDelta::FromMilliseconds(10)); | 99 base::TimeDelta::FromMilliseconds(10)); |
106 } | 100 } |
107 | 101 |
108 virtual void TearDown() OVERRIDE { | 102 virtual void TearDown() OVERRIDE { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 scoped_ptr<net::test_server::BasicHttpResponse> result = | 163 scoped_ptr<net::test_server::BasicHttpResponse> result = |
170 google_apis::test_util::CreateHttpResponseFromFile( | 164 google_apis::test_util::CreateHttpResponseFromFile( |
171 google_apis::test_util::GetTestFilePath( | 165 google_apis::test_util::GetTestFilePath( |
172 std::string("chromeos/gdata/contacts") + request.relative_url)); | 166 std::string("chromeos/gdata/contacts") + request.relative_url)); |
173 return result.PassAs<net::test_server::HttpResponse>(); | 167 return result.PassAs<net::test_server::HttpResponse>(); |
174 } | 168 } |
175 | 169 |
176 base::MessageLoopForUI message_loop_; | 170 base::MessageLoopForUI message_loop_; |
177 content::TestBrowserThread ui_thread_; | 171 content::TestBrowserThread ui_thread_; |
178 content::TestBrowserThread io_thread_; | 172 content::TestBrowserThread io_thread_; |
179 scoped_ptr<TestingProfile> profile_; | |
180 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 173 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
181 | 174 |
182 // Was the last download successful? Used to pass the result back from | 175 // Was the last download successful? Used to pass the result back from |
183 // OnSuccess() and OnFailure() to Download(). | 176 // OnSuccess() and OnFailure() to Download(). |
184 bool download_was_successful_; | 177 bool download_was_successful_; |
185 | 178 |
186 // Used to pass downloaded contacts back to Download(). | 179 // Used to pass downloaded contacts back to Download(). |
187 scoped_ptr<ScopedVector<contacts::Contact> > downloaded_contacts_; | 180 scoped_ptr<ScopedVector<contacts::Contact> > downloaded_contacts_; |
188 }; | 181 }; |
189 | 182 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 scoped_ptr<contacts::Contact> contact2(new contacts::Contact); | 328 scoped_ptr<contacts::Contact> contact2(new contacts::Contact); |
336 InitContact("http://example.com/2", "2012-06-21T16:20:13.208Z", | 329 InitContact("http://example.com/2", "2012-06-21T16:20:13.208Z", |
337 false, "Bob Smith", "Bob", "", "Smith", "", "", | 330 false, "Bob Smith", "Bob", "", "Smith", "", "", |
338 contact2.get()); | 331 contact2.get()); |
339 EXPECT_EQ(contacts::test::VarContactsToString( | 332 EXPECT_EQ(contacts::test::VarContactsToString( |
340 2, contact1.get(), contact2.get()), | 333 2, contact1.get(), contact2.get()), |
341 contacts::test::ContactsToString(*contacts)); | 334 contacts::test::ContactsToString(*contacts)); |
342 } | 335 } |
343 | 336 |
344 } // namespace contacts | 337 } // namespace contacts |
OLD | NEW |