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

Side by Side Diff: chrome/common/variations/experiment_labels_unittest.cc

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/variations/experiment_labels.h" 5 #include "chrome/common/variations/experiment_labels.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialB", 50 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialB",
51 "Group1", TEST_VALUE_B); 51 "Group1", TEST_VALUE_B);
52 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialC", 52 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialC",
53 "Default", TEST_VALUE_C); 53 "Default", TEST_VALUE_C);
54 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialD", 54 AssociateGoogleVariationID(variations::GOOGLE_UPDATE_SERVICE, "FieldTrialD",
55 "Default", TEST_VALUE_D); // Not actually used. 55 "Default", TEST_VALUE_D); // Not actually used.
56 56
57 for (size_t i = 0; i < arraysize(test_cases); ++i) { 57 for (size_t i = 0; i < arraysize(test_cases); ++i) {
58 // Parse the input groups. 58 // Parse the input groups.
59 base::FieldTrial::ActiveGroups groups; 59 base::FieldTrial::ActiveGroups groups;
60 std::vector<std::string> group_data; 60 std::vector<std::string> group_data = base::SplitString(
61 base::SplitString(test_cases[i].active_group_pairs, '#', &group_data); 61 test_cases[i].active_group_pairs, "#",
62 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
62 ASSERT_EQ(0U, group_data.size() % 2); 63 ASSERT_EQ(0U, group_data.size() % 2);
63 for (size_t j = 0; j < group_data.size(); j += 2) { 64 for (size_t j = 0; j < group_data.size(); j += 2) {
64 base::FieldTrial::ActiveGroup group; 65 base::FieldTrial::ActiveGroup group;
65 group.trial_name = group_data[j]; 66 group.trial_name = group_data[j];
66 group.group_name = group_data[j + 1]; 67 group.group_name = group_data[j + 1];
67 groups.push_back(group); 68 groups.push_back(group);
68 } 69 }
69 70
70 // Parse the expected output. 71 // Parse the expected output.
71 std::vector<std::string> expected_ids_list; 72 std::vector<std::string> expected_ids_list = base::SplitString(
72 base::SplitString(test_cases[i].expected_ids, '#', &expected_ids_list); 73 test_cases[i].expected_ids, "#",
74 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
73 75
74 std::string experiment_labels_string = base::UTF16ToUTF8( 76 std::string experiment_labels_string = base::UTF16ToUTF8(
75 BuildGoogleUpdateExperimentLabel(groups)); 77 BuildGoogleUpdateExperimentLabel(groups));
76 78
77 // Split the VariationIDs from the labels for verification below. 79 // Split the VariationIDs from the labels for verification below.
78 std::vector<std::string> split_labels;
79 std::set<std::string> parsed_ids; 80 std::set<std::string> parsed_ids;
80 base::SplitString(experiment_labels_string, ';', &split_labels); 81 for (const std::string& label : base::SplitString(
81 for (std::vector<std::string>::const_iterator it = split_labels.begin(); 82 experiment_labels_string, ";",
82 it != split_labels.end(); ++it) { 83 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
83 // The ID is precisely between the '=' and '|' characters in each label. 84 // The ID is precisely between the '=' and '|' characters in each label.
84 size_t index_of_equals = it->find('='); 85 size_t index_of_equals = label.find('=');
85 size_t index_of_pipe = it->find('|'); 86 size_t index_of_pipe = label.find('|');
86 ASSERT_NE(std::string::npos, index_of_equals); 87 ASSERT_NE(std::string::npos, index_of_equals);
87 ASSERT_NE(std::string::npos, index_of_pipe); 88 ASSERT_NE(std::string::npos, index_of_pipe);
88 ASSERT_GT(index_of_pipe, index_of_equals); 89 ASSERT_GT(index_of_pipe, index_of_equals);
89 parsed_ids.insert(it->substr(index_of_equals + 1, 90 parsed_ids.insert(label.substr(index_of_equals + 1,
90 index_of_pipe - index_of_equals - 1)); 91 index_of_pipe - index_of_equals - 1));
91 } 92 }
92 93
93 // Verify that the resulting string contains each of the expected labels, 94 // Verify that the resulting string contains each of the expected labels,
94 // and nothing more. Note that the date is stripped out and ignored. 95 // and nothing more. Note that the date is stripped out and ignored.
95 for (std::vector<std::string>::const_iterator it = 96 for (std::vector<std::string>::const_iterator it =
96 expected_ids_list.begin(); it != expected_ids_list.end(); ++it) { 97 expected_ids_list.begin(); it != expected_ids_list.end(); ++it) {
97 std::set<std::string>::iterator it2 = parsed_ids.find(*it); 98 std::set<std::string>::iterator it2 = parsed_ids.find(*it);
98 EXPECT_TRUE(parsed_ids.end() != it2); 99 EXPECT_TRUE(parsed_ids.end() != it2);
99 parsed_ids.erase(it2); 100 parsed_ids.erase(it2);
100 } 101 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 for (size_t i = 0; i < arraysize(test_cases); ++i) { 186 for (size_t i = 0; i < arraysize(test_cases); ++i) {
186 std::string non_variation_labels = base::UTF16ToUTF8( 187 std::string non_variation_labels = base::UTF16ToUTF8(
187 ExtractNonVariationLabels( 188 ExtractNonVariationLabels(
188 base::ASCIIToUTF16(test_cases[i].input_label))); 189 base::ASCIIToUTF16(test_cases[i].input_label)));
189 EXPECT_EQ(test_cases[i].expected_output, non_variation_labels); 190 EXPECT_EQ(test_cases[i].expected_output, non_variation_labels);
190 } 191 }
191 } 192 }
192 193
193 } // namespace chrome_variations 194 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_unittest.cc ('k') | chrome/common/variations/variations_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698