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

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

Issue 10790116: Have the VariationsService attempt to fetch the seed when an update is ready. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: asvit nit 2 Created 8 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
« no previous file with comments | « chrome/browser/metrics/variations_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/string_split.h" 6 #include "base/string_split.h"
7 #include "chrome/browser/metrics/proto/study.pb.h" 7 #include "chrome/browser/metrics/proto/study.pb.h"
8 #include "chrome/browser/metrics/variations_service.h" 8 #include "chrome/browser/metrics/variations_service.h"
9 #include "chrome/browser/upgrade_detector.h"
9 #include "chrome/common/chrome_version_info.h" 10 #include "chrome/common/chrome_version_info.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/test/base/testing_pref_service.h" 13 #include "chrome/test/base/testing_pref_service.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
13 17
14 namespace chrome_variations { 18 namespace chrome_variations {
15 19
16 namespace { 20 namespace {
17 21
22 // A test class used to validate expected functionality in VariationsService.
23 class TestVariationsService : public VariationsService {
24 public:
25 TestVariationsService() {}
26 virtual ~TestVariationsService() {}
27
28 bool fetch_attempted() { return fetch_attempted_; }
29
30 void SimulateUpgradeAvailable() {
31 // Simulate that an auto-update is ready by sending the appropriate
Alexei Svitkine (slow) 2012/07/24 14:44:49 Nit: Comment should be above the method.
SteveT 2012/07/24 19:22:54 Done.
32 // notification to the Observe method. Note that the source and details are
33 // not necessary for this notification type.
34 Observe(chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
35 content::Source<UpgradeDetector>(NULL),
36 content::NotificationService::NoDetails());
37 }
38
39 protected:
40 virtual void FetchVariationsSeed() {
41 fetch_attempted_ = true;
42 }
43
44 private:
45 bool fetch_attempted_;
Alexei Svitkine (slow) 2012/07/24 14:44:49 Please initialize |fetch_attempted_| in the constr
SteveT 2012/07/24 19:22:54 Yeah this caused a test failure earlier :( Done.
46
47 DISALLOW_COPY_AND_ASSIGN(TestVariationsService);
48 };
49
18 // Converts |time| to Study proto format. 50 // Converts |time| to Study proto format.
19 int64 TimeToProtoTime(const base::Time& time) { 51 int64 TimeToProtoTime(const base::Time& time) {
20 return (time - base::Time::UnixEpoch()).InSeconds(); 52 return (time - base::Time::UnixEpoch()).InSeconds();
21 } 53 }
22 54
23 // Populates |seed| with simple test data. The resulting seed will contain one 55 // Populates |seed| with simple test data. The resulting seed will contain one
24 // study called "test", which contains one experiment called "abc" with 56 // study called "test", which contains one experiment called "abc" with
25 // probability weight 100. |seed|'s study field will be cleared before adding 57 // probability weight 100. |seed|'s study field will be cleared before adding
26 // the new study. 58 // the new study.
27 chrome_variations::TrialsSeed CreateTestSeed() { 59 chrome_variations::TrialsSeed CreateTestSeed() {
28 chrome_variations::TrialsSeed seed; 60 chrome_variations::TrialsSeed seed;
29 chrome_variations::Study* study = seed.add_study(); 61 chrome_variations::Study* study = seed.add_study();
30 study->set_name("test"); 62 study->set_name("test");
31 study->set_default_experiment_name("abc"); 63 study->set_default_experiment_name("abc");
32 chrome_variations::Study_Experiment* experiment = study->add_experiment(); 64 chrome_variations::Study_Experiment* experiment = study->add_experiment();
33 experiment->set_name("abc"); 65 experiment->set_name("abc");
34 experiment->set_probability_weight(100); 66 experiment->set_probability_weight(100);
35 return seed; 67 return seed;
36 } 68 }
37 69
38 } // namespace 70 } // namespace
39 71
72 TEST(VariationsServiceTest, AttemptFetchOnAutoUpdate) {
73 // Simulate an auto-update and ensure that the VariationsService attempts
74 // to fetch the variations seed.
75 MessageLoopForUI message_loop;
76 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
77 &message_loop);
78 TestVariationsService test_service;
79 ASSERT_FALSE(test_service.fetch_attempted());
80 test_service.SimulateUpgradeAvailable();
81 ASSERT_TRUE(test_service.fetch_attempted());
82 }
83
40 TEST(VariationsServiceTest, CheckStudyChannel) { 84 TEST(VariationsServiceTest, CheckStudyChannel) {
41 const chrome::VersionInfo::Channel channels[] = { 85 const chrome::VersionInfo::Channel channels[] = {
42 chrome::VersionInfo::CHANNEL_CANARY, 86 chrome::VersionInfo::CHANNEL_CANARY,
43 chrome::VersionInfo::CHANNEL_DEV, 87 chrome::VersionInfo::CHANNEL_DEV,
44 chrome::VersionInfo::CHANNEL_BETA, 88 chrome::VersionInfo::CHANNEL_BETA,
45 chrome::VersionInfo::CHANNEL_STABLE, 89 chrome::VersionInfo::CHANNEL_STABLE,
46 }; 90 };
47 const Study_Channel study_channels[] = { 91 const Study_Channel study_channels[] = {
48 Study_Channel_CANARY, 92 Study_Channel_CANARY,
49 Study_Channel_DEV, 93 Study_Channel_DEV,
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 ASSERT_TRUE(valid); 493 ASSERT_TRUE(valid);
450 Study_Experiment* repeated_group = study.add_experiment(); 494 Study_Experiment* repeated_group = study.add_experiment();
451 repeated_group->set_name("abc"); 495 repeated_group->set_name("abc");
452 repeated_group->set_probability_weight(1); 496 repeated_group->set_probability_weight(1);
453 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, 497 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study,
454 &total_probability); 498 &total_probability);
455 EXPECT_FALSE(valid); 499 EXPECT_FALSE(valid);
456 } 500 }
457 501
458 } // namespace chrome_variations 502 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698