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

Side by Side Diff: chrome/browser/chromeos/settings/install_attributes_unittest.cc

Issue 2851593002: Use ScopedTaskEnvironment instead of MessageLoopForUI in chrome tests. (Closed)
Patch Set: fix-build-error 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/settings/install_attributes.h" 5 #include "chrome/browser/chromeos/settings/install_attributes.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/test/scoped_task_environment.h"
16 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" 17 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h"
17 #include "chromeos/chromeos_paths.h" 18 #include "chromeos/chromeos_paths.h"
18 #include "chromeos/cryptohome/cryptohome_util.h" 19 #include "chromeos/cryptohome/cryptohome_util.h"
19 #include "chromeos/dbus/cryptohome_client.h" 20 #include "chromeos/dbus/cryptohome_client.h"
20 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "google_apis/gaia/gaia_auth_util.h" 22 #include "google_apis/gaia/gaia_auth_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace chromeos { 25 namespace chromeos {
25 26
(...skipping 15 matching lines...) Expand all
41 42
42 } // namespace 43 } // namespace
43 44
44 static const char kTestDomain[] = "example.com"; 45 static const char kTestDomain[] = "example.com";
45 static const char kTestRealm[] = "realm.example.com"; 46 static const char kTestRealm[] = "realm.example.com";
46 static const char kTestDeviceId[] = "133750519"; 47 static const char kTestDeviceId[] = "133750519";
47 static const char kTestUserDeprecated[] = "test@example.com"; 48 static const char kTestUserDeprecated[] = "test@example.com";
48 49
49 class InstallAttributesTest : public testing::Test { 50 class InstallAttributesTest : public testing::Test {
50 protected: 51 protected:
51 InstallAttributesTest() {} 52 InstallAttributesTest()
53 : scoped_task_environment_(
54 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
52 55
53 void SetUp() override { 56 void SetUp() override {
54 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
55 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( 58 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
56 FILE_INSTALL_ATTRIBUTES, GetTempPath(), true, false)); 59 FILE_INSTALL_ATTRIBUTES, GetTempPath(), true, false));
57 DBusThreadManager::Initialize(); 60 DBusThreadManager::Initialize();
58 install_attributes_ = base::MakeUnique<InstallAttributes>( 61 install_attributes_ = base::MakeUnique<InstallAttributes>(
59 DBusThreadManager::Get()->GetCryptohomeClient()); 62 DBusThreadManager::Get()->GetCryptohomeClient());
60 } 63 }
61 64
62 void TearDown() override { DBusThreadManager::Shutdown(); } 65 void TearDown() override { DBusThreadManager::Shutdown(); }
63 66
64 base::FilePath GetTempPath() const { 67 base::FilePath GetTempPath() const {
65 base::FilePath temp_path = base::MakeAbsoluteFilePath(temp_dir_.GetPath()); 68 base::FilePath temp_path = base::MakeAbsoluteFilePath(temp_dir_.GetPath());
66 return temp_path.Append("install_attrs_test"); 69 return temp_path.Append("install_attrs_test");
67 } 70 }
68 71
69 void SetAttribute( 72 void SetAttribute(
70 cryptohome::SerializedInstallAttributes* install_attrs_proto, 73 cryptohome::SerializedInstallAttributes* install_attrs_proto,
71 const std::string& name, 74 const std::string& name,
72 const std::string& value) { 75 const std::string& value) {
73 cryptohome::SerializedInstallAttributes::Attribute* attribute; 76 cryptohome::SerializedInstallAttributes::Attribute* attribute;
74 attribute = install_attrs_proto->add_attributes(); 77 attribute = install_attrs_proto->add_attributes();
75 attribute->set_name(name); 78 attribute->set_name(name);
76 attribute->set_value(value); 79 attribute->set_value(value);
77 } 80 }
78 81
79 base::MessageLoopForUI message_loop_; 82 base::test::ScopedTaskEnvironment scoped_task_environment_;
80 base::ScopedTempDir temp_dir_; 83 base::ScopedTempDir temp_dir_;
81 std::unique_ptr<InstallAttributes> install_attributes_; 84 std::unique_ptr<InstallAttributes> install_attributes_;
82 85
83 InstallAttributes::LockResult LockDeviceAndWaitForResult( 86 InstallAttributes::LockResult LockDeviceAndWaitForResult(
84 policy::DeviceMode device_mode, 87 policy::DeviceMode device_mode,
85 const std::string& domain, 88 const std::string& domain,
86 const std::string& realm, 89 const std::string& realm,
87 const std::string& device_id) { 90 const std::string& device_id) {
88 base::RunLoop loop; 91 base::RunLoop loop;
89 InstallAttributes::LockResult result; 92 InstallAttributes::LockResult result;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 chromeos::DBusMethodCallStatus status = 309 chromeos::DBusMethodCallStatus status =
307 chromeos::DBusMethodCallStatus::DBUS_METHOD_CALL_FAILURE; 310 chromeos::DBusMethodCallStatus::DBUS_METHOD_CALL_FAILURE;
308 install_attributes_->SetBlockDevmodeInTpm( 311 install_attributes_->SetBlockDevmodeInTpm(
309 true, base::Bind(&OnSetBlockDevmode, &status)); 312 true, base::Bind(&OnSetBlockDevmode, &status));
310 base::RunLoop().RunUntilIdle(); 313 base::RunLoop().RunUntilIdle();
311 314
312 EXPECT_EQ(chromeos::DBusMethodCallStatus::DBUS_METHOD_CALL_SUCCESS, status); 315 EXPECT_EQ(chromeos::DBusMethodCallStatus::DBUS_METHOD_CALL_SUCCESS, status);
313 } 316 }
314 317
315 } // namespace chromeos 318 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698