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

Unified Diff: components/policy/core/common/preg_parser_unittest.cc

Issue 2860973002: Allow PolicyLoadStatusSample to override reporting method (Closed)
Patch Set: Change lambda bind to a more classical bind. 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/preg_parser_unittest.cc
diff --git a/components/policy/core/common/preg_parser_unittest.cc b/components/policy/core/common/preg_parser_unittest.cc
index d45a57bd7d13ea1f1d3cec9fda597830b3cca091..b9841c51085a8d28d4772f0a91ba3430b1da7b7d 100644
--- a/components/policy/core/common/preg_parser_unittest.cc
+++ b/components/policy/core/common/preg_parser_unittest.cc
@@ -7,6 +7,7 @@
#include <utility>
#include "base/base_paths.h"
+#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
@@ -26,6 +27,7 @@ namespace {
const char kRegistryPolBaseDir[] = "chrome/test/data/policy/gpo";
const char kRegistryPolFile[] = "parser_test/registry.pol";
const char kInvalidEncodingRegistryPolFile[] = "invalid_encoding/registry.pol";
+const char kNonExistingRegistryPolFile[] = "does_not_exist.pol";
const char kRegistryKey[] = "SOFTWARE\\Policies\\Chromium";
@@ -173,6 +175,31 @@ TEST_F(PRegParserTest, RejectInvalidStrings) {
EXPECT_TRUE(RegistryDictEquals(dict, empty));
}
+TEST_F(PRegParserTest, OverrideReportCallback) {
+ // Tests overriding the PolicyLoadStatusSample's ReportCallback.
+ std::bitset<POLICY_LOAD_STATUS_SIZE> status_bits;
+ PolicyLoadStatusSample::ReportCallback report_callback =
+ base::Bind([](std::bitset<POLICY_LOAD_STATUS_SIZE>* status_bits,
+ PolicyLoadStatus status) { (*status_bits)[status] = true; },
+ &status_bits);
+
+ {
+ // Needs to be scoped because reporting happens in the destructor of
+ // PolicyLoadStatusSample.
+ PolicyLoadStatusSample status(report_callback);
+ RegistryDict dict;
+ base::FilePath test_file(
+ test_data_dir_.AppendASCII(kNonExistingRegistryPolFile));
+ ASSERT_FALSE(preg_parser::ReadFile(
+ test_file, base::ASCIIToUTF16(kRegistryKey), &dict, &status));
+ }
+
+ std::bitset<POLICY_LOAD_STATUS_SIZE> expected_status_bits;
+ expected_status_bits[POLICY_LOAD_STATUS_STARTED] = true;
+ expected_status_bits[POLICY_LOAD_STATUS_READ_ERROR] = true;
+ EXPECT_EQ(expected_status_bits, status_bits);
+}
+
} // namespace
} // namespace preg_parser
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698