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

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

Issue 10375043: Variations Service now creates field trials from variations seed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Alexei's comments Created 8 years, 7 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/proto/study.pb.h" 5 #include "chrome/browser/metrics/proto/study.pb.h"
6 #include "chrome/browser/metrics/variations_service.h" 6 #include "chrome/browser/metrics/variations_service.h"
7 #include "chrome/common/chrome_version_info.h" 7 #include "chrome/common/chrome_version_info.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 11
12 // Converts |time| to chrome_variations::Study proto format. 12 // Converts |time| to chrome_variations::Study proto format.
13 int64 TimeToProtoTime(const base::Time& time) { 13 int64 TimeToProtoTime(const base::Time& time) {
14 return (time - base::Time::UnixEpoch()).InMilliseconds(); 14 return (time - base::Time::UnixEpoch()).InSeconds();
15 } 15 }
16 16
17 } // namespace 17 } // namespace
18 18
19 19
20 TEST(VariationsServiceTest, CheckStudyChannel) { 20 TEST(VariationsServiceTest, CheckStudyChannel) {
21 const chrome::VersionInfo::Channel channels[] = { 21 const chrome::VersionInfo::Channel channels[] = {
22 chrome::VersionInfo::CHANNEL_CANARY, 22 chrome::VersionInfo::CHANNEL_CANARY,
23 chrome::VersionInfo::CHANNEL_DEV, 23 chrome::VersionInfo::CHANNEL_DEV,
24 chrome::VersionInfo::CHANNEL_BETA, 24 chrome::VersionInfo::CHANNEL_BETA,
25 chrome::VersionInfo::CHANNEL_STABLE, 25 chrome::VersionInfo::CHANNEL_STABLE,
26 }; 26 };
27 const chrome_variations::Study_Channel study_channels[] = { 27 const chrome_variations::Study_Channel study_channels[] = {
28 chrome_variations::Study_Channel_CANARY, 28 chrome_variations::Study_Channel_CANARY,
29 chrome_variations::Study_Channel_DEV, 29 chrome_variations::Study_Channel_DEV,
30 chrome_variations::Study_Channel_BETA, 30 chrome_variations::Study_Channel_BETA,
31 chrome_variations::Study_Channel_STABLE, 31 chrome_variations::Study_Channel_STABLE,
32 }; 32 };
33 ASSERT_EQ(arraysize(channels), arraysize(study_channels)); 33 ASSERT_EQ(arraysize(channels), arraysize(study_channels));
34 bool channel_added[arraysize(channels)] = { 0 }; 34 bool channel_added[arraysize(channels)] = { 0 };
35 35
36 chrome_variations::Study study; 36 chrome_variations::Study study;
37 37
38 // Check in the forwarded order. The loop cond is <= arraysize(study_channels) 38 // Check in the forwarded order. The loop cond is <= arraysize(study_channels)
39 // instead of < so that the result of adding the last channel gets checked. 39 // instead of < so that the result of adding the last channel gets checked.
40 for (size_t i = 0; i <= arraysize(study_channels); ++i) { 40 for (size_t i = 0; i <= arraysize(study_channels); ++i) {
41 for (size_t j = 0; j < arraysize(channels); ++j) { 41 for (size_t j = 0; j < arraysize(channels); ++j) {
42 const bool expected = channel_added[j]; 42 const bool expected = channel_added[j] || study.channel_size()==0;
Alexei Svitkine (slow) 2012/05/08 03:40:13 Spaces around ==.
jwd 2012/05/08 03:47:24 Done.
43 const bool result = VariationsService::CheckStudyChannel(study, 43 const bool result = VariationsService::CheckStudyChannel(study,
44 channels[j]); 44 channels[j]);
45 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!"; 45 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!";
46 } 46 }
47 47
48 if (i < arraysize(study_channels)) 48 if (i < arraysize(study_channels))
49 { 49 {
50 study.add_channel(study_channels[i]); 50 study.add_channel(study_channels[i]);
51 channel_added[i] = true; 51 channel_added[i] = true;
52 } 52 }
53 } 53 }
54 54
55 // Do the same check in the reverse order. 55 // Do the same check in the reverse order.
56 study.clear_channel(); 56 study.clear_channel();
57 memset(&channel_added, 0, sizeof(channel_added)); 57 memset(&channel_added, 0, sizeof(channel_added));
58 for (size_t i = 0; i <= arraysize(study_channels); ++i) { 58 for (size_t i = 0; i <= arraysize(study_channels); ++i) {
59 for (size_t j = 0; j < arraysize(channels); ++j) { 59 for (size_t j = 0; j < arraysize(channels); ++j) {
60 const bool expected = channel_added[j]; 60 const bool expected = channel_added[j] || study.channel_size()==0;
Alexei Svitkine (slow) 2012/05/08 03:40:13 Spaces around ==.
jwd 2012/05/08 03:47:24 Done.
61 const bool result = VariationsService::CheckStudyChannel(study, 61 const bool result = VariationsService::CheckStudyChannel(study,
62 channels[j]); 62 channels[j]);
63 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!"; 63 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!";
64 } 64 }
65 65
66 if (i < arraysize(study_channels)) 66 if (i < arraysize(study_channels))
67 { 67 {
68 const int index = arraysize(study_channels) - i - 1; 68 const int index = arraysize(study_channels) - i - 1;
69 study.add_channel(study_channels[index]); 69 study.add_channel(study_channels[index]);
70 channel_added[index] = true; 70 channel_added[index] = true;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(expiry_test_cases); ++j) { 202 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(expiry_test_cases); ++j) {
203 study.set_start_date(TimeToProtoTime(start_test_cases[i].start_date)); 203 study.set_start_date(TimeToProtoTime(start_test_cases[i].start_date));
204 study.set_expiry_date(TimeToProtoTime(expiry_test_cases[j].expiry_date)); 204 study.set_expiry_date(TimeToProtoTime(expiry_test_cases[j].expiry_date));
205 const bool expected = start_test_cases[i].expected_result && 205 const bool expected = start_test_cases[i].expected_result &&
206 expiry_test_cases[j].expected_result; 206 expiry_test_cases[j].expected_result;
207 const bool result = VariationsService::CheckStudyDate(study, now); 207 const bool result = VariationsService::CheckStudyDate(study, now);
208 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!"; 208 EXPECT_EQ(expected, result) << "Case " << i << "," << j << " failed!";
209 } 209 }
210 } 210 }
211 } 211 }
OLDNEW
« chrome/browser/metrics/variations_service.cc ('K') | « chrome/browser/metrics/variations_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698