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_attributes.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(HostAttributesTest, Sanity) { |
| 16 HostAttributes().ToString(); |
| 17 } |
| 18 |
| 19 TEST(HostAttributesTest, DynamicValuesShouldBeEvaluated) { |
| 20 const char key[] = "A-Fake-Trait-Key-In-Host-Traits-Unit-Test"; |
| 21 bool value = false; |
| 22 int evaluated_times = 0; |
| 23 |
| 24 HostAttributes host_attributes; |
| 25 host_attributes.Register( |
| 26 key, base::Bind( |
| 27 [](int* evaluated_times, bool* value) { |
| 28 (*evaluated_times)++; |
| 29 return *value; |
| 30 }, |
| 31 &evaluated_times, &value)); |
| 32 |
| 33 std::string result = host_attributes.ToString(); |
| 34 ASSERT_FALSE(HostAttributes::ContainsAttribute(result, key)); |
| 35 ASSERT_EQ(evaluated_times, 1); |
| 36 |
| 37 value = true; |
| 38 result = host_attributes.ToString(); |
| 39 ASSERT_TRUE(HostAttributes::ContainsAttribute(result, key)); |
| 40 ASSERT_EQ(evaluated_times, 2); |
| 41 } |
| 42 |
| 43 } // namespace remoting |
OLD | NEW |