OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "chrome/installer/util/experiment_labels.h" |
| 6 |
| 7 #include "base/strings/string_piece.h" |
| 8 #include "base/time/time.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 using ::testing::HasSubstr; |
| 13 using ::testing::StartsWith; |
| 14 using ::testing::StrEq; |
| 15 |
| 16 namespace installer { |
| 17 |
| 18 TEST(ExperimentLabels, Value) { |
| 19 static constexpr wchar_t kDummyValue[] = |
| 20 L"name=value|Fri, 14 Aug 2015 16:13:03 GMT"; |
| 21 ExperimentLabels labels(kDummyValue); |
| 22 |
| 23 EXPECT_THAT(labels.value(), StrEq(kDummyValue)); |
| 24 } |
| 25 |
| 26 TEST(ExperimentLabels, GetValueForLabel) { |
| 27 static constexpr wchar_t kDummyValue[] = |
| 28 L"name=value|Fri, 14 Aug 2015 16:13:03 GMT;" |
| 29 L"name2=value2|Fri, 14 Aug 2015 16:13:03 GMT"; |
| 30 ExperimentLabels labels(kDummyValue); |
| 31 |
| 32 base::StringPiece16 value = labels.GetValueForLabel(L"name"); |
| 33 EXPECT_THAT(value.as_string().c_str(), StrEq(L"value")); |
| 34 |
| 35 value = labels.GetValueForLabel(L"name2"); |
| 36 EXPECT_THAT(value.as_string().c_str(), StrEq(L"value2")); |
| 37 |
| 38 value = labels.GetValueForLabel(L"name3"); |
| 39 EXPECT_TRUE(value.empty()); |
| 40 } |
| 41 |
| 42 TEST(ExperimentLabels, SetValueForLabel) { |
| 43 ExperimentLabels label(L""); |
| 44 |
| 45 label.SetValueForLabel(L"name", L"value", base::TimeDelta::FromSeconds(1)); |
| 46 base::StringPiece16 value = label.GetValueForLabel(L"name"); |
| 47 EXPECT_THAT(value.as_string().c_str(), StrEq(L"value")); |
| 48 EXPECT_THAT(label.value(), StartsWith(L"name=value|")); |
| 49 |
| 50 label.SetValueForLabel(L"name", L"othervalue", |
| 51 base::TimeDelta::FromSeconds(1)); |
| 52 value = label.GetValueForLabel(L"name"); |
| 53 EXPECT_THAT(value.as_string().c_str(), StrEq(L"othervalue")); |
| 54 EXPECT_THAT(label.value(), StartsWith(L"name=othervalue|")); |
| 55 |
| 56 label.SetValueForLabel(L"othername", L"somevalue", |
| 57 base::TimeDelta::FromSeconds(1)); |
| 58 value = label.GetValueForLabel(L"othername"); |
| 59 EXPECT_THAT(value.as_string().c_str(), StrEq(L"somevalue")); |
| 60 EXPECT_THAT(label.value(), HasSubstr(L"name=othervalue|")); |
| 61 EXPECT_THAT(label.value(), HasSubstr(L"othername=somevalue|")); |
| 62 } |
| 63 |
| 64 TEST(ExperimentLabels, TimeFormatting) { |
| 65 base::Time::Exploded exploded = {}; |
| 66 exploded.year = 2015; |
| 67 exploded.month = 8; |
| 68 exploded.day_of_week = 5; |
| 69 exploded.day_of_month = 14; |
| 70 exploded.hour = 16; |
| 71 exploded.minute = 13; |
| 72 exploded.second = 3; |
| 73 |
| 74 base::Time time; |
| 75 ASSERT_TRUE(base::Time::FromUTCExploded(exploded, &time)); |
| 76 |
| 77 ExperimentLabels label(L""); |
| 78 label.SetValueForLabel(L"name", L"value", time); |
| 79 EXPECT_THAT(label.value(), |
| 80 StrEq(L"name=value|Fri, 14 Aug 2015 16:13:03 GMT")); |
| 81 } |
| 82 |
| 83 } // namespace installer |
OLD | NEW |