Index: chrome/browser/sync/test/integration/wifi_credentials_helper.cc |
diff --git a/chrome/browser/sync/test/integration/wifi_credentials_helper.cc b/chrome/browser/sync/test/integration/wifi_credentials_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8ccc6c05a29a4e1fe69af0773da4c84505f21be |
--- /dev/null |
+++ b/chrome/browser/sync/test/integration/wifi_credentials_helper.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" |
+ |
+#include <set> |
+#include <utility> // for std::pair |
+#include <vector> |
+ |
+#include "base/strings/string_number_conversions.h" |
+#include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
+#include "chrome/browser/sync/test/integration/sync_test.h" |
+#include "components/wifi_sync/wifi_credential_syncable_service.h" |
+#include "components/wifi_sync/wifi_credential_syncable_service_factory.h" |
+#include "components/wifi_sync/wifi_security_class.h" |
+ |
+using wifi_sync::WifiCredentialSyncableService; |
+using wifi_sync::WifiCredentialSyncableServiceFactory; |
+using wifi_sync::WifiSecurityClass; |
+using sync_datatype_helper::test; |
+ |
+namespace wifi_credentials_helper { |
+ |
+namespace { |
+ |
+bool ServicesMatchInternal(const WifiCredentialSyncableService& service_a, |
+ const WifiCredentialSyncableService& service_b) { |
+ // Services that have synced should have identical credentials. |
+ const std::set< |
+ std::pair<std::vector<char>, WifiSecurityClass>> a_networks = |
+ service_a.GetWifiNetworksForTest(); |
+ const std::set< |
+ std::pair<std::vector<char>, WifiSecurityClass>> b_networks = |
+ service_b.GetWifiNetworksForTest(); |
+ |
+ if (a_networks.size() != b_networks.size()) { |
+ LOG(ERROR) << "Service a and b do not match in size: " << a_networks.size() |
+ << " vs " << b_networks.size() << " respectively."; |
+ return false; |
+ } |
+ |
+ for (const auto &network : a_networks) { |
+ if (b_networks.find(network) == b_networks.end()) { |
+ const std::vector<char>& a_ssid = network.first; |
+ const WifiSecurityClass a_security_class = network.second; |
+ LOG(ERROR) |
+ << "Network from a not found in b. " |
+ << "SSID (hex): " |
+ << base::HexEncode(a_ssid.data(), a_ssid.size()).c_str() << " " |
+ << "SecurityClass: " |
+ << a_security_class; |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+WifiCredentialSyncableService* GetServiceForBrowserContext(int profile_index) { |
+ return WifiCredentialSyncableServiceFactory::GetForProfile( |
+ test()->GetProfile(profile_index)); |
+} |
+ |
+WifiCredentialSyncableService* GetVerifierService() { |
+ return WifiCredentialSyncableServiceFactory::GetForProfile( |
+ test()->verifier()); |
+} |
+ |
+bool ServiceMatchesVerifier(int profile_index) { |
+ WifiCredentialSyncableService* verifier = GetVerifierService(); |
+ WifiCredentialSyncableService* other = |
+ GetServiceForBrowserContext(profile_index); |
+ CHECK(verifier); |
+ CHECK(other); |
+ return ServicesMatchInternal(*verifier, *other); |
+} |
+ |
+bool AllServicesMatch() { |
+ if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { |
+ LOG(ERROR) << "WifiCredentialSyncableService 0 does not match verifier."; |
+ return false; |
+ } |
+ |
+ WifiCredentialSyncableService* service_a = GetServiceForBrowserContext(0); |
+ CHECK(service_a); |
+ for (int it = 1; it < test()->num_clients(); ++it) { |
+ WifiCredentialSyncableService* service_b = GetServiceForBrowserContext(it); |
+ CHECK(service_b); |
+ if (!ServicesMatchInternal(*service_a, *service_b)) { |
+ LOG(ERROR) << "WifiCredentialSyncableService " << it << " " |
+ << "does not match with service 0."; |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
+} // namespace wifi_credentials_helper |