Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / gcapi / gcapi_omaha_experiment_test.cc
blob43b7bcaeb72f97c2526a22360d3fc365e66db7b3
1 // Copyright 2013 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.
5 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/installer/gcapi/gcapi.h"
9 #include "chrome/installer/gcapi/gcapi_test_registry_overrider.h"
10 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/google_update_experiment_util.h"
12 #include "chrome/installer/util/google_update_settings.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using base::ASCIIToUTF16;
17 namespace {
19 const wchar_t kBrand[] = L"ABCD";
20 const uint16 kUserLevel = GCAPI_INVOKED_STANDARD_SHELL;
22 const wchar_t kSomeExperiments[] = L"myexp=1|Aug 2;yourexp=2|Sep 5";
23 const wchar_t kSomeOtherExperiments[] = L"anotherexp=joe|Jun 7 2008";
24 const wchar_t kSomeMoreExperiments[] = L"moreexp=foo|Jul 31 1999";
26 class GCAPIOmahaExperimentTest : public ::testing::Test {
27 protected:
28 GCAPIOmahaExperimentTest()
29 : brand_(kBrand),
30 reactivation_label_(gcapi_internals::GetGCAPIExperimentLabel(
31 kBrand, gcapi_internals::kReactivationLabel)),
32 relaunch_label_(gcapi_internals::GetGCAPIExperimentLabel(
33 kBrand, gcapi_internals::kRelaunchLabel)) {
36 void VerifyExperimentLabels(const base::string16& expected_labels) {
37 base::string16 actual_labels;
38 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels(false,
39 &actual_labels));
40 EXPECT_EQ(expected_labels, actual_labels);
43 base::string16 brand_;
44 base::string16 reactivation_label_;
45 base::string16 relaunch_label_;
47 const GCAPITestRegistryOverrider gcapi_test_registry_overrider_;
50 TEST_F(GCAPIOmahaExperimentTest, SetReactivationLabelFromEmptyExperiments) {
51 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
52 VerifyExperimentLabels(reactivation_label_);
55 // Test the relaunch label once; all other tests go more in depth, but since
56 // both labels use the same logic underneath there is no need to test both in
57 // depth.
58 TEST_F(GCAPIOmahaExperimentTest, SetRelaunchLabelFromEmptyExperiments) {
59 ASSERT_TRUE(SetRelaunchExperimentLabels(kBrand, kUserLevel));
60 VerifyExperimentLabels(relaunch_label_);
63 TEST_F(GCAPIOmahaExperimentTest, SetReactivationLabelWithExistingExperiments) {
64 GoogleUpdateSettings::SetExperimentLabels(false, kSomeExperiments);
66 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
68 base::string16 expected_labels(kSomeExperiments);
69 expected_labels += google_update::kExperimentLabelSeparator;
70 expected_labels.append(reactivation_label_);
71 VerifyExperimentLabels(expected_labels);
74 TEST_F(GCAPIOmahaExperimentTest,
75 SetReactivationLabelWithExistingIdenticalExperiment) {
76 base::string16 previous_labels(kSomeExperiments);
77 previous_labels += google_update::kExperimentLabelSeparator;
78 previous_labels.append(reactivation_label_);
79 previous_labels += google_update::kExperimentLabelSeparator;
80 previous_labels.append(kSomeOtherExperiments);
81 GoogleUpdateSettings::SetExperimentLabels(false, previous_labels);
83 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
85 base::string16 expected_labels(kSomeExperiments);
86 expected_labels += google_update::kExperimentLabelSeparator;
87 expected_labels.append(kSomeOtherExperiments);
88 expected_labels += google_update::kExperimentLabelSeparator;
89 expected_labels.append(reactivation_label_);
90 VerifyExperimentLabels(expected_labels);
93 TEST_F(GCAPIOmahaExperimentTest,
94 SetReactivationLabelWithExistingIdenticalAtBeginning) {
95 base::string16 previous_labels(reactivation_label_);
96 previous_labels += google_update::kExperimentLabelSeparator;
97 previous_labels.append(kSomeExperiments);
98 GoogleUpdateSettings::SetExperimentLabels(false, previous_labels);
100 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
102 base::string16 expected_labels(kSomeExperiments);
103 expected_labels += google_update::kExperimentLabelSeparator;
104 expected_labels.append(reactivation_label_);
105 VerifyExperimentLabels(expected_labels);
108 TEST_F(GCAPIOmahaExperimentTest,
109 SetReactivationLabelWithFakeMatchInAnExperiment) {
110 base::string16 previous_labels(kSomeExperiments);
111 previous_labels += google_update::kExperimentLabelSeparator;
112 previous_labels.append(L"blah_");
113 // Shouldn't match deletion criteria.
114 previous_labels.append(reactivation_label_);
115 previous_labels += google_update::kExperimentLabelSeparator;
116 previous_labels.append(kSomeOtherExperiments);
117 previous_labels += google_update::kExperimentLabelSeparator;
118 // Should match the deletion criteria.
119 previous_labels.append(reactivation_label_);
120 previous_labels += google_update::kExperimentLabelSeparator;
121 previous_labels.append(kSomeMoreExperiments);
122 GoogleUpdateSettings::SetExperimentLabels(false, previous_labels);
124 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
126 base::string16 expected_labels(kSomeExperiments);
127 expected_labels += google_update::kExperimentLabelSeparator;
128 expected_labels.append(L"blah_");
129 expected_labels.append(reactivation_label_);
130 expected_labels += google_update::kExperimentLabelSeparator;
131 expected_labels.append(kSomeOtherExperiments);
132 expected_labels += google_update::kExperimentLabelSeparator;
133 expected_labels.append(kSomeMoreExperiments);
134 expected_labels += google_update::kExperimentLabelSeparator;
135 expected_labels.append(reactivation_label_);
136 VerifyExperimentLabels(expected_labels);
139 TEST_F(GCAPIOmahaExperimentTest,
140 SetReactivationLabelWithFakeMatchInAnExperimentAndNoRealMatch) {
141 base::string16 previous_labels(kSomeExperiments);
142 previous_labels += google_update::kExperimentLabelSeparator;
143 previous_labels.append(L"blah_");
144 // Shouldn't match deletion criteria.
145 previous_labels.append(reactivation_label_);
146 previous_labels += google_update::kExperimentLabelSeparator;
147 previous_labels.append(kSomeOtherExperiments);
148 GoogleUpdateSettings::SetExperimentLabels(false, previous_labels);
150 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
152 base::string16 expected_labels(kSomeExperiments);
153 expected_labels += google_update::kExperimentLabelSeparator;
154 expected_labels.append(L"blah_");
155 expected_labels.append(reactivation_label_);
156 expected_labels += google_update::kExperimentLabelSeparator;
157 expected_labels.append(kSomeOtherExperiments);
158 expected_labels += google_update::kExperimentLabelSeparator;
159 expected_labels.append(reactivation_label_);
160 VerifyExperimentLabels(expected_labels);
163 TEST_F(GCAPIOmahaExperimentTest,
164 SetReactivationLabelWithExistingEntryWithLabelAsPrefix) {
165 base::string16 previous_labels(kSomeExperiments);
166 previous_labels += google_update::kExperimentLabelSeparator;
167 // Append prefix matching the label, but not followed by '='.
168 previous_labels.append(gcapi_internals::kReactivationLabel);
169 // Shouldn't match deletion criteria.
170 previous_labels.append(kSomeOtherExperiments);
171 GoogleUpdateSettings::SetExperimentLabels(false, previous_labels);
173 ASSERT_TRUE(SetReactivationExperimentLabels(kBrand, kUserLevel));
175 base::string16 expected_labels(kSomeExperiments);
176 expected_labels += google_update::kExperimentLabelSeparator;
177 expected_labels.append(gcapi_internals::kReactivationLabel);
178 expected_labels.append(kSomeOtherExperiments);
179 expected_labels += google_update::kExperimentLabelSeparator;
180 expected_labels.append(reactivation_label_);
181 VerifyExperimentLabels(expected_labels);
184 } // namespace