Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..489d313aced130397bb3d497f133a63f9daaec90 |
| --- /dev/null |
| +++ b/remoting/host/pairing_registry_delegate_linux_unittest.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/pairing_registry_delegate_linux.h" |
| + |
| +#include "base/file_util.h" |
| +#include "base/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "base/task_runner.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "base/timer.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace remoting { |
| +namespace protocol { |
| + |
| +class PairingRegistryDelegateLinuxTest : public testing::Test { |
| + public: |
| + void SaveComplete(PairingRegistry::Delegate* delegate, |
| + PairingRegistry::Pairing pairing, |
| + bool success) { |
| + EXPECT_TRUE(success); |
| + // Load the pairings again to make sure we get what we've just written. |
|
Lambros
2013/06/20 17:59:20
I think it would be better to delete the delegate
Jamie
2013/06/20 20:17:09
Done.
|
| + delegate->GetPairing( |
| + pairing.client_id(), |
| + base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad, |
| + base::Unretained(this), |
| + pairing)); |
| + } |
| + |
| + void VerifyLoad(PairingRegistry::Pairing expected, |
| + PairingRegistry::Pairing actual) { |
| + EXPECT_EQ(actual, expected); |
| + base::MessageLoop::current()->Quit(); |
| + } |
| +}; |
| + |
| +TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) { |
| + base::MessageLoop message_loop; |
| + base::RunLoop run_loop; |
| + |
| + // Create a temporary directory in order to get a unique name, then delete |
| + // it so that we can 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("registry.json"); |
| + file_util::Delete(temp_dir, false); |
|
Lambros
2013/06/20 17:59:20
Better not to delete the temp dir here. Instead, d
Jamie
2013/06/20 20:17:09
Done.
|
| + |
| + PairingRegistryDelegateLinux* delegate = |
| + new PairingRegistryDelegateLinux(base::ThreadTaskRunnerHandle::Get()); |
| + delegate->SetFilenameForTesting(temp_file); |
| + |
| + PairingRegistry::Pairing pairing = |
| + PairingRegistry::Pairing::Create("client_id"); |
| + delegate->AddPairing( |
| + pairing, |
| + base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete, |
| + base::Unretained(this), |
| + delegate, |
| + pairing)); |
| + |
| + run_loop.Run(); |
| + |
| + file_util::Delete(temp_dir, true); |
| +}; |
| + |
| +} // namespace protocol |
| +} // namespace remoting |