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