summaryrefslogtreecommitdiffstats
path: root/chrome/test/sync
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 23:57:20 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 23:57:20 +0000
commit3c47992ef36d4737f1ca8f6c701f047c05b12481 (patch)
treea745663ad77f4b5baf9904adfbbbc65de3bbb22c /chrome/test/sync
parentd9735af55ab6fe947c68eb27c686df901d260398 (diff)
downloadchromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.zip
chromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.tar.gz
chromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.tar.bz2
Sync: Remove pthreads from auth_watcher.
BUG=19895 TEST=AuthWatcherTest Review URL: http://codereview.chromium.org/246098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/sync')
-rw-r--r--chrome/test/sync/engine/mock_server_connection.cc43
-rw-r--r--chrome/test/sync/engine/mock_server_connection.h14
-rw-r--r--chrome/test/sync/engine/test_directory_setter_upper.cc21
-rw-r--r--chrome/test/sync/engine/test_directory_setter_upper.h14
4 files changed, 86 insertions, 6 deletions
diff --git a/chrome/test/sync/engine/mock_server_connection.cc b/chrome/test/sync/engine/mock_server_connection.cc
index c4595bd..46ec870 100644
--- a/chrome/test/sync/engine/mock_server_connection.cc
+++ b/chrome/test/sync/engine/mock_server_connection.cc
@@ -70,22 +70,23 @@ void MockConnectionManager::SetMidCommitObserver(
bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
const string& path,
const string& auth_token) {
-
- ScopedDirLookup directory(directory_manager_, directory_name_);
- CHECK(directory.good());
-
ClientToServerMessage post;
CHECK(post.ParseFromString(params->buffer_in));
client_stuck_ = post.sync_problem_detected();
ClientToServerResponse response;
response.Clear();
+
+ ScopedDirLookup directory(directory_manager_, directory_name_);
+ // For any non-AUTHENTICATE requests, a valid directory should be set up.
// If the Directory's locked when we do this, it's a problem as in normal
// use this function could take a while to return because it accesses the
// network. As we can't test this we do the next best thing and hang here
// when there's an issue.
- {
+ if (post.message_contents() != ClientToServerMessage::AUTHENTICATE) {
+ CHECK(directory.good());
WriteTransaction wt(directory, syncable::UNITTEST, __FILE__, __LINE__);
}
+
if (fail_next_postbuffer_) {
fail_next_postbuffer_ = false;
return false;
@@ -101,12 +102,15 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
return true;
}
bool result = true;
- EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday());
+ EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() ||
+ post.message_contents() == ClientToServerMessage::AUTHENTICATE);
store_birthday_sent_ = true;
if (post.message_contents() == ClientToServerMessage::COMMIT) {
ProcessCommit(&post, &response);
} else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) {
ProcessGetUpdates(&post, &response);
+ } else if (post.message_contents() == ClientToServerMessage::AUTHENTICATE) {
+ ProcessAuthenticate(&post, &response, auth_token);
} else {
EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
return false;
@@ -249,6 +253,33 @@ void MockConnectionManager::ProcessGetUpdates(ClientToServerMessage* csm,
ResetUpdates();
}
+void MockConnectionManager::ProcessAuthenticate(ClientToServerMessage* csm,
+ ClientToServerResponse* response, const std::string& auth_token){
+ ASSERT_EQ(csm->message_contents(), ClientToServerMessage::AUTHENTICATE);
+ EXPECT_FALSE(auth_token.empty());
+
+ if (auth_token != valid_auth_token_) {
+ response->set_error_code(ClientToServerResponse::AUTH_INVALID);
+ return;
+ }
+
+ response->set_error_code(ClientToServerResponse::SUCCESS);
+ response->mutable_authenticate()->CopyFrom(auth_response_);
+ auth_response_.Clear();
+}
+
+void MockConnectionManager::SetAuthenticationResponseInfo(
+ const std::string& valid_auth_token,
+ const std::string& user_display_name,
+ const std::string& user_display_email,
+ const std::string& user_obfuscated_id) {
+ valid_auth_token_ = valid_auth_token;
+ sync_pb::UserIdentification* user = auth_response_.mutable_user();
+ user->set_display_name(user_display_name);
+ user->set_email(user_display_email);
+ user->set_obfuscated_id(user_obfuscated_id);
+}
+
bool MockConnectionManager::ShouldConflictThisCommit() {
bool conflict = false;
if (conflict_all_commits_) {
diff --git a/chrome/test/sync/engine/mock_server_connection.h b/chrome/test/sync/engine/mock_server_connection.h
index 8c0cca7..1c19a5b 100644
--- a/chrome/test/sync/engine/mock_server_connection.h
+++ b/chrome/test/sync/engine/mock_server_connection.h
@@ -109,6 +109,12 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager {
void SetNewTimestamp(int64 ts);
void SetNewestTimestamp(int64 ts);
+ // For AUTHENTICATE responses.
+ void SetAuthenticationResponseInfo(const std::string& valid_auth_token,
+ const std::string& user_display_name,
+ const std::string& user_display_email,
+ const std::string& user_obfuscated_id);
+
void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; }
// Simple inspectors.
@@ -144,6 +150,9 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager {
// Functions to handle the various types of server request.
void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm,
sync_pb::ClientToServerResponse* response);
+ void ProcessAuthenticate(sync_pb::ClientToServerMessage* csm,
+ sync_pb::ClientToServerResponse* response,
+ const std::string& auth_token);
void ProcessCommit(sync_pb::ClientToServerMessage* csm,
sync_pb::ClientToServerResponse* response_buffer);
// Locate the most recent update message for purpose of alteration.
@@ -190,6 +199,11 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager {
TestCallbackFunction mid_commit_callback_function_;
MidCommitObserver* mid_commit_observer_;
+ // The AUTHENTICATE response we'll return for auth requests.
+ sync_pb::AuthenticateResponse auth_response_;
+ // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN.
+ std::string valid_auth_token_;
+
scoped_ptr<sync_pb::ClientCommand> client_command_;
// The next value to use for the position_in_parent property.
diff --git a/chrome/test/sync/engine/test_directory_setter_upper.cc b/chrome/test/sync/engine/test_directory_setter_upper.cc
index 0a7b32d..919ce2a 100644
--- a/chrome/test/sync/engine/test_directory_setter_upper.cc
+++ b/chrome/test/sync/engine/test_directory_setter_upper.cc
@@ -4,6 +4,7 @@
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
+#include "base/string_util.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/util/compat_file.h"
@@ -17,6 +18,8 @@ using syncable::ScopedDirLookup;
namespace browser_sync {
TestDirectorySetterUpper::TestDirectorySetterUpper() : name_(PSTR("Test")) {}
+TestDirectorySetterUpper::TestDirectorySetterUpper(const PathString& name)
+ : name_(name) {}
TestDirectorySetterUpper::~TestDirectorySetterUpper() {}
@@ -82,4 +85,22 @@ void ManuallyOpenedTestDirectorySetterUpper::TearDown() {
}
}
+TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper(
+ const std::string& name) : TestDirectorySetterUpper(UTF8ToWide(name)) {
+}
+
+void TriggeredOpenTestDirectorySetterUpper::SetUp() {
+ Init();
+}
+
+void TriggeredOpenTestDirectorySetterUpper::TearDown() {
+ DirectoryManager::DirNames names;
+ manager()->GetOpenDirectories(&names);
+ if (!names.empty()) {
+ ASSERT_EQ(1, names.size());
+ ASSERT_EQ(name(), names[0]);
+ TestDirectorySetterUpper::TearDown();
+ }
+}
+
} // namespace browser_sync
diff --git a/chrome/test/sync/engine/test_directory_setter_upper.h b/chrome/test/sync/engine/test_directory_setter_upper.h
index 0cfa3e6..3c8936a 100644
--- a/chrome/test/sync/engine/test_directory_setter_upper.h
+++ b/chrome/test/sync/engine/test_directory_setter_upper.h
@@ -59,6 +59,8 @@ class TestDirectorySetterUpper {
const PathString& name() const { return name_; }
protected:
+ // Subclasses may want to use a different directory name.
+ explicit TestDirectorySetterUpper(const PathString& name);
virtual void Init();
private:
@@ -82,6 +84,18 @@ class ManuallyOpenedTestDirectorySetterUpper : public TestDirectorySetterUpper {
bool was_opened_;
};
+// Use this flavor if you have a test that will trigger the opening event to
+// happen automagically. It is careful on teardown to close only if needed.
+class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper {
+ public:
+ // A triggered open is typically in response to a successful auth event just
+ // as in "real life". In this case, the name that will be used should be
+ // deterministically known at construction, and is passed in |name|.
+ TriggeredOpenTestDirectorySetterUpper(const std::string& name);
+ virtual void SetUp();
+ virtual void TearDown();
+};
+
} // namespace browser_sync
#endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_