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

Side by Side 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: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/pairing_registry_delegate_linux.h" 5 #include "remoting/host/pairing_registry_delegate_linux.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace remoting { 15 namespace remoting {
16 16
17 using protocol::PairingRegistry; 17 using protocol::PairingRegistry;
18 18
19 class PairingRegistryDelegateLinuxTest : public testing::Test { 19 class PairingRegistryDelegateLinuxTest : public testing::Test {
20 public: 20 public:
21 void SaveComplete(PairingRegistry::Delegate* delegate, 21 void SaveComplete(PairingRegistry::Delegate* delegate,
22 const std::string& expected_json, 22 PairingRegistry::Pairing expected_pairing,
23 bool success) { 23 bool success) {
24 EXPECT_TRUE(success); 24 EXPECT_TRUE(success);
25
25 // Load the pairings again to make sure we get what we've just written. 26 // Load the pairings again to make sure we get what we've just written.
Jamie 2013/07/30 21:35:07 s/pairings/pairing/
alexeypa (please no reviews) 2013/07/31 21:31:24 Done.
26 delegate->Load( 27 delegate->Load(
28 expected_pairing.client_id(),
27 base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad, 29 base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad,
28 base::Unretained(this), 30 base::Unretained(this),
29 expected_json)); 31 expected_pairing));
30 } 32 }
31 33
32 void VerifyLoad(const std::string& expected, 34 void VerifyLoad(PairingRegistry::Pairing expected_pairing,
33 const std::string& actual) { 35 PairingRegistry::Pairing actual_pairing) {
34 EXPECT_EQ(actual, expected); 36 EXPECT_EQ(actual_pairing.client_id(), expected_pairing.client_id());
37 EXPECT_EQ(actual_pairing, expected_pairing);
35 base::MessageLoop::current()->Quit(); 38 base::MessageLoop::current()->Quit();
36 } 39 }
37 }; 40 };
38 41
39 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) { 42 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
40 base::MessageLoop message_loop; 43 base::MessageLoop message_loop;
41 base::RunLoop run_loop; 44 base::RunLoop run_loop;
42 45
43 // Create a temporary directory in order to get a unique name and use a 46 // Create a temporary directory in order to get a unique name and use a
44 // subdirectory to ensure that the AddPairing method creates the parent 47 // subdirectory to ensure that the AddPairing method creates the parent
45 // directory if it doesn't exist. 48 // directory if it doesn't exist.
46 base::FilePath temp_dir; 49 base::FilePath temp_dir;
47 file_util::CreateNewTempDirectory("chromoting-test", &temp_dir); 50 file_util::CreateNewTempDirectory("chromoting-test", &temp_dir);
48 base::FilePath temp_file = temp_dir.Append("dir").Append("registry.json"); 51 base::FilePath temp_registry = temp_dir.Append("pairing-registry");
49 52
50 scoped_refptr<base::TaskRunner> task_runner = 53 scoped_refptr<base::TaskRunner> task_runner =
51 base::ThreadTaskRunnerHandle::Get(); 54 base::ThreadTaskRunnerHandle::Get();
52 scoped_ptr<PairingRegistryDelegateLinux> save_delegate( 55 scoped_ptr<PairingRegistryDelegateLinux> save_delegate(
53 new PairingRegistryDelegateLinux(task_runner)); 56 new PairingRegistryDelegateLinux(task_runner));
54 scoped_ptr<PairingRegistryDelegateLinux> load_delegate( 57 scoped_ptr<PairingRegistryDelegateLinux> load_delegate(
55 new PairingRegistryDelegateLinux(task_runner)); 58 new PairingRegistryDelegateLinux(task_runner));
56 save_delegate->SetFilenameForTesting(temp_file); 59 save_delegate->SetRegistryPathForTesting(temp_registry);
57 load_delegate->SetFilenameForTesting(temp_file); 60 load_delegate->SetRegistryPathForTesting(temp_registry);
Jamie 2013/07/30 21:35:07 I think we need more unit tests now that the inter
alexeypa (please no reviews) 2013/07/31 21:31:24 Done.
58 61
59 // Save the pairings, then load them using a different delegate to ensure 62 // Save the pairings, then load them using a different delegate to ensure
60 // that the test isn't passing due to cached values. Note that the delegate 63 // that the test isn't passing due to cached values.
61 // doesn't require that the strings it loads and saves are valid JSON, so 64 PairingRegistry::Pairing test_pairing(base::Time::Now(), "xxx", "xxx", "xxx");
62 // we can simplify the test a bit.
63 std::string test_data = "test data";
64 save_delegate->Save( 65 save_delegate->Save(
65 test_data, 66 test_pairing,
66 base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete, 67 base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete,
67 base::Unretained(this), 68 base::Unretained(this),
68 load_delegate.get(), 69 load_delegate.get(),
69 test_data)); 70 test_pairing));
70 71
71 run_loop.Run(); 72 run_loop.Run();
72 73
73 base::DeleteFile(temp_dir, true); 74 base::DeleteFile(temp_dir, true);
74 }; 75 };
75 76
76 } // namespace remoting 77 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698