Chromium Code Reviews| 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..19eb0172e2af09759f225638c856263c4fccb81b |
| --- /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 !max_count_ ? true : (sids_visited_.size() < max_count_); |
|
gab
2016/06/01 16:17:04
So |max_count_| is always 0 or 1. Make it a bool?
|
| + } |
| + |
| + void set_max_count(int count) { max_count_ = count; } |
| + |
| + const std::vector<base::string16> sids_visited() const { |
| + return sids_visited_; |
| + } |
| + |
| + private: |
| + std::vector<base::string16> sids_visited_; |
| + size_t max_count_ = 0; |
| + |
| + 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_LT(0U, visitor.sids_visited().size()); |
|
gab
2016/06/01 16:17:04
Inequalities are more readable with constant on RH
grt (UTC plus 2)
2016/06/01 18:00:47
Okay. I had done it this way for consistency with
gab
2016/06/03 15:13:08
Right but reading inequalities backward is so weir
grt (UTC plus 2)
2016/06/06 01:10:11
I agreed with your logic and changed it as you req
|
| +} |
| + |
| +// Tests that only one user hive is visited when the visitor returns false to |
| +// stop the iteration. |
| +TEST(UserHiveVisitor, VisitOneHive) { |
| + UserHiveVisitor visitor; |
| + |
| + visitor.set_max_count(1); |
| + VisitUserHives( |
| + base::Bind(&UserHiveVisitor::OnUserHive, base::Unretained(&visitor))); |
| + |
| + EXPECT_EQ(1U, visitor.sids_visited().size()); |
| +} |
| + |
| +} // namespace installer |