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 <vector> |
| 6 |
| 7 #include "base/stringprintf.h" |
| 8 #include "breakpad/src/client/windows/common/ipc_protocol.h" |
| 9 #include "chrome/app/breakpad_field_trial_win.h" |
| 10 #include "chrome/app/breakpad_win.h" |
| 11 #include "chrome/common/child_process_logging.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using breakpad_win::g_custom_entries; |
| 15 using breakpad_win::g_experiment_chunks_offset; |
| 16 using breakpad_win::g_num_of_experiments_offset; |
| 17 |
| 18 class ChromeAppBreakpadTest : public testing::Test { |
| 19 public: |
| 20 ChromeAppBreakpadTest() { |
| 21 testing::InitCustomInfoEntries(); |
| 22 } |
| 23 |
| 24 protected: |
| 25 typedef std::vector<string16> Experiments; |
| 26 void ValidateExperimentChunks(const Experiments& experiments) { |
| 27 testing::SetExperimentList(experiments); |
| 28 EXPECT_STREQ(base::StringPrintf(L"%d", experiments.size()).c_str(), |
| 29 (*g_custom_entries)[g_num_of_experiments_offset].value); |
| 30 // We make a copy of the array that we empty as we find the experiments. |
| 31 Experiments experiments_left(experiments); |
| 32 for (int i = 0; i < kMaxReportedExperimentChunks; ++i) { |
| 33 EXPECT_STREQ(base::StringPrintf(L"experiment-chunk-%i", i + 1).c_str(), |
| 34 (*g_custom_entries)[g_experiment_chunks_offset + i].name); |
| 35 if (experiments_left.empty()) { |
| 36 // All other slots should be empty. |
| 37 EXPECT_STREQ( |
| 38 L"", (*g_custom_entries)[g_experiment_chunks_offset + i].value); |
| 39 } else { |
| 40 // We can't guarantee the order, so we must search for them all. |
| 41 Experiments::const_iterator experiment = experiments_left.begin(); |
| 42 while (experiment != experiments_left.end()) { |
| 43 if (wcsstr((*g_custom_entries)[g_experiment_chunks_offset + i].value, |
| 44 experiment->c_str())) { |
| 45 experiment = experiments_left.erase(experiment); |
| 46 } else { |
| 47 ++experiment; |
| 48 } |
| 49 } |
| 50 } |
| 51 } |
| 52 EXPECT_TRUE(experiments_left.empty()); |
| 53 } |
| 54 |
| 55 private: |
| 56 static const wchar_t* kNumExperiments; |
| 57 static const size_t kNumExperimentsSize; |
| 58 }; |
| 59 |
| 60 const wchar_t* ChromeAppBreakpadTest::kNumExperiments = L"num-experiments"; |
| 61 const size_t ChromeAppBreakpadTest::kNumExperimentsSize = |
| 62 wcslen(ChromeAppBreakpadTest::kNumExperiments); |
| 63 |
| 64 TEST_F(ChromeAppBreakpadTest, ExperimentList) { |
| 65 Experiments experiments; |
| 66 experiments.push_back(L"ABCDE-12345"); |
| 67 ValidateExperimentChunks(experiments); |
| 68 |
| 69 experiments.push_back(L"There-You Are"); |
| 70 ValidateExperimentChunks(experiments); |
| 71 |
| 72 experiments.push_back(L"Peter-Sellers"); |
| 73 ValidateExperimentChunks(experiments); |
| 74 |
| 75 experiments.push_back(L"Eat me-Drink me"); |
| 76 ValidateExperimentChunks(experiments); |
| 77 } |
OLD | NEW |