OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics/variations/variations_service.h" | 5 #include "chrome/browser/metrics/variations/variations_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Number of notification received with CRITICAL severity. | 117 // Number of notification received with CRITICAL severity. |
118 int crticial_changes_notified_; | 118 int crticial_changes_notified_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(TestVariationsServiceObserver); | 120 DISALLOW_COPY_AND_ASSIGN(TestVariationsServiceObserver); |
121 }; | 121 }; |
122 | 122 |
123 // Populates |seed| with simple test data. The resulting seed will contain one | 123 // Populates |seed| with simple test data. The resulting seed will contain one |
124 // study called "test", which contains one experiment called "abc" with | 124 // study called "test", which contains one experiment called "abc" with |
125 // probability weight 100. |seed|'s study field will be cleared before adding | 125 // probability weight 100. |seed|'s study field will be cleared before adding |
126 // the new study. | 126 // the new study. |
127 VariationsSeed CreateTestSeed() { | 127 variations::VariationsSeed CreateTestSeed() { |
128 VariationsSeed seed; | 128 variations::VariationsSeed seed; |
129 Study* study = seed.add_study(); | 129 variations::Study* study = seed.add_study(); |
130 study->set_name("test"); | 130 study->set_name("test"); |
131 study->set_default_experiment_name("abc"); | 131 study->set_default_experiment_name("abc"); |
132 Study_Experiment* experiment = study->add_experiment(); | 132 variations::Study_Experiment* experiment = study->add_experiment(); |
133 experiment->set_name("abc"); | 133 experiment->set_name("abc"); |
134 experiment->set_probability_weight(100); | 134 experiment->set_probability_weight(100); |
135 seed.set_serial_number("123"); | 135 seed.set_serial_number("123"); |
136 return seed; | 136 return seed; |
137 } | 137 } |
138 | 138 |
139 // Serializes |seed| to protobuf binary format. | 139 // Serializes |seed| to protobuf binary format. |
140 std::string SerializeSeed(const VariationsSeed& seed) { | 140 std::string SerializeSeed(const variations::VariationsSeed& seed) { |
141 std::string serialized_seed; | 141 std::string serialized_seed; |
142 seed.SerializeToString(&serialized_seed); | 142 seed.SerializeToString(&serialized_seed); |
143 return serialized_seed; | 143 return serialized_seed; |
144 } | 144 } |
145 | 145 |
146 // Simulates a variations service response by setting a date header and the | 146 // Simulates a variations service response by setting a date header and the |
147 // specified HTTP |response_code| on |fetcher|. | 147 // specified HTTP |response_code| on |fetcher|. |
148 void SimulateServerResponse(int response_code, net::TestURLFetcher* fetcher) { | 148 void SimulateServerResponse(int response_code, net::TestURLFetcher* fetcher) { |
149 ASSERT_TRUE(fetcher); | 149 ASSERT_TRUE(fetcher); |
150 scoped_refptr<net::HttpResponseHeaders> headers( | 150 scoped_refptr<net::HttpResponseHeaders> headers( |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 {0, 1, 1, 0, 1}, | 390 {0, 1, 1, 0, 1}, |
391 {1, 1, 1, 0, 1}, | 391 {1, 1, 1, 0, 1}, |
392 {1, 1, 0, 1, 0}, | 392 {1, 1, 0, 1, 0}, |
393 {1, 0, 1, 0, 1}, | 393 {1, 0, 1, 0, 1}, |
394 }; | 394 }; |
395 | 395 |
396 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 396 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
397 TestVariationsServiceObserver observer; | 397 TestVariationsServiceObserver observer; |
398 service.AddObserver(&observer); | 398 service.AddObserver(&observer); |
399 | 399 |
400 VariationsSeedSimulator::Result result; | 400 variations::VariationsSeedSimulator::Result result; |
401 result.normal_group_change_count = cases[i].normal_count; | 401 result.normal_group_change_count = cases[i].normal_count; |
402 result.kill_best_effort_group_change_count = cases[i].best_effort_count; | 402 result.kill_best_effort_group_change_count = cases[i].best_effort_count; |
403 result.kill_critical_group_change_count = cases[i].critical_count; | 403 result.kill_critical_group_change_count = cases[i].critical_count; |
404 service.NotifyObservers(result); | 404 service.NotifyObservers(result); |
405 | 405 |
406 EXPECT_EQ(cases[i].expected_best_effort_notifications, | 406 EXPECT_EQ(cases[i].expected_best_effort_notifications, |
407 observer.best_effort_changes_notified()) << i; | 407 observer.best_effort_changes_notified()) << i; |
408 EXPECT_EQ(cases[i].expected_crtical_notifications, | 408 EXPECT_EQ(cases[i].expected_crtical_notifications, |
409 observer.crticial_changes_notified()) << i; | 409 observer.crticial_changes_notified()) << i; |
410 | 410 |
411 service.RemoveObserver(&observer); | 411 service.RemoveObserver(&observer); |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
415 } // namespace chrome_variations | 415 } // namespace chrome_variations |
OLD | NEW |