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

Side by Side Diff: chromeos/cryptohome/system_salt_getter_unittest.cc

Issue 34303002: chromeos: Wait for service to be available when getting system salt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 7 years, 2 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
« no previous file with comments | « chromeos/cryptohome/system_salt_getter.cc ('k') | chromeos/dbus/cryptohome_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chromeos/cryptohome/system_salt_getter.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "chromeos/dbus/fake_cryptohome_client.h"
11 #include "chromeos/dbus/fake_dbus_thread_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace chromeos {
15 namespace {
16
17 // Used as a GetSystemSaltCallback.
18 void CopySystemSalt(std::string* out_system_salt,
19 const std::string& system_salt) {
20 *out_system_salt = system_salt;
21 }
22
23 class SystemSaltGetterTest : public testing::Test {
24 protected:
25 SystemSaltGetterTest() : fake_cryptohome_client_(NULL) {}
26
27 virtual void SetUp() OVERRIDE {
28 FakeDBusThreadManager* dbus_thread_manager = new FakeDBusThreadManager;
29 fake_cryptohome_client_ = dbus_thread_manager->fake_cryptohome_client();
30 DBusThreadManager::InitializeForTesting(dbus_thread_manager);
31
32 EXPECT_FALSE(SystemSaltGetter::IsInitialized());
33 SystemSaltGetter::Initialize();
34 ASSERT_TRUE(SystemSaltGetter::IsInitialized());
35 ASSERT_TRUE(SystemSaltGetter::Get());
36 }
37
38 virtual void TearDown() OVERRIDE {
39 SystemSaltGetter::Shutdown();
40 DBusThreadManager::Shutdown();
41 }
42
43 base::MessageLoopForUI message_loop_;
44 FakeCryptohomeClient* fake_cryptohome_client_;
45 };
46
47 TEST_F(SystemSaltGetterTest, GetSystemSalt) {
48 // Try to get system salt before the service becomes available.
49 fake_cryptohome_client_->SetServiceIsAvailable(false);
50 std::string system_salt;
51 SystemSaltGetter::Get()->GetSystemSalt(
52 base::Bind(&CopySystemSalt, &system_salt));
53 base::RunLoop().RunUntilIdle();
54 EXPECT_TRUE(system_salt.empty()); // System salt is not returned yet.
55
56 // Service becomes available.
57 fake_cryptohome_client_->SetServiceIsAvailable(true);
58 const std::string expected_system_salt =
59 SystemSaltGetter::ConvertRawSaltToHexString(
60 FakeCryptohomeClient::GetStubSystemSalt());
61 EXPECT_EQ(expected_system_salt, system_salt); // System salt is returned.
62 }
63
64 } // namespace
65 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/cryptohome/system_salt_getter.cc ('k') | chromeos/dbus/cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698