Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/metrics/variations/variations_service_unittest.cc

Issue 412943002: Move variations component code to variations namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | chrome/browser/omnibox/omnibox_field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698