Index: remoting/host/host_attributes_unittest.cc |
diff --git a/remoting/host/host_attributes_unittest.cc b/remoting/host/host_attributes_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e0268727c5d558471815b23854fcc66324475ac |
--- /dev/null |
+++ b/remoting/host/host_attributes_unittest.cc |
@@ -0,0 +1,43 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/host/host_attributes.h" |
+ |
+#include <string> |
+ |
+#include "base/bind.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace remoting { |
+ |
+// Ensures there is no DCHECK failure or crash in Register() and Callbacks. |
+TEST(HostAttributesTest, Sanity) { |
+ HostAttributes().ToString(); |
+} |
+ |
+TEST(HostAttributesTest, DynamicValuesShouldBeEvaluated) { |
+ const char key[] = "A-Fake-Trait-Key-In-Host-Traits-Unit-Test"; |
+ bool value = false; |
+ int evaluated_times = 0; |
+ |
+ HostAttributes host_attributes; |
+ host_attributes.Register( |
+ key, base::Bind( |
+ [](int* evaluated_times, bool* value) { |
+ (*evaluated_times)++; |
+ return *value; |
+ }, |
+ &evaluated_times, &value)); |
+ |
+ std::string result = host_attributes.ToString(); |
+ ASSERT_FALSE(HostAttributes::ContainsAttribute(result, key)); |
+ ASSERT_EQ(evaluated_times, 1); |
+ |
+ value = true; |
+ result = host_attributes.ToString(); |
+ ASSERT_TRUE(HostAttributes::ContainsAttribute(result, key)); |
+ ASSERT_EQ(evaluated_times, 2); |
+} |
+ |
+} // namespace remoting |