Index: components/wifi_sync/wifi_credential_syncable_service_unittest.cc |
diff --git a/components/wifi_sync/wifi_credential_syncable_service_unittest.cc b/components/wifi_sync/wifi_credential_syncable_service_unittest.cc |
index efcd4739836081b8dd02b1e861bd1b58bfde915c..96ad8e2e63ab1a3d1b07a1581d31255d3a1205cd 100644 |
--- a/components/wifi_sync/wifi_credential_syncable_service_unittest.cc |
+++ b/components/wifi_sync/wifi_credential_syncable_service_unittest.cc |
@@ -12,6 +12,7 @@ |
#include "base/time/time.h" |
#include "base/tracked_objects.h" |
#include "components/wifi_sync/wifi_config_delegate.h" |
+#include "components/wifi_sync/wifi_config_observer.h" |
#include "components/wifi_sync/wifi_credential.h" |
#include "components/wifi_sync/wifi_security_class.h" |
#include "sync/api/attachments/attachment_id.h" |
@@ -39,7 +40,8 @@ const char kSsidNonUtf8[] = "\xc0"; |
// been called. |
class FakeWifiConfigDelegate : public WifiConfigDelegate { |
public: |
- FakeWifiConfigDelegate() : add_count_(0) {} |
+ FakeWifiConfigDelegate() |
+ : add_count_(0) {} |
~FakeWifiConfigDelegate() override {} |
// WifiConfigDelegate implementation. |
@@ -58,25 +60,64 @@ class FakeWifiConfigDelegate : public WifiConfigDelegate { |
DISALLOW_COPY_AND_ASSIGN(FakeWifiConfigDelegate); |
}; |
+// Fake implementation of WifiConfigObserver, which provides the |
+// ability to check how many times a WifiConfigObserver method has |
+// been called. |
+class FakeWifiConfigObserver : public WifiConfigObserver { |
+ public: |
+ FakeWifiConfigObserver() |
+ : start_syncing_called_(false), |
+ stop_syncing_called_(false) {} |
+ ~FakeWifiConfigObserver() override {} |
+ |
+ // WifiConfigObserver implementation. |
+ void StartSyncing( |
+ base::WeakPtr<WifiCredentialSyncableService> syncable_service) override { |
+ start_syncing_called_ = true; |
+ } |
+ void StopSyncing() override { |
+ stop_syncing_called_ = true; |
+ } |
+ |
+ // Returns whether or not the StartSyncing method has been called. |
+ bool start_syncing_called() const { return start_syncing_called_; } |
+ |
+ // Returns whether or not the StopSyncing method has been called. |
+ bool stop_syncing_called() const { return stop_syncing_called_; } |
+ |
+ private: |
+ // Whether or not StartSyncing has been called on this fake. |
+ bool start_syncing_called_; |
+ |
+ // Whether or not StopSyncing has been called on this fake. |
+ bool stop_syncing_called_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeWifiConfigObserver); |
+}; |
+ |
// Unit tests for WifiCredentialSyncableService. |
class WifiCredentialSyncableServiceTest : public testing::Test { |
protected: |
WifiCredentialSyncableServiceTest() |
: config_delegate_(new FakeWifiConfigDelegate()), |
+ config_observer_(new FakeWifiConfigObserver()), |
change_processor_(nullptr) { |
syncable_service_.reset( |
new WifiCredentialSyncableServiceImpl( |
- make_scoped_ptr(config_delegate_))); |
+ make_scoped_ptr(config_delegate_), |
+ make_scoped_ptr(config_observer_))); |
} |
// Wrappers for methods in WifiCredentialSyncableService. |
+ void StopSyncing() { |
+ syncable_service_->StopSyncing(syncer::WIFI_CREDENTIALS); |
+ } |
syncer::SyncError ProcessSyncChanges( |
const syncer::SyncChangeList& change_list) { |
return syncable_service_->ProcessSyncChanges(FROM_HERE, change_list); |
} |
- bool AddToSyncedNetworks(const std::string& item_id, |
- const WifiCredential& credential) { |
- return syncable_service_->AddToSyncedNetworks(item_id, credential); |
+ bool AddToSyncedNetworks(const WifiCredential& credential) { |
+ return syncable_service_->AddToSyncedNetworks(credential); |
} |
// Returns the number of change requests received by |
@@ -86,6 +127,18 @@ class WifiCredentialSyncableServiceTest : public testing::Test { |
return change_processor_->changes().size(); |
} |
+ // Returns whether or not StartSyncing has been called on |
+ // |config_observer_|. |
+ bool config_observer_start_syncing_called() { |
+ return config_observer_->start_syncing_called(); |
+ } |
+ |
+ // Returns whether or not StopSyncing been called on |
+ // |config_observer_|. |
+ bool config_observer_stop_syncing_called() { |
+ return config_observer_->stop_syncing_called(); |
+ } |
+ |
// Returns the number of times AddToLocalNetworks has been called on |
// |config_delegate_|. |
unsigned int config_delegate_add_count() { |
@@ -149,6 +202,7 @@ class WifiCredentialSyncableServiceTest : public testing::Test { |
private: |
scoped_ptr<WifiCredentialSyncableService> syncable_service_; |
FakeWifiConfigDelegate* config_delegate_; // Owned by |syncable_service_| |
+ FakeWifiConfigObserver* config_observer_; // Owned by |syncable_service_| |
FakeSyncChangeProcessor* change_processor_; // Owned by |syncable_service_| |
DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableServiceTest); |
@@ -163,6 +217,17 @@ TEST_F(WifiCredentialSyncableServiceTest, ProcessSyncChangesNotStarted) { |
EXPECT_EQ(0U, config_delegate_add_count()); |
} |
+TEST_F(WifiCredentialSyncableServiceTest, StartSyncing) { |
+ StartSyncing(); |
+ EXPECT_TRUE(config_observer_start_syncing_called()); |
+} |
+ |
+TEST_F(WifiCredentialSyncableServiceTest, StopSyncing) { |
+ StartSyncing(); |
+ StopSyncing(); |
+ EXPECT_TRUE(config_observer_stop_syncing_called()); |
+} |
+ |
TEST_F(WifiCredentialSyncableServiceTest, |
ProcessSyncChangesActionAddSecurityClassInvalid) { |
syncer::SyncChangeList changes; |
@@ -275,13 +340,13 @@ TEST_F(WifiCredentialSyncableServiceTest, |
TEST_F(WifiCredentialSyncableServiceTest, AddToSyncedNetworksNotStarted) { |
EXPECT_FALSE(AddToSyncedNetworks( |
- "fake-item-id", MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
+ MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
} |
TEST_F(WifiCredentialSyncableServiceTest, AddToSyncedNetworksSuccess) { |
StartSyncing(); |
EXPECT_TRUE(AddToSyncedNetworks( |
- "fake-item-id", MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
+ MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
EXPECT_EQ(1, change_processor_changes_size()); |
} |
@@ -289,9 +354,8 @@ TEST_F(WifiCredentialSyncableServiceTest, |
AddToSyncedNetworksDifferentSecurityClassesSuccess) { |
StartSyncing(); |
EXPECT_TRUE(AddToSyncedNetworks( |
- "fake-item-id", MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
+ MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
EXPECT_TRUE(AddToSyncedNetworks( |
- "fake-item-id-2", |
MakeCredential(kSsidNonUtf8, SECURITY_CLASS_WEP, ""))); |
EXPECT_EQ(2, change_processor_changes_size()); |
} |
@@ -300,9 +364,9 @@ TEST_F(WifiCredentialSyncableServiceTest, |
AddToSyncedNetworksDifferentSsidsSuccess) { |
StartSyncing(); |
EXPECT_TRUE(AddToSyncedNetworks( |
- "fake-item-id", MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
+ MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
EXPECT_TRUE(AddToSyncedNetworks( |
- "fake-item-id-2", MakeCredential(kSsid, SECURITY_CLASS_NONE, ""))); |
+ MakeCredential(kSsid, SECURITY_CLASS_NONE, ""))); |
EXPECT_EQ(2, change_processor_changes_size()); |
} |
@@ -312,12 +376,10 @@ TEST_F(WifiCredentialSyncableServiceTest, |
StartSyncing(); |
EXPECT_TRUE( |
AddToSyncedNetworks( |
- "fake-item-id", |
MakeCredential(kSsidNonUtf8, SECURITY_CLASS_PSK, passphrase))); |
EXPECT_EQ(1, change_processor_changes_size()); |
EXPECT_FALSE( |
AddToSyncedNetworks( |
- "fake-item-id", |
MakeCredential(kSsidNonUtf8, SECURITY_CLASS_PSK, passphrase))); |
EXPECT_EQ(1, change_processor_changes_size()); |
} |
@@ -327,12 +389,10 @@ TEST_F(WifiCredentialSyncableServiceTest, |
StartSyncing(); |
EXPECT_TRUE( |
AddToSyncedNetworks( |
- "fake-item-id", |
MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
EXPECT_EQ(1, change_processor_changes_size()); |
EXPECT_FALSE( |
AddToSyncedNetworks( |
- "fake-item-id", |
MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); |
EXPECT_EQ(1, change_processor_changes_size()); |
} |