| 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" |
| 11 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 11 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 13 #include "chrome/browser/sync/test/integration/status_change_checker.h" | 13 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| 14 #include "chrome/browser/sync/test/integration/sync_test.h" | 14 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 15 #include "google_apis/gaia/google_service_auth_error.h" | 15 #include "google_apis/gaia/google_service_auth_error.h" |
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 | 18 |
| 19 using bookmarks_helper::AddURL; | 19 using bookmarks_helper::AddURL; |
| 20 | 20 |
| 21 const char kShortLivedOAuth2Token[] = | 21 const char kShortLivedOAuth2Token[] = |
| 22 "{" | 22 "{" |
| 23 " \"refresh_token\": \"short_lived_refresh_token\"," | 23 " \"refresh_token\": \"short_lived_refresh_token\"," |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 "}"; | 38 "}"; |
| 39 | 39 |
| 40 const char kInvalidClientOAuth2Token[] = "{" | 40 const char kInvalidClientOAuth2Token[] = "{" |
| 41 " \"error\": \"invalid_client\"" | 41 " \"error\": \"invalid_client\"" |
| 42 "}"; | 42 "}"; |
| 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 SingleClientStatusChangeChecker { |
| 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 | 53 virtual std::string GetDebugMessage() const OVERRIDE; |
| 54 private: | |
| 55 ProfileSyncService* service_; | |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 TestForAuthError::TestForAuthError(ProfileSyncService* service) | 56 TestForAuthError::TestForAuthError(ProfileSyncService* service) |
| 59 : StatusChangeChecker("Testing for auth error"), service_(service) {} | 57 : SingleClientStatusChangeChecker(service) {} |
| 60 | 58 |
| 61 TestForAuthError::~TestForAuthError() {} | 59 TestForAuthError::~TestForAuthError() {} |
| 62 | 60 |
| 63 bool TestForAuthError::IsExitConditionSatisfied() { | 61 bool TestForAuthError::IsExitConditionSatisfied() { |
| 64 return !service_->HasUnsyncedItems() || | 62 return !service()->HasUnsyncedItems() || |
| 65 (service_->GetSyncTokenStatus().last_get_token_error.state() != | 63 (service()->GetSyncTokenStatus().last_get_token_error.state() != |
| 66 GoogleServiceAuthError::NONE); | 64 GoogleServiceAuthError::NONE); |
| 67 } | 65 } |
| 68 | 66 |
| 67 std::string TestForAuthError::GetDebugMessage() const { |
| 68 return "Waiting for auth error"; |
| 69 } |
| 70 |
| 69 class SyncAuthTest : public SyncTest { | 71 class SyncAuthTest : public SyncTest { |
| 70 public: | 72 public: |
| 71 SyncAuthTest() : SyncTest(SINGLE_CLIENT), bookmark_index_(0) {} | 73 SyncAuthTest() : SyncTest(SINGLE_CLIENT), bookmark_index_(0) {} |
| 72 virtual ~SyncAuthTest() {} | 74 virtual ~SyncAuthTest() {} |
| 73 | 75 |
| 74 // Helper function that adds a bookmark and waits for either an auth error, or | 76 // 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 | 77 // for the bookmark to be committed. Returns true if it detects an auth |
| 76 // error, false if the bookmark is committed successfully. | 78 // error, false if the bookmark is committed successfully. |
| 77 bool AttemptToTriggerAuthError() { | 79 bool AttemptToTriggerAuthError() { |
| 78 int bookmark_index = GetNextBookmarkIndex(); | 80 int bookmark_index = GetNextBookmarkIndex(); |
| 79 std::wstring title = base::StringPrintf(L"Bookmark %d", bookmark_index); | 81 std::wstring title = base::StringPrintf(L"Bookmark %d", bookmark_index); |
| 80 GURL url = GURL(base::StringPrintf("http://www.foo%d.com", bookmark_index)); | 82 GURL url = GURL(base::StringPrintf("http://www.foo%d.com", bookmark_index)); |
| 81 EXPECT_TRUE(AddURL(0, title, url) != NULL); | 83 EXPECT_TRUE(AddURL(0, title, url) != NULL); |
| 82 | 84 |
| 83 // Run until the bookmark is committed or an auth error is encountered. | 85 // Run until the bookmark is committed or an auth error is encountered. |
| 84 TestForAuthError checker_(GetClient(0)->service()); | 86 TestForAuthError checker_(GetClient(0)->service()); |
| 85 GetClient(0)->AwaitStatusChange(&checker_, "Attempt to trigger auth error"); | 87 GetClient(0)->AwaitStatusChange(&checker_); |
| 86 | 88 |
| 87 GoogleServiceAuthError oauth_error = | 89 GoogleServiceAuthError oauth_error = |
| 88 GetClient(0)->service()->GetSyncTokenStatus().last_get_token_error; | 90 GetClient(0)->service()->GetSyncTokenStatus().last_get_token_error; |
| 89 | 91 |
| 90 return oauth_error.state() != GoogleServiceAuthError::NONE; | 92 return oauth_error.state() != GoogleServiceAuthError::NONE; |
| 91 } | 93 } |
| 92 | 94 |
| 93 // Sets the authenticated state of the python sync server to |auth_state| and | 95 // 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 | 96 // sets the canned response that will be returned to the OAuth2TokenService |
| 95 // when it tries to fetch an access token. | 97 // 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, | 296 SetAuthStateAndTokenResponse(AUTHENTICATED_TRUE, |
| 295 kValidOAuth2Token, | 297 kValidOAuth2Token, |
| 296 net::HTTP_OK, | 298 net::HTTP_OK, |
| 297 net::URLRequestStatus::SUCCESS); | 299 net::URLRequestStatus::SUCCESS); |
| 298 | 300 |
| 299 // Verify that the next sync cycle is successful, and uses the new auth token. | 301 // Verify that the next sync cycle is successful, and uses the new auth token. |
| 300 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); | 302 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); |
| 301 std::string new_token = GetClient(0)->service()->GetAccessTokenForTest(); | 303 std::string new_token = GetClient(0)->service()->GetAccessTokenForTest(); |
| 302 ASSERT_NE(old_token, new_token); | 304 ASSERT_NE(old_token, new_token); |
| 303 } | 305 } |
| OLD | NEW |