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 29 matching lines...) Expand all Loading... |
40 TestVariationsService(TestRequestAllowedNotifier* test_notifier, | 40 TestVariationsService(TestRequestAllowedNotifier* test_notifier, |
41 PrefService* local_state) | 41 PrefService* local_state) |
42 : VariationsService(test_notifier, local_state, NULL), | 42 : VariationsService(test_notifier, local_state, NULL), |
43 intercepts_fetch_(true), | 43 intercepts_fetch_(true), |
44 fetch_attempted_(false), | 44 fetch_attempted_(false), |
45 seed_stored_(false) { | 45 seed_stored_(false) { |
46 // Set this so StartRepeatedVariationsSeedFetch can be called in tests. | 46 // Set this so StartRepeatedVariationsSeedFetch can be called in tests. |
47 SetCreateTrialsFromSeedCalledForTesting(true); | 47 SetCreateTrialsFromSeedCalledForTesting(true); |
48 } | 48 } |
49 | 49 |
50 virtual ~TestVariationsService() { | 50 ~TestVariationsService() override {} |
51 } | |
52 | 51 |
53 void set_intercepts_fetch(bool value) { | 52 void set_intercepts_fetch(bool value) { |
54 intercepts_fetch_ = value; | 53 intercepts_fetch_ = value; |
55 } | 54 } |
56 | 55 |
57 bool fetch_attempted() const { return fetch_attempted_; } | 56 bool fetch_attempted() const { return fetch_attempted_; } |
58 | 57 |
59 bool seed_stored() const { return seed_stored_; } | 58 bool seed_stored() const { return seed_stored_; } |
60 | 59 |
61 virtual void DoActualFetch() override { | 60 void DoActualFetch() override { |
62 if (intercepts_fetch_) { | 61 if (intercepts_fetch_) { |
63 fetch_attempted_ = true; | 62 fetch_attempted_ = true; |
64 return; | 63 return; |
65 } | 64 } |
66 | 65 |
67 VariationsService::DoActualFetch(); | 66 VariationsService::DoActualFetch(); |
68 } | 67 } |
69 | 68 |
70 protected: | 69 protected: |
71 virtual void StoreSeed(const std::string& seed_data, | 70 void StoreSeed(const std::string& seed_data, |
72 const std::string& seed_signature, | 71 const std::string& seed_signature, |
73 const base::Time& date_fetched) override { | 72 const base::Time& date_fetched) override { |
74 seed_stored_ = true; | 73 seed_stored_ = true; |
75 } | 74 } |
76 | 75 |
77 private: | 76 private: |
78 bool intercepts_fetch_; | 77 bool intercepts_fetch_; |
79 bool fetch_attempted_; | 78 bool fetch_attempted_; |
80 bool seed_stored_; | 79 bool seed_stored_; |
81 | 80 |
82 DISALLOW_COPY_AND_ASSIGN(TestVariationsService); | 81 DISALLOW_COPY_AND_ASSIGN(TestVariationsService); |
83 }; | 82 }; |
84 | 83 |
85 class TestVariationsServiceObserver : public VariationsService::Observer { | 84 class TestVariationsServiceObserver : public VariationsService::Observer { |
86 public: | 85 public: |
87 TestVariationsServiceObserver() | 86 TestVariationsServiceObserver() |
88 : best_effort_changes_notified_(0), | 87 : best_effort_changes_notified_(0), |
89 crticial_changes_notified_(0) { | 88 crticial_changes_notified_(0) { |
90 } | 89 } |
91 virtual ~TestVariationsServiceObserver() { | 90 ~TestVariationsServiceObserver() override {} |
92 } | |
93 | 91 |
94 virtual void OnExperimentChangesDetected(Severity severity) override { | 92 void OnExperimentChangesDetected(Severity severity) override { |
95 switch (severity) { | 93 switch (severity) { |
96 case BEST_EFFORT: | 94 case BEST_EFFORT: |
97 ++best_effort_changes_notified_; | 95 ++best_effort_changes_notified_; |
98 break; | 96 break; |
99 case CRITICAL: | 97 case CRITICAL: |
100 ++crticial_changes_notified_; | 98 ++crticial_changes_notified_; |
101 break; | 99 break; |
102 } | 100 } |
103 } | 101 } |
104 | 102 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 EXPECT_EQ(cases[i].expected_best_effort_notifications, | 404 EXPECT_EQ(cases[i].expected_best_effort_notifications, |
407 observer.best_effort_changes_notified()) << i; | 405 observer.best_effort_changes_notified()) << i; |
408 EXPECT_EQ(cases[i].expected_crtical_notifications, | 406 EXPECT_EQ(cases[i].expected_crtical_notifications, |
409 observer.crticial_changes_notified()) << i; | 407 observer.crticial_changes_notified()) << i; |
410 | 408 |
411 service.RemoveObserver(&observer); | 409 service.RemoveObserver(&observer); |
412 } | 410 } |
413 } | 411 } |
414 | 412 |
415 } // namespace chrome_variations | 413 } // namespace chrome_variations |
OLD | NEW |