Index: chrome/app/breakpad_win_unittest.cc |
=================================================================== |
--- chrome/app/breakpad_win_unittest.cc (revision 0) |
+++ chrome/app/breakpad_win_unittest.cc (revision 0) |
@@ -0,0 +1,96 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/metrics/field_trial.h" |
+#include "base/stringprintf.h" |
+#include "breakpad/src/client/windows/common/ipc_protocol.h" |
+#include "chrome/app/breakpad_win.h" |
+#include "chrome/common/child_process_logging.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+class ChromeAppBreakpadTest : public testing::Test { |
+ public: |
+ ChromeAppBreakpadTest() |
+ : custom_info_(testing::TestGetCustomInfo()), |
+ num_experiments_index_(0) { |
+ while (num_experiments_index_ < custom_info_->count) { |
+ if (!wcsncmp(custom_info_->entries[num_experiments_index_].name, |
+ kNumExperiments, kNumExperimentsSize + 1)) { |
+ break; |
+ } |
+ ++num_experiments_index_; |
+ } |
+ // We need room for the kMaxReportedExperimentChunks experiment chunks. |
+ EXPECT_GE(custom_info_->count, |
+ num_experiments_index_ + kMaxReportedExperimentChunks); |
+ } |
+ |
+ protected: |
+ typedef std::vector<base::FieldTrial::NameGroupId> Experiments; |
+ void ValidateExperimentChunks(const Experiments& experiments) { |
+ testing::TestUpdateExperiments(); |
+ EXPECT_STREQ(base::StringPrintf(L"%d", experiments.size()).c_str(), |
+ custom_info_->entries[num_experiments_index_].value); |
+ // We make a copy of the array that we empty as we find the experiments. |
+ Experiments experiments_left(experiments); |
+ for (int i = 1; i <= kMaxReportedExperimentChunks; ++i) { |
+ EXPECT_STREQ(base::StringPrintf(L"experiment-chunk-%i", i).c_str(), |
+ 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
|
+ if (experiments_left.empty()) { |
+ // All other slots should be empty. |
+ EXPECT_STREQ(L"", |
+ custom_info_->entries[num_experiments_index_ + i].value); |
+ } else { |
+ // We can't guarantee the order, so we must search for them all. |
+ Experiments::const_iterator experiment = experiments_left.begin(); |
+ while (experiment != experiments_left.end()) { |
+ std::wstring experiment_str = base::StringPrintf( |
+ L"%x-%x", experiment->name, experiment->group); |
+ if (wcsstr(custom_info_->entries[num_experiments_index_ + i].value, |
+ experiment_str.c_str())) { |
+ experiment = experiments_left.erase(experiment); |
+ } else { |
+ ++experiment; |
+ } |
+ } |
+ } |
+ } |
+ EXPECT_TRUE(experiments_left.empty()); |
+ } |
+ |
+ private: |
+ static const wchar_t* kNumExperiments; |
+ static const size_t kNumExperimentsSize; |
+ google_breakpad::CustomClientInfo* custom_info_; |
+ size_t num_experiments_index_; |
+}; |
+ |
+const wchar_t* ChromeAppBreakpadTest::kNumExperiments = L"num-experiments"; |
+const size_t ChromeAppBreakpadTest::kNumExperimentsSize = |
+ wcslen(ChromeAppBreakpadTest::kNumExperiments); |
+ |
+TEST_F(ChromeAppBreakpadTest, ExperimentList) { |
+ base::FieldTrialList field_trial_list("ABCDE"); |
+ base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial("All", "To"); |
+ base::FieldTrial::NameGroupId name_group_id; |
+ trial->GetNameGroupId(&name_group_id); |
+ Experiments experiments; |
+ experiments.push_back(name_group_id); |
+ ValidateExperimentChunks(experiments); |
+ |
+ trial = base::FieldTrialList::CreateFieldTrial("There", "You Are"); |
+ trial->GetNameGroupId(&name_group_id); |
+ experiments.push_back(name_group_id); |
+ ValidateExperimentChunks(experiments); |
+ |
+ trial = base::FieldTrialList::CreateFieldTrial("Peter", "Sellers"); |
+ trial->GetNameGroupId(&name_group_id); |
+ experiments.push_back(name_group_id); |
+ ValidateExperimentChunks(experiments); |
+ |
+ trial = base::FieldTrialList::CreateFieldTrial("Eat me", "Drink me"); |
+ trial->GetNameGroupId(&name_group_id); |
+ experiments.push_back(name_group_id); |
+ ValidateExperimentChunks(experiments); |
+} |
Property changes on: chrome\app\breakpad_win_unittest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |