| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/mock_log.h" |
| 11 #include "components/policy/core/common/fake_async_policy_loader.h" | 12 #include "components/policy/core/common/fake_async_policy_loader.h" |
| 12 #include "policy/policy_constants.h" | 13 #include "policy/policy_constants.h" |
| 13 #include "remoting/host/dns_blackhole_checker.h" | 14 #include "remoting/host/dns_blackhole_checker.h" |
| 14 #include "remoting/host/policy_watcher.h" | 15 #include "remoting/host/policy_watcher.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 | 20 |
| 20 namespace key = ::policy::key; | 21 namespace key = ::policy::key; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 testing::InSequence sequence; | 433 testing::InSequence sequence; |
| 433 EXPECT_CALL(mock_policy_callback_, | 434 EXPECT_CALL(mock_policy_callback_, |
| 434 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); | 435 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
| 435 | 436 |
| 436 SetPolicies(empty_); | 437 SetPolicies(empty_); |
| 437 StartWatching(); | 438 StartWatching(); |
| 438 SetPolicies(unknown_policies_); | 439 SetPolicies(unknown_policies_); |
| 439 SetPolicies(empty_); | 440 SetPolicies(empty_); |
| 440 } | 441 } |
| 441 | 442 |
| 443 class MisspelledPolicyTest : public PolicyWatcherTest, |
| 444 public ::testing::WithParamInterface<const char*> { |
| 445 }; |
| 446 |
| 447 // Verify that a misspelled policy causes a warning written to the log. |
| 448 TEST_P(MisspelledPolicyTest, WarningLogged) { |
| 449 const char* misspelled_policy_name = GetParam(); |
| 450 base::test::MockLog mock_log; |
| 451 |
| 452 ON_CALL(mock_log, Log(testing::_, testing::_, testing::_, testing::_, |
| 453 testing::_)).WillByDefault(testing::Return(true)); |
| 454 |
| 455 EXPECT_CALL(mock_log, |
| 456 Log(logging::LOG_WARNING, testing::_, testing::_, testing::_, |
| 457 testing::HasSubstr(misspelled_policy_name))).Times(1); |
| 458 |
| 459 EXPECT_CALL(mock_policy_callback_, |
| 460 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
| 461 |
| 462 base::DictionaryValue misspelled_policies; |
| 463 misspelled_policies.SetString(misspelled_policy_name, "some test value"); |
| 464 mock_log.StartCapturingLogs(); |
| 465 |
| 466 SetPolicies(misspelled_policies); |
| 467 StartWatching(); |
| 468 |
| 469 mock_log.StopCapturingLogs(); |
| 470 } |
| 471 |
| 472 INSTANTIATE_TEST_CASE_P( |
| 473 PolicyWatcherTest, |
| 474 MisspelledPolicyTest, |
| 475 ::testing::Values("RemoteAccessHostDomainX", |
| 476 "XRemoteAccessHostDomain", |
| 477 "RemoteAccessHostdomain", |
| 478 "RemoteAccessHostPolicyForFutureVersion")); |
| 479 |
| 442 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { | 480 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { |
| 443 #if !defined(NDEBUG) | 481 #if !defined(NDEBUG) |
| 444 EXPECT_CALL( | 482 EXPECT_CALL( |
| 445 mock_policy_callback_, | 483 mock_policy_callback_, |
| 446 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); | 484 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); |
| 447 #else | 485 #else |
| 448 EXPECT_CALL(mock_policy_callback_, | 486 EXPECT_CALL(mock_policy_callback_, |
| 449 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); | 487 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
| 450 #endif | 488 #endif |
| 451 | 489 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } | 743 } |
| 706 | 744 |
| 707 // Today, the only verification offered by this test is: | 745 // Today, the only verification offered by this test is: |
| 708 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy | 746 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy |
| 709 // - Automated verification that nothing crashed | 747 // - Automated verification that nothing crashed |
| 710 } | 748 } |
| 711 | 749 |
| 712 #endif | 750 #endif |
| 713 | 751 |
| 714 } // namespace remoting | 752 } // namespace remoting |
| OLD | NEW |