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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" |
10 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 11 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
11 #include "chrome/browser/extensions/app_notify_channel_ui.h" | 12 #include "chrome/browser/extensions/app_notify_channel_ui.h" |
12 #include "chrome/browser/signin/token_service_factory.h" | 13 #include "chrome/browser/signin/token_service_factory.h" |
13 #include "chrome/browser/signin/token_service_unittest.h" | 14 #include "chrome/browser/signin/token_service_unittest.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/net/gaia/gaia_urls.h" | 16 #include "chrome/common/net/gaia/gaia_urls.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_pref_service.h" | 18 #include "chrome/test/base/testing_pref_service.h" |
18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
19 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 scoped_ptr<bool> setup_result_; | 166 scoped_ptr<bool> setup_result_; |
166 | 167 |
167 DISALLOW_COPY_AND_ASSIGN(TestUI); | 168 DISALLOW_COPY_AND_ASSIGN(TestUI); |
168 }; | 169 }; |
169 | 170 |
170 } // namespace | 171 } // namespace |
171 | 172 |
172 class AppNotifyChannelSetupTest : public testing::Test { | 173 class AppNotifyChannelSetupTest : public testing::Test { |
173 public: | 174 public: |
174 AppNotifyChannelSetupTest() : ui_thread_(BrowserThread::UI, &message_loop_), | 175 AppNotifyChannelSetupTest() : ui_thread_(BrowserThread::UI, &message_loop_), |
| 176 db_thread_(BrowserThread::DB), |
175 ui_(new TestUI()) { | 177 ui_(new TestUI()) { |
176 } | 178 } |
177 | 179 |
178 virtual ~AppNotifyChannelSetupTest() {} | 180 virtual ~AppNotifyChannelSetupTest() {} |
179 | 181 |
180 virtual void SetLoggedInUser(const std::string username) { | 182 virtual void SetLoggedInUser(const std::string username) { |
181 TestingPrefService* prefs = profile_.GetTestingPrefService(); | 183 TestingPrefService* prefs = profile_.GetTestingPrefService(); |
182 prefs->SetUserPref(prefs::kGoogleServicesUsername, | 184 prefs->SetUserPref(prefs::kGoogleServicesUsername, |
183 new StringValue(username)); | 185 new StringValue(username)); |
184 } | 186 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 228 } |
227 | 229 |
228 virtual void RunServerTest(AppNotifyChannelSetup* setup, | 230 virtual void RunServerTest(AppNotifyChannelSetup* setup, |
229 const std::string& expected_code, | 231 const std::string& expected_code, |
230 const std::string& expected_error) { | 232 const std::string& expected_error) { |
231 setup->Start(); | 233 setup->Start(); |
232 message_loop_.Run(); | 234 message_loop_.Run(); |
233 delegate_.ExpectWasCalled(expected_code, expected_error); | 235 delegate_.ExpectWasCalled(expected_code, expected_error); |
234 } | 236 } |
235 | 237 |
| 238 virtual void SetUp() OVERRIDE { |
| 239 db_thread_.Start(); |
| 240 } |
| 241 |
| 242 virtual void TearDown() OVERRIDE { |
| 243 // Schedule another task on the DB thread to notify us that it's safe to |
| 244 // carry on with the test. |
| 245 base::WaitableEvent done(false, false); |
| 246 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 247 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 248 done.Wait(); |
| 249 db_thread_.Stop(); |
| 250 } |
| 251 |
236 protected: | 252 protected: |
237 MessageLoop message_loop_; | 253 MessageLoop message_loop_; |
238 content::TestBrowserThread ui_thread_; | 254 content::TestBrowserThread ui_thread_; |
| 255 content::TestBrowserThread db_thread_; |
239 TestProfile profile_; | 256 TestProfile profile_; |
240 TestDelegate delegate_; | 257 TestDelegate delegate_; |
241 scoped_ptr<TestUI> ui_; | 258 scoped_ptr<TestUI> ui_; |
242 FakeURLFetcherFactory factory_; | 259 FakeURLFetcherFactory factory_; |
243 }; | 260 }; |
244 | 261 |
245 TEST_F(AppNotifyChannelSetupTest, LoginFailure) { | 262 TEST_F(AppNotifyChannelSetupTest, LoginFailure) { |
246 SetupLogin(true, false); | 263 SetupLogin(true, false); |
247 | 264 |
248 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 265 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 SetupLogin(false, true); | 309 SetupLogin(false, true); |
293 SetupFetchAccessToken(false); | 310 SetupFetchAccessToken(false); |
294 SetupLogin(true, true); | 311 SetupLogin(true, true); |
295 SetupFetchAccessToken(true); | 312 SetupFetchAccessToken(true); |
296 SetupRecordGrant(true); | 313 SetupRecordGrant(true); |
297 SetupGetChannelId(true); | 314 SetupGetChannelId(true); |
298 | 315 |
299 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 316 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
300 RunServerTest(setup, "dummy_do_not_use", ""); | 317 RunServerTest(setup, "dummy_do_not_use", ""); |
301 } | 318 } |
OLD | NEW |