Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: remoting/protocol/pairing_registry_unittest.cc

Issue 19714002: Add serialization to PairingRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer feedback. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/pairing_registry.cc ('k') | remoting/protocol/protocol_mock_objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/pairing_registry_unittest.cc
diff --git a/remoting/protocol/pairing_registry_unittest.cc b/remoting/protocol/pairing_registry_unittest.cc
index b113f1369e7937c8a18af51570f8b6883d38e735..f564256c335bdc60d723f63a840a2617ab2dccdf 100644
--- a/remoting/protocol/pairing_registry_unittest.cc
+++ b/remoting/protocol/pairing_registry_unittest.cc
@@ -33,11 +33,6 @@ void VerifyPairing(PairingRegistry::Pairing expected,
EXPECT_FALSE(actual.HasKey(PairingRegistry::kSharedSecretKey));
}
-// SaveCallback that expects to be called with success = true.
-void ExpectSaveSuccess(bool success) {
- EXPECT_TRUE(success);
-}
-
} // namespace
namespace remoting {
@@ -45,20 +40,38 @@ namespace protocol {
class PairingRegistryTest : public testing::Test {
public:
- void CompareSecret(const std::string& expected,
- PairingRegistry::Pairing actual) {
- EXPECT_EQ(expected, actual.shared_secret());
- secret_ = actual.shared_secret();
- got_secret_ = true;
+ virtual void SetUp() OVERRIDE {
+ callback_count_ = 0;
}
void set_pairings(scoped_ptr<base::ListValue> pairings) {
pairings_ = pairings.Pass();
}
+ void ExpectSecret(const std::string& expected,
+ PairingRegistry::Pairing actual) {
+ EXPECT_EQ(expected, actual.shared_secret());
+ ++callback_count_;
+ }
+
+ void ExpectSaveSuccess(bool success) {
+ EXPECT_TRUE(success);
+ ++callback_count_;
+ }
+
+ void ExpectClientName(const std::string& expected,
+ PairingRegistry::Pairing actual) {
+ EXPECT_EQ(expected, actual.client_name());
+ ++callback_count_;
+ }
+
+ void ExpectNoPairings(scoped_ptr<base::ListValue> pairings) {
+ EXPECT_TRUE(pairings->empty());
+ ++callback_count_;
+ }
+
protected:
- std::string secret_;
- bool got_secret_;
+ int callback_count_;
scoped_ptr<base::ListValue> pairings_;
};
@@ -73,24 +86,22 @@ TEST_F(PairingRegistryTest, CreateAndGetPairings) {
PairingRegistry::Pairing pairing_2 = registry->CreatePairing("my_client");
mock_delegate->RunCallback();
+ EXPECT_NE(pairing_1.shared_secret(), pairing_2.shared_secret());
+
registry->GetPairing(pairing_1.client_id(),
- base::Bind(&PairingRegistryTest::CompareSecret,
+ base::Bind(&PairingRegistryTest::ExpectSecret,
base::Unretained(this),
pairing_1.shared_secret()));
- got_secret_ = false;
mock_delegate->RunCallback();
- EXPECT_TRUE(got_secret_);
- std::string secret_1 = secret_;
+ EXPECT_EQ(1, callback_count_);
// Check that the second client is paired with a different shared secret.
registry->GetPairing(pairing_2.client_id(),
- base::Bind(&PairingRegistryTest::CompareSecret,
+ base::Bind(&PairingRegistryTest::ExpectSecret,
base::Unretained(this),
pairing_2.shared_secret()));
- got_secret_ = false;
mock_delegate->RunCallback();
- EXPECT_TRUE(got_secret_);
- EXPECT_NE(secret_, secret_1);
+ EXPECT_EQ(2, callback_count_);
}
TEST_F(PairingRegistryTest, GetAllPairings) {
@@ -138,7 +149,10 @@ TEST_F(PairingRegistryTest, DeletePairing) {
PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client2");
mock_delegate->RunCallback();
- registry->DeletePairing(pairing_1.client_id(), base::Bind(ExpectSaveSuccess));
+ registry->DeletePairing(
+ pairing_1.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectSaveSuccess,
+ base::Unretained(this)));
mock_delegate->RunCallback();
// Re-read the list, and verify it only has the pairing_2 client.
@@ -167,7 +181,9 @@ TEST_F(PairingRegistryTest, ClearAllPairings) {
PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client2");
mock_delegate->RunCallback();
- registry->ClearAllPairings(base::Bind(ExpectSaveSuccess));
+ registry->ClearAllPairings(
+ base::Bind(&PairingRegistryTest::ExpectSaveSuccess,
+ base::Unretained(this)));
// Re-read the list, and verify it is empty.
registry->GetAllPairings(
@@ -178,5 +194,53 @@ TEST_F(PairingRegistryTest, ClearAllPairings) {
EXPECT_TRUE(pairings_->empty());
}
+TEST_F(PairingRegistryTest, SerializedRequests) {
+ MockPairingRegistryDelegate* mock_delegate =
+ new MockPairingRegistryDelegate();
+ scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate);
+ mock_delegate->set_run_save_callback_automatically(false);
+
+ scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass()));
+ PairingRegistry::Pairing pairing_1 = registry->CreatePairing("client1");
+ PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client2");
+ registry->GetPairing(
+ pairing_1.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectClientName,
+ base::Unretained(this), "client1"));
+ registry->GetPairing(
+ pairing_2.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectClientName,
+ base::Unretained(this), "client2"));
+ registry->DeletePairing(
+ pairing_2.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectSaveSuccess,
+ base::Unretained(this)));
+ registry->GetPairing(
+ pairing_1.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectClientName,
+ base::Unretained(this), "client1"));
+ registry->GetPairing(
+ pairing_2.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectClientName,
+ base::Unretained(this), ""));
+ registry->ClearAllPairings(
+ base::Bind(&PairingRegistryTest::ExpectSaveSuccess,
+ base::Unretained(this)));
+ registry->GetAllPairings(
+ base::Bind(&PairingRegistryTest::ExpectNoPairings,
+ base::Unretained(this)));
+ PairingRegistry::Pairing pairing_3 = registry->CreatePairing("client3");
+ registry->GetPairing(
+ pairing_3.client_id(),
+ base::Bind(&PairingRegistryTest::ExpectClientName,
+ base::Unretained(this), "client3"));
+
+ while (mock_delegate->HasCallback()) {
+ mock_delegate->RunCallback();
+ }
+
+ EXPECT_EQ(8, callback_count_);
+}
+
} // namespace protocol
} // namespace remoting
« no previous file with comments | « remoting/protocol/pairing_registry.cc ('k') | remoting/protocol/protocol_mock_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698