Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "base/metrics/field_trial.h" | |
| 6 #include "base/stringprintf.h" | |
| 7 #include "breakpad/src/client/windows/common/ipc_protocol.h" | |
| 8 #include "chrome/app/breakpad_win.h" | |
| 9 #include "chrome/common/child_process_logging.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 class ChromeAppBreakpadTest : public testing::Test { | |
| 13 public: | |
| 14 ChromeAppBreakpadTest() | |
| 15 : custom_info_(testing::TestGetCustomInfo()), | |
| 16 num_experiments_index_(0) { | |
| 17 while (num_experiments_index_ < custom_info_->count) { | |
| 18 if (!wcsncmp(custom_info_->entries[num_experiments_index_].name, | |
| 19 kNumExperiments, kNumExperimentsSize + 1)) { | |
| 20 break; | |
| 21 } | |
| 22 ++num_experiments_index_; | |
| 23 } | |
| 24 // We need room for the kMaxReportedExperimentChunks experiment chunks. | |
| 25 EXPECT_GE(custom_info_->count, | |
| 26 num_experiments_index_ + kMaxReportedExperimentChunks); | |
| 27 } | |
| 28 | |
| 29 protected: | |
| 30 typedef std::vector<base::FieldTrial::NameGroupId> Experiments; | |
| 31 void ValidateExperimentChunks(const Experiments& experiments) { | |
| 32 testing::TestUpdateExperiments(); | |
| 33 EXPECT_STREQ(base::StringPrintf(L"%d", experiments.size()).c_str(), | |
| 34 custom_info_->entries[num_experiments_index_].value); | |
| 35 // We make a copy of the array that we empty as we find the experiments. | |
| 36 Experiments experiments_left(experiments); | |
| 37 for (int i = 1; i <= kMaxReportedExperimentChunks; ++i) { | |
| 38 EXPECT_STREQ(base::StringPrintf(L"experiment-chunk-%i", i).c_str(), | |
| 39 custom_info_->entries[num_experiments_index_ + i].name); | |
|
robertshield
2012/03/14 13:51:48
is there an off-by-one here and in the two places
MAD
2012/03/15 22:37:36
No, it's on purpose, we want the string to be 1 ba
robertshield
2012/03/20 19:24:31
That's unconventional enough to merit a comment ab
| |
| 40 if (experiments_left.empty()) { | |
| 41 // All other slots should be empty. | |
| 42 EXPECT_STREQ(L"", | |
| 43 custom_info_->entries[num_experiments_index_ + i].value); | |
| 44 } else { | |
| 45 // We can't guarantee the order, so we must search for them all. | |
| 46 Experiments::const_iterator experiment = experiments_left.begin(); | |
| 47 while (experiment != experiments_left.end()) { | |
| 48 std::wstring experiment_str = base::StringPrintf( | |
| 49 L"%x-%x", experiment->name, experiment->group); | |
| 50 if (wcsstr(custom_info_->entries[num_experiments_index_ + i].value, | |
| 51 experiment_str.c_str())) { | |
| 52 experiment = experiments_left.erase(experiment); | |
| 53 } else { | |
| 54 ++experiment; | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 EXPECT_TRUE(experiments_left.empty()); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 static const wchar_t* kNumExperiments; | |
| 64 static const size_t kNumExperimentsSize; | |
| 65 google_breakpad::CustomClientInfo* custom_info_; | |
| 66 size_t num_experiments_index_; | |
| 67 }; | |
| 68 | |
| 69 const wchar_t* ChromeAppBreakpadTest::kNumExperiments = L"num-experiments"; | |
| 70 const size_t ChromeAppBreakpadTest::kNumExperimentsSize = | |
| 71 wcslen(ChromeAppBreakpadTest::kNumExperiments); | |
| 72 | |
| 73 TEST_F(ChromeAppBreakpadTest, ExperimentList) { | |
| 74 base::FieldTrialList field_trial_list("ABCDE"); | |
| 75 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial("All", "To"); | |
| 76 base::FieldTrial::NameGroupId name_group_id; | |
| 77 trial->GetNameGroupId(&name_group_id); | |
| 78 Experiments experiments; | |
| 79 experiments.push_back(name_group_id); | |
| 80 ValidateExperimentChunks(experiments); | |
| 81 | |
| 82 trial = base::FieldTrialList::CreateFieldTrial("There", "You Are"); | |
| 83 trial->GetNameGroupId(&name_group_id); | |
| 84 experiments.push_back(name_group_id); | |
| 85 ValidateExperimentChunks(experiments); | |
| 86 | |
| 87 trial = base::FieldTrialList::CreateFieldTrial("Peter", "Sellers"); | |
| 88 trial->GetNameGroupId(&name_group_id); | |
| 89 experiments.push_back(name_group_id); | |
| 90 ValidateExperimentChunks(experiments); | |
| 91 | |
| 92 trial = base::FieldTrialList::CreateFieldTrial("Eat me", "Drink me"); | |
| 93 trial->GetNameGroupId(&name_group_id); | |
| 94 experiments.push_back(name_group_id); | |
| 95 ValidateExperimentChunks(experiments); | |
| 96 } | |
| OLD | NEW |