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

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: merge to tot Created 8 years, 4 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"
10 #include "chrome/common/chrome_notification_types.h"
9 #include "chrome/common/chrome_version_info.h" 11 #include "chrome/common/chrome_version_info.h"
10 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.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() : fetch_attempted_(false) {}
26 virtual ~TestVariationsService() {}
27
28 bool fetch_attempted() { return fetch_attempted_; }
29
30 protected:
31 virtual void FetchVariationsSeed() OVERRIDE {
32 fetch_attempted_ = true;
33 }
34
35 private:
36 bool fetch_attempted_;
37
38 DISALLOW_COPY_AND_ASSIGN(TestVariationsService);
39 };
40
18 // Converts |time| to Study proto format. 41 // Converts |time| to Study proto format.
19 int64 TimeToProtoTime(const base::Time& time) { 42 int64 TimeToProtoTime(const base::Time& time) {
20 return (time - base::Time::UnixEpoch()).InSeconds(); 43 return (time - base::Time::UnixEpoch()).InSeconds();
21 } 44 }
22 45
23 // Populates |seed| with simple test data. The resulting seed will contain one 46 // Populates |seed| with simple test data. The resulting seed will contain one
24 // study called "test", which contains one experiment called "abc" with 47 // study called "test", which contains one experiment called "abc" with
25 // probability weight 100. |seed|'s study field will be cleared before adding 48 // probability weight 100. |seed|'s study field will be cleared before adding
26 // the new study. 49 // the new study.
27 chrome_variations::TrialsSeed CreateTestSeed() { 50 chrome_variations::TrialsSeed CreateTestSeed() {
28 chrome_variations::TrialsSeed seed; 51 chrome_variations::TrialsSeed seed;
29 chrome_variations::Study* study = seed.add_study(); 52 chrome_variations::Study* study = seed.add_study();
30 study->set_name("test"); 53 study->set_name("test");
31 study->set_default_experiment_name("abc"); 54 study->set_default_experiment_name("abc");
32 chrome_variations::Study_Experiment* experiment = study->add_experiment(); 55 chrome_variations::Study_Experiment* experiment = study->add_experiment();
33 experiment->set_name("abc"); 56 experiment->set_name("abc");
34 experiment->set_probability_weight(100); 57 experiment->set_probability_weight(100);
35 return seed; 58 return seed;
36 } 59 }
37 60
38 } // namespace 61 } // namespace
39 62
63 TEST(VariationsServiceTest, AttemptFetchOnAutoUpdate) {
64 // Simulate an auto-update and ensure that the VariationsService attempts
65 // to fetch the Variations seed.
66 MessageLoopForUI message_loop;
67 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
68 &message_loop);
69 TestVariationsService test_service;
70 EXPECT_FALSE(test_service.fetch_attempted());
71 content::NotificationService::current()->Notify(
72 chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
73 content::Source<UpgradeDetector>(UpgradeDetector::GetInstance()),
74 content::NotificationService::NoDetails());
75 EXPECT_TRUE(test_service.fetch_attempted());
76 }
77
40 TEST(VariationsServiceTest, CheckStudyChannel) { 78 TEST(VariationsServiceTest, CheckStudyChannel) {
41 const chrome::VersionInfo::Channel channels[] = { 79 const chrome::VersionInfo::Channel channels[] = {
42 chrome::VersionInfo::CHANNEL_CANARY, 80 chrome::VersionInfo::CHANNEL_CANARY,
43 chrome::VersionInfo::CHANNEL_DEV, 81 chrome::VersionInfo::CHANNEL_DEV,
44 chrome::VersionInfo::CHANNEL_BETA, 82 chrome::VersionInfo::CHANNEL_BETA,
45 chrome::VersionInfo::CHANNEL_STABLE, 83 chrome::VersionInfo::CHANNEL_STABLE,
46 }; 84 };
47 const Study_Channel study_channels[] = { 85 const Study_Channel study_channels[] = {
48 Study_Channel_CANARY, 86 Study_Channel_CANARY,
49 Study_Channel_DEV, 87 Study_Channel_DEV,
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 ASSERT_TRUE(valid); 487 ASSERT_TRUE(valid);
450 Study_Experiment* repeated_group = study.add_experiment(); 488 Study_Experiment* repeated_group = study.add_experiment();
451 repeated_group->set_name("abc"); 489 repeated_group->set_name("abc");
452 repeated_group->set_probability_weight(1); 490 repeated_group->set_probability_weight(1);
453 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, 491 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study,
454 &total_probability); 492 &total_probability);
455 EXPECT_FALSE(valid); 493 EXPECT_FALSE(valid);
456 } 494 }
457 495
458 } // namespace chrome_variations 496 } // 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