Chromium Code Reviews| 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..3c5ec0f1e36dfb645627c527a23acb513ffd3562 |
| --- /dev/null |
| +++ b/chrome/browser/sync/test/integration/wifi_credentials_helper.cc |
| @@ -0,0 +1,103 @@ |
| +// 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/profiles/profile.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; |
| + |
| +using SsidBytes = |
| + wifi_sync::WifiCredentialSyncableService::SsidBytes; |
| +using WifiSsidSecuritySet = |
| + wifi_sync::WifiCredentialSyncableService::WifiSsidSecuritySet; |
| + |
| +namespace wifi_credentials_helper { |
| + |
| +namespace { |
| + |
| +bool ServicesMatchInternal(const WifiCredentialSyncableService& service_a, |
| + const WifiCredentialSyncableService& service_b) { |
| + // Services that have synced should have identical credentials. |
| + const WifiSsidSecuritySet a_networks = service_a.GetWifiNetworksForTest(); |
|
erikwright (departed)
2014/11/17 20:18:57
Instead of querying the services, shouldn't you be
mukesh agrawal
2014/12/04 18:55:01
Agreed. This is fixed in PS8.
|
| + const WifiSsidSecuritySet 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 SsidBytes& 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::GetForBrowserContext( |
| + test()->GetProfile(profile_index)); |
| +} |
| + |
| +WifiCredentialSyncableService* GetVerifierService() { |
| + return WifiCredentialSyncableServiceFactory::GetForBrowserContext( |
| + 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 |