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

Side by Side Diff: remoting/host/pairing_registry_delegate_linux_unittest.cc

Issue 15709005: Linux pairing registry delegate implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer feedback. Created 7 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/pairing_registry_delegate_linux.h"
6
7 #include "base/file_util.h"
8 #include "base/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/timer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace remoting {
16
17 using protocol::PairingRegistry;
18
19 class PairingRegistryDelegateLinuxTest : public testing::Test {
20 public:
21 void SaveComplete(PairingRegistry::Delegate* delegate,
22 PairingRegistry::Pairing pairing,
23 bool success) {
24 EXPECT_TRUE(success);
25 // Load the pairings again to make sure we get what we've just written.
26 delegate->GetPairing(
27 pairing.client_id(),
28 base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad,
29 base::Unretained(this),
30 pairing));
31 }
32
33 void VerifyLoad(PairingRegistry::Pairing expected,
34 PairingRegistry::Pairing actual) {
35 EXPECT_EQ(actual, expected);
36 base::MessageLoop::current()->Quit();
37 }
38 };
39
40 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
41 base::MessageLoop message_loop;
42 base::RunLoop run_loop;
43
44 // Create a temporary directory in order to get a unique name and use a
45 // subdirectory to ensure that the AddPairing method creates the parent
46 // directory if it doesn't exist.
47 base::FilePath temp_dir;
48 file_util::CreateNewTempDirectory("chromoting-test", &temp_dir);
49 base::FilePath temp_file = temp_dir.Append("dir").Append("registry.json");
50
51 scoped_refptr<base::TaskRunner> task_runner =
52 base::ThreadTaskRunnerHandle::Get();
53 scoped_ptr<PairingRegistryDelegateLinux> save_delegate(
54 new PairingRegistryDelegateLinux(task_runner));
55 scoped_ptr<PairingRegistryDelegateLinux> load_delegate(
56 new PairingRegistryDelegateLinux(task_runner));
57 save_delegate->SetFilenameForTesting(temp_file);
58 load_delegate->SetFilenameForTesting(temp_file);
59
60 // Save the pairings, then load them using a different delegate to ensure
61 // that the test isn't passing due to cached values.
62 PairingRegistry::Pairing pairing =
63 PairingRegistry::Pairing::Create("client_id");
64 save_delegate->AddPairing(
65 pairing,
66 base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete,
67 base::Unretained(this),
68 load_delegate.get(),
69 pairing));
70
71 run_loop.Run();
72
73 file_util::Delete(temp_dir, true);
74 };
75
76 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698