Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: chrome/installer/util/experiment_labels_unittest.cc

Issue 2872583002: Adding ExperimentLabels helper class. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/installer/util/experiment_labels_unittest.cc
diff --git a/chrome/installer/util/experiment_labels_unittest.cc b/chrome/installer/util/experiment_labels_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c69ec2f71edbe23ffce0657a9eac37b82ab982c
--- /dev/null
+++ b/chrome/installer/util/experiment_labels_unittest.cc
@@ -0,0 +1,83 @@
+// Copyright 2017 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 "chrome/installer/util/experiment_labels.h"
+
+#include "base/strings/string_piece.h"
+#include "base/time/time.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::HasSubstr;
+using ::testing::StartsWith;
+using ::testing::StrEq;
+
+namespace installer {
+
+TEST(ExperimentLabels, value) {
Patrick Monette 2017/05/08 15:27:48 s/value/Value? I have never seen a test name with
grt (UTC plus 2) 2017/05/08 20:15:26 Done. I did that 'cause the method it is testing i
+ static constexpr wchar_t kDummyValue[] =
+ L"name=value|Fri, 14 Aug 2015 16:13:03 GMT";
+ ExperimentLabels labels(kDummyValue);
+
+ EXPECT_THAT(labels.value(), StrEq(kDummyValue));
+}
+
+TEST(ExperimentLabels, GetValueForLabel) {
+ static constexpr wchar_t kDummyValue[] =
+ L"name=value|Fri, 14 Aug 2015 16:13:03 GMT;"
+ L"name2=value2|Fri, 14 Aug 2015 16:13:03 GMT";
+ ExperimentLabels labels(kDummyValue);
+
+ base::StringPiece16 value = labels.GetValueForLabel(L"name");
+ EXPECT_THAT(value.as_string().c_str(), StrEq(L"value"));
+
+ value = labels.GetValueForLabel(L"name2");
+ EXPECT_THAT(value.as_string().c_str(), StrEq(L"value2"));
+
+ value = labels.GetValueForLabel(L"name3");
+ EXPECT_TRUE(value.empty());
+}
+
+TEST(ExperimentLabels, SetValueForLabel) {
+ ExperimentLabels label(L"");
+
+ label.SetValueForLabel(L"name", L"value", base::TimeDelta::FromSeconds(1));
+ base::StringPiece16 value = label.GetValueForLabel(L"name");
+ EXPECT_THAT(value.as_string().c_str(), StrEq(L"value"));
+ EXPECT_THAT(label.value(), StartsWith(L"name=value|"));
+
+ label.SetValueForLabel(L"name", L"othervalue",
+ base::TimeDelta::FromSeconds(1));
+ value = label.GetValueForLabel(L"name");
+ EXPECT_THAT(value.as_string().c_str(), StrEq(L"othervalue"));
+ EXPECT_THAT(label.value(), StartsWith(L"name=othervalue|"));
+
+ label.SetValueForLabel(L"othername", L"somevalue",
+ base::TimeDelta::FromSeconds(1));
+ value = label.GetValueForLabel(L"othername");
+ EXPECT_THAT(value.as_string().c_str(), StrEq(L"somevalue"));
+ EXPECT_THAT(label.value(), HasSubstr(L"name=othervalue|"));
+ EXPECT_THAT(label.value(), HasSubstr(L"othername=somevalue|"));
+}
+
+TEST(ExperimentLabels, TimeFormatting) {
+ base::Time::Exploded exploded = {};
+ exploded.year = 2015;
+ exploded.month = 8;
+ exploded.day_of_week = 5;
+ exploded.day_of_month = 14;
+ exploded.hour = 16;
+ exploded.minute = 13;
+ exploded.second = 3;
+
+ base::Time time;
+ ASSERT_TRUE(base::Time::FromUTCExploded(exploded, &time));
+
+ ExperimentLabels label(L"");
+ label.SetValueForLabel(L"name", L"value", time);
+ EXPECT_THAT(label.value(),
+ StrEq(L"name=value|Fri, 14 Aug 2015 16:13:03 GMT"));
+}
+
+} // namespace installer
« chrome/installer/util/experiment_labels.cc ('K') | « chrome/installer/util/experiment_labels.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698