OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/host_traits.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 // Ensures there is no DCHECK failure or crash in Register() and Callbacks. |
| 15 TEST(HostTraitsTest, Sanity) { |
| 16 host_traits().ToString(); |
| 17 } |
| 18 |
| 19 TEST(HostTraitsTest, DynamicValuesShouldBeEvaluated) { |
| 20 const char trait_key[] = "A-Fake-Trait-Key-In-Host-Traits-Unit-Test"; |
| 21 bool value = false; |
| 22 int evaluated_times = 0; |
| 23 |
| 24 host_traits().Register(trait_key, |
| 25 base::Bind([](int* evaluated_times, bool* value) { |
| 26 (*evaluated_times)++; |
| 27 return *value; |
| 28 }, &evaluated_times, &value)); |
| 29 |
| 30 std::string result = host_traits().ToString(); |
| 31 ASSERT_FALSE(HostTraits::ContainsTrait(result, trait_key)); |
| 32 ASSERT_EQ(evaluated_times, 1); |
| 33 |
| 34 value = true; |
| 35 result = host_traits().ToString(); |
| 36 ASSERT_TRUE(HostTraits::ContainsTrait(result, trait_key)); |
| 37 ASSERT_EQ(evaluated_times, 2); |
| 38 |
| 39 host_traits().Erase(trait_key); |
| 40 } |
| 41 |
| 42 } // namespace remoting |
OLD | NEW |