Index: chrome/browser/metrics/variations_service_unittest.cc |
diff --git a/chrome/browser/metrics/variations_service_unittest.cc b/chrome/browser/metrics/variations_service_unittest.cc |
index d51149f1a1b93396d8efd06b83e836874fc7388d..fcfd4f97ba7c0d5ae8561459aa631af9a515084a 100644 |
--- a/chrome/browser/metrics/variations_service_unittest.cc |
+++ b/chrome/browser/metrics/variations_service_unittest.cc |
@@ -6,15 +6,47 @@ |
#include "base/string_split.h" |
#include "chrome/browser/metrics/proto/study.pb.h" |
#include "chrome/browser/metrics/variations_service.h" |
+#include "chrome/browser/upgrade_detector.h" |
+#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_pref_service.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/test/test_browser_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace chrome_variations { |
namespace { |
+// A test class used to validate expected functionality in VariationsService. |
+class TestVariationsService : public VariationsService { |
+ public: |
+ TestVariationsService() : fetch_attempted_(false) {} |
+ virtual ~TestVariationsService() {} |
+ |
+ bool fetch_attempted() { return fetch_attempted_; } |
+ |
+ // Simulate that an auto-update is ready by sending the appropriate |
+ // notification to the Observe method. Note that the source and details are |
+ // not necessary for this notification type. |
+ void SimulateUpgradeAvailable() { |
+ Observe(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
+ content::Source<UpgradeDetector>(NULL), |
+ content::NotificationService::NoDetails()); |
Ilya Sherman
2012/08/07 20:31:51
nit: This seems a little odd. Why not dispatch th
SteveT
2012/08/08 18:11:39
That makes way more sense, and yes, I do like the
|
+ } |
+ |
+ protected: |
+ virtual void FetchVariationsSeed() { |
Ilya Sherman
2012/08/07 20:31:51
nit: OVERRIDE
SteveT
2012/08/08 18:11:39
Done.
|
+ fetch_attempted_ = true; |
+ } |
+ |
+ private: |
+ bool fetch_attempted_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestVariationsService); |
+}; |
+ |
// Converts |time| to Study proto format. |
int64 TimeToProtoTime(const base::Time& time) { |
return (time - base::Time::UnixEpoch()).InSeconds(); |
@@ -37,6 +69,18 @@ chrome_variations::TrialsSeed CreateTestSeed() { |
} // namespace |
+TEST(VariationsServiceTest, AttemptFetchOnAutoUpdate) { |
+ // Simulate an auto-update and ensure that the VariationsService attempts |
+ // to fetch the variations seed. |
+ MessageLoopForUI message_loop; |
+ content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
+ &message_loop); |
Ilya Sherman
2012/08/07 20:31:51
nit: Why is this needed? If it's just to satisfy
SteveT
2012/08/08 18:11:39
Yes, this was just to satisfy the DCHECKs on Brows
Ilya Sherman
2012/08/08 21:33:47
It's an ok pattern; it's just often overkill and a
|
+ TestVariationsService test_service; |
+ ASSERT_FALSE(test_service.fetch_attempted()); |
Ilya Sherman
2012/08/07 20:31:51
nit: EXPECT_FALSE
SteveT
2012/08/08 18:11:39
Done.
|
+ test_service.SimulateUpgradeAvailable(); |
+ ASSERT_TRUE(test_service.fetch_attempted()); |
Ilya Sherman
2012/08/07 20:31:51
nit: EXPECT_TRUE
SteveT
2012/08/08 18:11:39
Done.
|
+} |
+ |
TEST(VariationsServiceTest, CheckStudyChannel) { |
const chrome::VersionInfo::Channel channels[] = { |
chrome::VersionInfo::CHANNEL_CANARY, |