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

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

Issue 2845973003: Use ScopedTaskEnvironment instead of MessageLoopForUI in chromeos tests. (Closed)
Patch Set: CR Created 3 years, 7 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
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 "chromeos/cryptohome/system_salt_getter.h" 5 #include "chromeos/cryptohome/system_salt_getter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/scoped_task_environment.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/fake_cryptohome_client.h" 11 #include "chromeos/dbus/fake_cryptohome_client.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace chromeos { 14 namespace chromeos {
15 namespace { 15 namespace {
16 16
17 // Used as a GetSystemSaltCallback. 17 // Used as a GetSystemSaltCallback.
18 void CopySystemSalt(std::string* out_system_salt, 18 void CopySystemSalt(std::string* out_system_salt,
19 const std::string& system_salt) { 19 const std::string& system_salt) {
20 *out_system_salt = system_salt; 20 *out_system_salt = system_salt;
21 } 21 }
22 22
23 class SystemSaltGetterTest : public testing::Test { 23 class SystemSaltGetterTest : public testing::Test {
24 protected: 24 protected:
25 SystemSaltGetterTest() : fake_cryptohome_client_(NULL) {} 25 SystemSaltGetterTest()
26 : scoped_task_environment_(
27 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
26 28
27 void SetUp() override { 29 void SetUp() override {
28 fake_cryptohome_client_ = new FakeCryptohomeClient; 30 fake_cryptohome_client_ = new FakeCryptohomeClient;
29 DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( 31 DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient(
30 std::unique_ptr<CryptohomeClient>(fake_cryptohome_client_)); 32 std::unique_ptr<CryptohomeClient>(fake_cryptohome_client_));
31 33
32 EXPECT_FALSE(SystemSaltGetter::IsInitialized()); 34 EXPECT_FALSE(SystemSaltGetter::IsInitialized());
33 SystemSaltGetter::Initialize(); 35 SystemSaltGetter::Initialize();
34 ASSERT_TRUE(SystemSaltGetter::IsInitialized()); 36 ASSERT_TRUE(SystemSaltGetter::IsInitialized());
35 ASSERT_TRUE(SystemSaltGetter::Get()); 37 ASSERT_TRUE(SystemSaltGetter::Get());
36 } 38 }
37 39
38 void TearDown() override { 40 void TearDown() override {
39 SystemSaltGetter::Shutdown(); 41 SystemSaltGetter::Shutdown();
40 DBusThreadManager::Shutdown(); 42 DBusThreadManager::Shutdown();
41 } 43 }
42 44
43 base::MessageLoopForUI message_loop_; 45 base::test::ScopedTaskEnvironment scoped_task_environment_;
44 FakeCryptohomeClient* fake_cryptohome_client_; 46 FakeCryptohomeClient* fake_cryptohome_client_ = nullptr;
45 }; 47 };
46 48
47 TEST_F(SystemSaltGetterTest, GetSystemSalt) { 49 TEST_F(SystemSaltGetterTest, GetSystemSalt) {
48 // Try to get system salt before the service becomes available. 50 // Try to get system salt before the service becomes available.
49 fake_cryptohome_client_->SetServiceIsAvailable(false); 51 fake_cryptohome_client_->SetServiceIsAvailable(false);
50 std::string system_salt; 52 std::string system_salt;
51 SystemSaltGetter::Get()->GetSystemSalt( 53 SystemSaltGetter::Get()->GetSystemSalt(
52 base::Bind(&CopySystemSalt, &system_salt)); 54 base::Bind(&CopySystemSalt, &system_salt));
53 base::RunLoop().RunUntilIdle(); 55 base::RunLoop().RunUntilIdle();
54 EXPECT_TRUE(system_salt.empty()); // System salt is not returned yet. 56 EXPECT_TRUE(system_salt.empty()); // System salt is not returned yet.
55 57
56 // Service becomes available. 58 // Service becomes available.
57 fake_cryptohome_client_->SetServiceIsAvailable(true); 59 fake_cryptohome_client_->SetServiceIsAvailable(true);
58 base::RunLoop().RunUntilIdle(); 60 base::RunLoop().RunUntilIdle();
59 const std::string expected_system_salt = 61 const std::string expected_system_salt =
60 SystemSaltGetter::ConvertRawSaltToHexString( 62 SystemSaltGetter::ConvertRawSaltToHexString(
61 FakeCryptohomeClient::GetStubSystemSalt()); 63 FakeCryptohomeClient::GetStubSystemSalt());
62 EXPECT_EQ(expected_system_salt, system_salt); // System salt is returned. 64 EXPECT_EQ(expected_system_salt, system_salt); // System salt is returned.
63 } 65 }
64 66
65 } // namespace 67 } // namespace
66 } // namespace chromeos 68 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/audio/cras_audio_handler_unittest.cc ('k') | chromeos/network/firewall_hole_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698