Commit bfe7577b authored by lukasza's avatar lukasza Committed by Commit bot

Unit tests for misspelled policy names.

This verifies that we detect and report misspelled policy names
regardless of whether "RemoteAccessHost" appears as a prefix,
suffix or a substring.  I felt adding this test is important
to "document" the behavior asked about in
https://codereview.chromium.org/966433002/diff/120001/remoting/host/policy_watcher.cc#newcode109

The new test verifies expected behavior via MockLog class moved to base/test in
crrev.com/966423003.  I feel that the benefit of documenting and automatically
verifying the expected behavior outweights the small maintenence cost of an
additional test and the slight ickyness of verifying the behavior by looking at
log output.

BUG=

Review URL: https://codereview.chromium.org/979823004

Cr-Commit-Position: refs/heads/master@{#319172}
parent 9589b67f
......@@ -8,6 +8,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/mock_log.h"
#include "components/policy/core/common/fake_async_policy_loader.h"
#include "policy/policy_constants.h"
#include "remoting/host/dns_blackhole_checker.h"
......@@ -439,6 +440,43 @@ TEST_F(PolicyWatcherTest, FilterUnknownPolicies) {
SetPolicies(empty_);
}
class MisspelledPolicyTest : public PolicyWatcherTest,
public ::testing::WithParamInterface<const char*> {
};
// Verify that a misspelled policy causes a warning written to the log.
TEST_P(MisspelledPolicyTest, WarningLogged) {
const char* misspelled_policy_name = GetParam();
base::test::MockLog mock_log;
ON_CALL(mock_log, Log(testing::_, testing::_, testing::_, testing::_,
testing::_)).WillByDefault(testing::Return(true));
EXPECT_CALL(mock_log,
Log(logging::LOG_WARNING, testing::_, testing::_, testing::_,
testing::HasSubstr(misspelled_policy_name))).Times(1);
EXPECT_CALL(mock_policy_callback_,
OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
base::DictionaryValue misspelled_policies;
misspelled_policies.SetString(misspelled_policy_name, "some test value");
mock_log.StartCapturingLogs();
SetPolicies(misspelled_policies);
StartWatching();
mock_log.StopCapturingLogs();
}
INSTANTIATE_TEST_CASE_P(
PolicyWatcherTest,
MisspelledPolicyTest,
::testing::Values("RemoteAccessHostDomainX",
"XRemoteAccessHostDomain",
"RemoteAccessHostdomain",
"RemoteAccessHostPolicyForFutureVersion"));
TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) {
#if !defined(NDEBUG)
EXPECT_CALL(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment