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

Unified Diff: remoting/host/pairing_registry_delegate_linux_unittest.cc

Issue 21128006: Refactored PairingRegistry::Delegate such that it can retrieve/modify for a single client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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/host/pairing_registry_delegate_linux.cc ('k') | remoting/host/pairing_registry_delegate_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/pairing_registry_delegate_linux_unittest.cc
diff --git a/remoting/host/pairing_registry_delegate_linux_unittest.cc b/remoting/host/pairing_registry_delegate_linux_unittest.cc
index 0f679eb8f257670f21f596ce95aae7b8d44871e6..d044a04b8ce038f276d58f51ec67c1b840c51791 100644
--- a/remoting/host/pairing_registry_delegate_linux_unittest.cc
+++ b/remoting/host/pairing_registry_delegate_linux_unittest.cc
@@ -5,11 +5,8 @@
#include "remoting/host/pairing_registry_delegate_linux.h"
#include "base/file_util.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/task_runner.h"
-#include "base/thread_task_runner_handle.h"
#include "base/timer/timer.h"
+#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
@@ -18,59 +15,75 @@ using protocol::PairingRegistry;
class PairingRegistryDelegateLinuxTest : public testing::Test {
public:
- void SaveComplete(PairingRegistry::Delegate* delegate,
- const std::string& expected_json,
- bool success) {
- EXPECT_TRUE(success);
- // Load the pairings again to make sure we get what we've just written.
- delegate->Load(
- base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad,
- base::Unretained(this),
- expected_json));
+ virtual void SetUp() OVERRIDE {
+ // Create a temporary directory in order to get a unique name and use a
+ // subdirectory to ensure that PairingRegistryDelegateLinux::Save() creates
+ // the parent directory if it doesn't exist.
+ file_util::CreateNewTempDirectory("chromoting-test", &temp_dir_);
+ temp_registry_ = temp_dir_.Append("paired-clients");
}
- void VerifyLoad(const std::string& expected,
- const std::string& actual) {
- EXPECT_EQ(actual, expected);
- base::MessageLoop::current()->Quit();
+ virtual void TearDown() OVERRIDE {
+ base::DeleteFile(temp_dir_, true);
}
+
+ protected:
+ base::FilePath temp_dir_;
+ base::FilePath temp_registry_;
};
TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
- base::MessageLoop message_loop;
- base::RunLoop run_loop;
-
- // Create a temporary directory in order to get a unique name and use a
- // subdirectory to ensure that the AddPairing method creates the parent
- // directory if it doesn't exist.
- base::FilePath temp_dir;
- file_util::CreateNewTempDirectory("chromoting-test", &temp_dir);
- base::FilePath temp_file = temp_dir.Append("dir").Append("registry.json");
-
- scoped_refptr<base::TaskRunner> task_runner =
- base::ThreadTaskRunnerHandle::Get();
+ scoped_ptr<PairingRegistryDelegateLinux> delegate(
+ new PairingRegistryDelegateLinux());
+ delegate->SetRegistryPathForTesting(temp_registry_);
+
+ // Check that registry is initially empty.
+ EXPECT_TRUE(delegate->LoadAll()->empty());
+
+ // Add a couple of pairings.
+ PairingRegistry::Pairing pairing1(base::Time::Now(), "xxx", "xxx", "xxx");
+ PairingRegistry::Pairing pairing2(base::Time::Now(), "yyy", "yyy", "yyy");
+ EXPECT_TRUE(delegate->Save(pairing1));
+ EXPECT_TRUE(delegate->Save(pairing2));
+
+ // Verify that there are two pairings in the store now.
+EXPECT_EQ(delegate->LoadAll()->GetSize(), 2u);
+
+ // Verify that they can be retrieved.
+ EXPECT_EQ(delegate->Load(pairing1.client_id()), pairing1);
+ EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
+
+ // Delete the first pairing.
+ EXPECT_TRUE(delegate->Delete(pairing1.client_id()));
+
+ // Verify that there is only one pairing left.
+ EXPECT_EQ(delegate->Load(pairing1.client_id()), PairingRegistry::Pairing());
+ EXPECT_EQ(delegate->Load(pairing2.client_id()), pairing2);
+
+ // Verify that the only value that left is |pairing2|.
+ EXPECT_EQ(delegate->LoadAll()->GetSize(), 1u);
+ scoped_ptr<base::ListValue> pairings = delegate->LoadAll();
+ base::Value* json;
+ EXPECT_TRUE(pairings->Get(0, &json));
+ EXPECT_EQ(PairingRegistry::Pairing::CreateFromValue(*json), pairing2);
+
+ // Delete the rest and verify.
+ EXPECT_TRUE(delegate->DeleteAll());
+ EXPECT_TRUE(delegate->LoadAll()->empty());
+}
+
+// Verifies that the delegate is stateless by using two different instances.
+TEST_F(PairingRegistryDelegateLinuxTest, Stateless) {
scoped_ptr<PairingRegistryDelegateLinux> save_delegate(
- new PairingRegistryDelegateLinux(task_runner));
+ new PairingRegistryDelegateLinux());
scoped_ptr<PairingRegistryDelegateLinux> load_delegate(
- new PairingRegistryDelegateLinux(task_runner));
- save_delegate->SetFilenameForTesting(temp_file);
- load_delegate->SetFilenameForTesting(temp_file);
-
- // Save the pairings, then load them using a different delegate to ensure
- // that the test isn't passing due to cached values. Note that the delegate
- // doesn't require that the strings it loads and saves are valid JSON, so
- // we can simplify the test a bit.
- std::string test_data = "test data";
- save_delegate->Save(
- test_data,
- base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete,
- base::Unretained(this),
- load_delegate.get(),
- test_data));
-
- run_loop.Run();
-
- base::DeleteFile(temp_dir, true);
-};
+ new PairingRegistryDelegateLinux());
+ save_delegate->SetRegistryPathForTesting(temp_registry_);
+ load_delegate->SetRegistryPathForTesting(temp_registry_);
+
+ PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx");
+ EXPECT_TRUE(save_delegate->Save(pairing));
+ EXPECT_EQ(load_delegate->Load(pairing.client_id()), pairing);
+}
} // namespace remoting
« no previous file with comments | « remoting/host/pairing_registry_delegate_linux.cc ('k') | remoting/host/pairing_registry_delegate_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698