| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 8 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 const char kEmptyOAuth2Token[] = ""; | 44 const char kEmptyOAuth2Token[] = ""; |
| 45 | 45 |
| 46 const char kMalformedOAuth2Token[] = "{ \"foo\": "; | 46 const char kMalformedOAuth2Token[] = "{ \"foo\": "; |
| 47 | 47 |
| 48 class TestForAuthError : public StatusChangeChecker { | 48 class TestForAuthError : public StatusChangeChecker { |
| 49 public: | 49 public: |
| 50 explicit TestForAuthError(ProfileSyncService* service); | 50 explicit TestForAuthError(ProfileSyncService* service); |
| 51 virtual ~TestForAuthError(); | 51 virtual ~TestForAuthError(); |
| 52 virtual bool IsExitConditionSatisfied() OVERRIDE; | 52 virtual bool IsExitConditionSatisfied() OVERRIDE; |
| 53 virtual std::string GetDebugMessage() const OVERRIDE; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 ProfileSyncService* service_; | 56 ProfileSyncService* service_; |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 TestForAuthError::TestForAuthError(ProfileSyncService* service) | 59 TestForAuthError::TestForAuthError(ProfileSyncService* service) |
| 59 : StatusChangeChecker("Testing for auth error"), service_(service) {} | 60 : service_(service) {} |
| 60 | 61 |
| 61 TestForAuthError::~TestForAuthError() {} | 62 TestForAuthError::~TestForAuthError() {} |
| 62 | 63 |
| 63 bool TestForAuthError::IsExitConditionSatisfied() { | 64 bool TestForAuthError::IsExitConditionSatisfied() { |
| 64 return !service_->HasUnsyncedItems() || | 65 return !service_->HasUnsyncedItems() || |
| 65 (service_->GetSyncTokenStatus().last_get_token_error.state() != | 66 (service_->GetSyncTokenStatus().last_get_token_error.state() != |
| 66 GoogleServiceAuthError::NONE); | 67 GoogleServiceAuthError::NONE); |
| 67 } | 68 } |
| 68 | 69 |
| 70 std::string TestForAuthError::GetDebugMessage() const { |
| 71 return "Waiting for auth error"; |
| 72 } |
| 73 |
| 69 class SyncAuthTest : public SyncTest { | 74 class SyncAuthTest : public SyncTest { |
| 70 public: | 75 public: |
| 71 SyncAuthTest() : SyncTest(SINGLE_CLIENT), bookmark_index_(0) {} | 76 SyncAuthTest() : SyncTest(SINGLE_CLIENT), bookmark_index_(0) {} |
| 72 virtual ~SyncAuthTest() {} | 77 virtual ~SyncAuthTest() {} |
| 73 | 78 |
| 74 // Helper function that adds a bookmark and waits for either an auth error, or | 79 // Helper function that adds a bookmark and waits for either an auth error, or |
| 75 // for the bookmark to be committed. Returns true if it detects an auth | 80 // for the bookmark to be committed. Returns true if it detects an auth |
| 76 // error, false if the bookmark is committed successfully. | 81 // error, false if the bookmark is committed successfully. |
| 77 bool AttemptToTriggerAuthError() { | 82 bool AttemptToTriggerAuthError() { |
| 78 int bookmark_index = GetNextBookmarkIndex(); | 83 int bookmark_index = GetNextBookmarkIndex(); |
| 79 std::wstring title = base::StringPrintf(L"Bookmark %d", bookmark_index); | 84 std::wstring title = base::StringPrintf(L"Bookmark %d", bookmark_index); |
| 80 GURL url = GURL(base::StringPrintf("http://www.foo%d.com", bookmark_index)); | 85 GURL url = GURL(base::StringPrintf("http://www.foo%d.com", bookmark_index)); |
| 81 EXPECT_TRUE(AddURL(0, title, url) != NULL); | 86 EXPECT_TRUE(AddURL(0, title, url) != NULL); |
| 82 | 87 |
| 83 // Run until the bookmark is committed or an auth error is encountered. | 88 // Run until the bookmark is committed or an auth error is encountered. |
| 84 TestForAuthError checker_(GetClient(0)->service()); | 89 TestForAuthError checker_(GetClient(0)->service()); |
| 85 GetClient(0)->AwaitStatusChange(&checker_, "Attempt to trigger auth error"); | 90 GetClient(0)->AwaitStatusChange(&checker_); |
| 86 | 91 |
| 87 GoogleServiceAuthError oauth_error = | 92 GoogleServiceAuthError oauth_error = |
| 88 GetClient(0)->service()->GetSyncTokenStatus().last_get_token_error; | 93 GetClient(0)->service()->GetSyncTokenStatus().last_get_token_error; |
| 89 | 94 |
| 90 return oauth_error.state() != GoogleServiceAuthError::NONE; | 95 return oauth_error.state() != GoogleServiceAuthError::NONE; |
| 91 } | 96 } |
| 92 | 97 |
| 93 // Sets the authenticated state of the python sync server to |auth_state| and | 98 // Sets the authenticated state of the python sync server to |auth_state| and |
| 94 // sets the canned response that will be returned to the OAuth2TokenService | 99 // sets the canned response that will be returned to the OAuth2TokenService |
| 95 // when it tries to fetch an access token. | 100 // when it tries to fetch an access token. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 SetAuthStateAndTokenResponse(AUTHENTICATED_TRUE, | 299 SetAuthStateAndTokenResponse(AUTHENTICATED_TRUE, |
| 295 kValidOAuth2Token, | 300 kValidOAuth2Token, |
| 296 net::HTTP_OK, | 301 net::HTTP_OK, |
| 297 net::URLRequestStatus::SUCCESS); | 302 net::URLRequestStatus::SUCCESS); |
| 298 | 303 |
| 299 // Verify that the next sync cycle is successful, and uses the new auth token. | 304 // Verify that the next sync cycle is successful, and uses the new auth token. |
| 300 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); | 305 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); |
| 301 std::string new_token = GetClient(0)->service()->GetAccessTokenForTest(); | 306 std::string new_token = GetClient(0)->service()->GetAccessTokenForTest(); |
| 302 ASSERT_NE(old_token, new_token); | 307 ASSERT_NE(old_token, new_token); |
| 303 } | 308 } |
| OLD | NEW |