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

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 namespace protocol {
17
18 class PairingRegistryDelegateLinuxTest : public testing::Test {
19 public:
20 void SaveComplete(PairingRegistry::Delegate* delegate,
21 PairingRegistry::Pairing pairing,
22 bool success) {
23 EXPECT_TRUE(success);
24 // 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.
25 delegate->GetPairing(
26 pairing.client_id(),
27 base::Bind(&PairingRegistryDelegateLinuxTest::VerifyLoad,
28 base::Unretained(this),
29 pairing));
30 }
31
32 void VerifyLoad(PairingRegistry::Pairing expected,
33 PairingRegistry::Pairing actual) {
34 EXPECT_EQ(actual, expected);
35 base::MessageLoop::current()->Quit();
36 }
37 };
38
39 TEST_F(PairingRegistryDelegateLinuxTest, SaveAndLoad) {
40 base::MessageLoop message_loop;
41 base::RunLoop run_loop;
42
43 // Create a temporary directory in order to get a unique name, then delete
44 // it so that we can ensure that the AddPairing method creates the parent
45 // directory if it doesn't exist.
46 base::FilePath temp_dir;
47 file_util::CreateNewTempDirectory("chromoting-test", &temp_dir);
48 base::FilePath temp_file = temp_dir.Append("registry.json");
49 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.
50
51 PairingRegistryDelegateLinux* delegate =
52 new PairingRegistryDelegateLinux(base::ThreadTaskRunnerHandle::Get());
53 delegate->SetFilenameForTesting(temp_file);
54
55 PairingRegistry::Pairing pairing =
56 PairingRegistry::Pairing::Create("client_id");
57 delegate->AddPairing(
58 pairing,
59 base::Bind(&PairingRegistryDelegateLinuxTest::SaveComplete,
60 base::Unretained(this),
61 delegate,
62 pairing));
63
64 run_loop.Run();
65
66 file_util::Delete(temp_dir, true);
67 };
68
69 } // namespace protocol
70 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698