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

Unified Diff: chrome/browser/metrics/variations/variations_service_unittest.cc

Issue 10917120: Activate the VariationsService for ChromeOS and ensure that it does not ping the server until the E… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: unit tests refactored Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/variations/variations_service_unittest.cc
diff --git a/chrome/browser/metrics/variations/variations_service_unittest.cc b/chrome/browser/metrics/variations/variations_service_unittest.cc
index 0de0800342379ff326e0489f17d10e0fd2ac7ad0..ebefd95cd3315070a8cfd4531ffeb7bbefee6ab4 100644
--- a/chrome/browser/metrics/variations/variations_service_unittest.cc
+++ b/chrome/browser/metrics/variations/variations_service_unittest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/metrics/variations/variations_service.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -16,54 +17,6 @@ namespace chrome_variations {
namespace {
-// A test class used to validate expected functionality in VariationsService.
-class TestVariationsService : public VariationsService {
- public:
- TestVariationsService() : VariationsService(),
- fetch_attempted_(false) {
- }
- virtual ~TestVariationsService() {}
-
- bool fetch_attempted() const { return fetch_attempted_; }
- void SetFetchAttempted(bool attempted) { fetch_attempted_ = attempted; }
-
- protected:
- virtual void FetchVariationsSeed() OVERRIDE {
- fetch_attempted_ = true;
- }
-
- private:
- bool fetch_attempted_;
-
- DISALLOW_COPY_AND_ASSIGN(TestVariationsService);
-};
-
-// Override NetworkChangeNotifier to simulate connection type changes for tests.
-class TestNetworkChangeNotifier : public net::NetworkChangeNotifier {
- public:
- TestNetworkChangeNotifier()
- : net::NetworkChangeNotifier(),
- connection_type_to_return_(
- net::NetworkChangeNotifier::CONNECTION_UNKNOWN) {
- }
-
- void SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::ConnectionType type) {
- connection_type_to_return_ = type;
- net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange();
- MessageLoop::current()->RunAllPending();
- }
-
- private:
- virtual ConnectionType GetCurrentConnectionType() const OVERRIDE {
- return connection_type_to_return_;
- }
-
- net::NetworkChangeNotifier::ConnectionType connection_type_to_return_;
-
- DISALLOW_COPY_AND_ASSIGN(TestNetworkChangeNotifier);
-};
-
// Converts |time| to Study proto format.
int64 TimeToProtoTime(const base::Time& time) {
return (time - base::Time::UnixEpoch()).InSeconds();
@@ -86,36 +39,6 @@ TrialsSeed CreateTestSeed() {
} // namespace
-// A test fixture class for VariationsService tests that require network state
-// simulations.
-class VariationsServiceNetworkTest : public testing::Test {
- public:
- VariationsServiceNetworkTest()
- : ui_thread(content::BrowserThread::UI, &message_loop) { }
- ~VariationsServiceNetworkTest() { }
-
- void SetWasOfflineDuringLastRequestAttempt(bool offline) {
- test_service.SetWasOfflineDuringLastRequestAttemptForTesting(offline);
- }
-
- void SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::ConnectionType type) {
- notifier.SimulateNetworkConnectionChange(type);
- }
-
- bool fetch_attempted() const {
- return test_service.fetch_attempted();
- }
-
- private:
- MessageLoopForUI message_loop;
- content::TestBrowserThread ui_thread;
- TestNetworkChangeNotifier notifier;
- TestVariationsService test_service;
-
- DISALLOW_COPY_AND_ASSIGN(VariationsServiceNetworkTest);
-};
-
TEST(VariationsServiceTest, CheckStudyChannel) {
const chrome::VersionInfo::Channel channels[] = {
chrome::VersionInfo::CHANNEL_CANARY,
@@ -534,53 +457,4 @@ TEST(VariationsServiceTest, ValidateStudy) {
EXPECT_FALSE(valid);
}
Alexei Svitkine (slow) 2012/09/12 15:15:46 Can you add a test that mocks the ResourceRequestA
SteveT 2012/09/14 20:25:09 Not done yet...
-TEST_F(VariationsServiceNetworkTest, DoNotFetchIfOffline) {
- SetWasOfflineDuringLastRequestAttempt(true);
- SimulateNetworkConnectionChange(net::NetworkChangeNotifier::CONNECTION_NONE);
- EXPECT_FALSE(fetch_attempted());
-}
-
-TEST_F(VariationsServiceNetworkTest, DoNotFetchIfOnlineToOnline) {
- SetWasOfflineDuringLastRequestAttempt(false);
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_ETHERNET);
- EXPECT_FALSE(fetch_attempted());
-}
-
-TEST_F(VariationsServiceNetworkTest, FetchOnReconnect) {
- SetWasOfflineDuringLastRequestAttempt(true);
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_ETHERNET);
- EXPECT_TRUE(fetch_attempted());
-}
-
-TEST_F(VariationsServiceNetworkTest, NoFetchOnWardriving) {
- SetWasOfflineDuringLastRequestAttempt(false);
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_WIFI);
- EXPECT_FALSE(fetch_attempted());
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_3G);
- EXPECT_FALSE(fetch_attempted());
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_4G);
- EXPECT_FALSE(fetch_attempted());
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_WIFI);
- EXPECT_FALSE(fetch_attempted());
-}
-
-TEST_F(VariationsServiceNetworkTest, NoFetchOnFlakyConnection) {
- SetWasOfflineDuringLastRequestAttempt(false);
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_WIFI);
- EXPECT_FALSE(fetch_attempted());
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_NONE);
- EXPECT_FALSE(fetch_attempted());
- SimulateNetworkConnectionChange(
- net::NetworkChangeNotifier::CONNECTION_WIFI);
- EXPECT_FALSE(fetch_attempted());
-}
-
} // namespace chrome_variations

Powered by Google App Engine
This is Rietveld 408576698