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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/setup/user_hive_visitor.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/setup/user_hive_visitor_unittest.cc
diff --git a/chrome/installer/setup/user_hive_visitor_unittest.cc b/chrome/installer/setup/user_hive_visitor_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c44a63e89179726f1646a426063da878350012a4
--- /dev/null
+++ b/chrome/installer/setup/user_hive_visitor_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/setup/user_hive_visitor.h"
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/macros.h"
+#include "base/strings/string16.h"
+#include "base/win/registry.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace installer {
+
+namespace {
+
+class UserHiveVisitor {
+ public:
+ UserHiveVisitor() = default;
+
+ bool OnUserHive(const wchar_t* sid, base::win::RegKey* key) {
+ EXPECT_NE(nullptr, sid);
+ EXPECT_STRNE(L"", sid);
+ EXPECT_NE(nullptr, key);
+ EXPECT_TRUE(key->Valid());
+ sids_visited_.push_back(sid);
+ return !early_exit_;
+ }
+
+ void set_early_exit(bool early_exit) { early_exit_ = early_exit; }
+
+ const std::vector<base::string16> sids_visited() const {
+ return sids_visited_;
+ }
+
+ private:
+ std::vector<base::string16> sids_visited_;
+ bool early_exit_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(UserHiveVisitor);
+};
+
+} // namespace
+
+// Tests that the visitor visits at least one user hive. This will succeed even
+// when run as an ordinary user, as the current user's hive is always available.
+TEST(UserHiveVisitorTest, VisitAllUserHives) {
+ UserHiveVisitor visitor;
+
+ VisitUserHives(
+ base::Bind(&UserHiveVisitor::OnUserHive, base::Unretained(&visitor)));
+
+ EXPECT_GT(visitor.sids_visited().size(), 0U);
+}
+
+// Tests that only one user hive is visited when the visitor returns false to
+// stop the iteration.
+TEST(UserHiveVisitor, VisitOneHive) {
+ UserHiveVisitor visitor;
+
+ visitor.set_early_exit(true);
+ VisitUserHives(
+ base::Bind(&UserHiveVisitor::OnUserHive, base::Unretained(&visitor)));
+
+ EXPECT_EQ(1U, visitor.sids_visited().size());
+}
+
+} // namespace installer
« 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