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

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: cosmetic 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
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..e39764abb02442eea91fd572d71197f4236f932f 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,60 @@ 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 the AddPairing method creates the parent
Jamie 2013/08/01 22:44:04 s/AddPairing/Save/ (or LinuxPairingRegistryDelegat
alexeypa (please no reviews) 2013/08/01 23:07:43 Done.
+ // 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;
+// Verify that the registry is initially empty.
+TEST_F(PairingRegistryDelegateLinuxTest, Empty) {
+ scoped_ptr<PairingRegistryDelegateLinux> delegate(
+ new PairingRegistryDelegateLinux());
+ delegate->SetRegistryPathForTesting(temp_registry_);
+ EXPECT_TRUE(delegate->LoadAll()->empty());
+}
- // 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");
+// Verify that an entry can deleted.
+TEST_F(PairingRegistryDelegateLinuxTest, Delete) {
Jamie 2013/08/01 22:44:04 Can you add a test for DeleteAll as well (since it
alexeypa (please no reviews) 2013/08/01 23:07:43 Done.
+ scoped_ptr<PairingRegistryDelegateLinux> delegate(
+ new PairingRegistryDelegateLinux());
+ delegate->SetRegistryPathForTesting(temp_registry_);
- scoped_refptr<base::TaskRunner> task_runner =
- base::ThreadTaskRunnerHandle::Get();
- scoped_ptr<PairingRegistryDelegateLinux> save_delegate(
- new PairingRegistryDelegateLinux(task_runner));
- scoped_ptr<PairingRegistryDelegateLinux> load_delegate(
- new PairingRegistryDelegateLinux(task_runner));
- save_delegate->SetFilenameForTesting(temp_file);
- load_delegate->SetFilenameForTesting(temp_file);
+ EXPECT_TRUE(delegate->LoadAll()->empty());
- // 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));
+ PairingRegistry::Pairing pairing(base::Time::Now(), "xxx", "xxx", "xxx");
+ EXPECT_TRUE(delegate->Save(pairing));
+ EXPECT_EQ(delegate->Load(pairing.client_id()), pairing);
- run_loop.Run();
+ EXPECT_TRUE(delegate->Delete(pairing.client_id()));
+ EXPECT_TRUE(delegate->LoadAll()->empty());
+}
- base::DeleteFile(temp_dir, true);
-};
+// Verify that an entry can be saved and loaded. Different instances of
+// the delegate are used to make sure that the objects are stateless.
+TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
+ scoped_ptr<PairingRegistryDelegateLinux> save_delegate(
+ new PairingRegistryDelegateLinux());
+ scoped_ptr<PairingRegistryDelegateLinux> load_delegate(
+ 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

Powered by Google App Engine
This is Rietveld 408576698