summaryrefslogtreecommitdiffstats
path: root/chrome/app/breakpad_unittest_win.cc
blob: 75fd8f75845c54827a8a362ebc9588e2d4ba898f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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 <vector>

#include "base/stringprintf.h"
#include "breakpad/src/client/windows/common/ipc_protocol.h"
#include "chrome/app/breakpad_field_trial_win.h"
#include "chrome/app/breakpad_win.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "testing/gtest/include/gtest/gtest.h"

using breakpad_win::g_custom_entries;
using breakpad_win::g_experiment_chunks_offset;
using breakpad_win::g_num_of_experiments_offset;

class ChromeAppBreakpadTest : public testing::Test {
 public:
  ChromeAppBreakpadTest() {
    testing::InitCustomInfoEntries();
  }

 protected:
  typedef std::vector<string16> Experiments;
  void ValidateExperimentChunks(const Experiments& experiments) {
    std::vector<string16> chunks;
    chrome_variations::GenerateVariationChunks(experiments, &chunks);
    testing::SetExperimentChunks(chunks, experiments.size());
    EXPECT_STREQ(base::StringPrintf(L"%d", experiments.size()).c_str(),
                 (*g_custom_entries)[g_num_of_experiments_offset].value);
    // We make a copy of the array that we empty as we find the experiments.
    Experiments experiments_left(experiments);
    for (int i = 0; i < kMaxReportedVariationChunks; ++i) {
      const google_breakpad::CustomInfoEntry& entry =
          (*g_custom_entries)[g_experiment_chunks_offset + i];
      EXPECT_STREQ(base::StringPrintf(L"experiment-chunk-%i", i + 1).c_str(),
                   entry.name);
      // An empty value should only appear when |experiments_left| is empty.
      if (wcslen(entry.value) == 0)
        EXPECT_TRUE(experiments_left.empty());
      if (experiments_left.empty()) {
        // All other slots should be empty.
        EXPECT_STREQ(L"", entry.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()) {
          if (wcsstr(entry.value, experiment->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;
};

const wchar_t* ChromeAppBreakpadTest::kNumExperiments = L"num-experiments";
const size_t ChromeAppBreakpadTest::kNumExperimentsSize =
    wcslen(ChromeAppBreakpadTest::kNumExperiments);

TEST_F(ChromeAppBreakpadTest, ExperimentList) {
  Experiments experiments;
  experiments.push_back(L"ABCDE-12345");
  ValidateExperimentChunks(experiments);

  experiments.push_back(L"There-You Are");
  ValidateExperimentChunks(experiments);

  experiments.push_back(L"Peter-Sellers");
  ValidateExperimentChunks(experiments);

  experiments.push_back(L"Eat me-Drink me");
  ValidateExperimentChunks(experiments);
}