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

Side by Side Diff: chrome/installer/setup/user_hive_visitor_unittest.cc

Issue 2027063002: Introduce UserHiveVisitor for performing operations on local users' registry hives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gab review Created 4 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
« no previous file with comments | « chrome/installer/setup/user_hive_visitor.cc ('k') | no next file » | 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 2016 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 "chrome/installer/setup/user_hive_visitor.h"
6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/macros.h"
11 #include "base/strings/string16.h"
12 #include "base/win/registry.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace installer {
16
17 namespace {
18
19 class UserHiveVisitor {
20 public:
21 UserHiveVisitor() = default;
22
23 bool OnUserHive(const wchar_t* sid, base::win::RegKey* key) {
24 EXPECT_NE(nullptr, sid);
25 EXPECT_STRNE(L"", sid);
26 EXPECT_NE(nullptr, key);
27 EXPECT_TRUE(key->Valid());
28 sids_visited_.push_back(sid);
29 return !early_exit_;
30 }
31
32 void set_early_exit(bool early_exit) { early_exit_ = early_exit; }
33
34 const std::vector<base::string16> sids_visited() const {
35 return sids_visited_;
36 }
37
38 private:
39 std::vector<base::string16> sids_visited_;
40 bool early_exit_ = false;
41
42 DISALLOW_COPY_AND_ASSIGN(UserHiveVisitor);
43 };
44
45 } // namespace
46
47 // Tests that the visitor visits at least one user hive. This will succeed even
48 // when run as an ordinary user, as the current user's hive is always available.
49 TEST(UserHiveVisitorTest, VisitAllUserHives) {
50 UserHiveVisitor visitor;
51
52 VisitUserHives(
53 base::Bind(&UserHiveVisitor::OnUserHive, base::Unretained(&visitor)));
54
55 EXPECT_GT(visitor.sids_visited().size(), 0U);
56 }
57
58 // Tests that only one user hive is visited when the visitor returns false to
59 // stop the iteration.
60 TEST(UserHiveVisitor, VisitOneHive) {
61 UserHiveVisitor visitor;
62
63 visitor.set_early_exit(true);
64 VisitUserHives(
65 base::Bind(&UserHiveVisitor::OnUserHive, base::Unretained(&visitor)));
66
67 EXPECT_EQ(1U, visitor.sids_visited().size());
68 }
69
70 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/user_hive_visitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698