diff options
author | lukasza <lukasza@chromium.org> | 2015-03-04 16:28:12 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-05 00:28:57 +0000 |
commit | bfe7577b0faa92b2fc912b7bbfe85bd994ac7e33 (patch) | |
tree | ba2f4ba4050cdd08932a11fcd8d1818485290323 | |
parent | 9589b67f3b415a742c7f65ebd106e202f5a01f42 (diff) | |
download | chromium_src-bfe7577b0faa92b2fc912b7bbfe85bd994ac7e33.zip chromium_src-bfe7577b0faa92b2fc912b7bbfe85bd994ac7e33.tar.gz chromium_src-bfe7577b0faa92b2fc912b7bbfe85bd994ac7e33.tar.bz2 |
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}
-rw-r--r-- | remoting/host/policy_watcher_unittest.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/remoting/host/policy_watcher_unittest.cc b/remoting/host/policy_watcher_unittest.cc index 843e4a3..9845828 100644 --- a/remoting/host/policy_watcher_unittest.cc +++ b/remoting/host/policy_watcher_unittest.cc @@ -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( |