Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" | |
| 6 | |
| 7 #include <set> | |
| 8 #include <utility> // for std::pair | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | |
| 14 #include "chrome/browser/sync/test/integration/sync_test.h" | |
| 15 #include "components/wifi_sync/wifi_credential_syncable_service.h" | |
| 16 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h" | |
| 17 #include "components/wifi_sync/wifi_security_class.h" | |
| 18 | |
| 19 using wifi_sync::WifiCredentialSyncableService; | |
| 20 using wifi_sync::WifiCredentialSyncableServiceFactory; | |
| 21 using wifi_sync::WifiSecurityClass; | |
| 22 using sync_datatype_helper::test; | |
| 23 | |
| 24 using SsidBytes = | |
| 25 wifi_sync::WifiCredentialSyncableService::SsidBytes; | |
| 26 using WifiSsidSecuritySet = | |
| 27 wifi_sync::WifiCredentialSyncableService::WifiSsidSecuritySet; | |
| 28 | |
| 29 namespace wifi_credentials_helper { | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 bool ServicesMatchInternal(const WifiCredentialSyncableService& service_a, | |
| 34 const WifiCredentialSyncableService& service_b) { | |
| 35 // Services that have synced should have identical credentials. | |
| 36 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.
| |
| 37 const WifiSsidSecuritySet b_networks = service_b.GetWifiNetworksForTest(); | |
| 38 | |
| 39 if (a_networks.size() != b_networks.size()) { | |
| 40 LOG(ERROR) << "Service a and b do not match in size: " << a_networks.size() | |
| 41 << " vs " << b_networks.size() << " respectively."; | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 for (const auto &network : a_networks) { | |
| 46 if (b_networks.find(network) == b_networks.end()) { | |
| 47 const SsidBytes& a_ssid = network.first; | |
| 48 const WifiSecurityClass a_security_class = network.second; | |
| 49 LOG(ERROR) | |
| 50 << "Network from a not found in b. " | |
| 51 << "SSID (hex): " | |
| 52 << base::HexEncode(a_ssid.data(), a_ssid.size()).c_str() << " " | |
| 53 << "SecurityClass: " | |
| 54 << a_security_class; | |
| 55 return false; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 WifiCredentialSyncableService* GetServiceForBrowserContext(int profile_index) { | |
| 65 return WifiCredentialSyncableServiceFactory::GetForBrowserContext( | |
| 66 test()->GetProfile(profile_index)); | |
| 67 } | |
| 68 | |
| 69 WifiCredentialSyncableService* GetVerifierService() { | |
| 70 return WifiCredentialSyncableServiceFactory::GetForBrowserContext( | |
| 71 test()->verifier()); | |
| 72 } | |
| 73 | |
| 74 bool ServiceMatchesVerifier(int profile_index) { | |
| 75 WifiCredentialSyncableService* verifier = GetVerifierService(); | |
| 76 WifiCredentialSyncableService* other = | |
| 77 GetServiceForBrowserContext(profile_index); | |
| 78 CHECK(verifier); | |
| 79 CHECK(other); | |
| 80 return ServicesMatchInternal(*verifier, *other); | |
| 81 } | |
| 82 | |
| 83 bool AllServicesMatch() { | |
| 84 if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { | |
| 85 LOG(ERROR) << "WifiCredentialSyncableService 0 does not match verifier."; | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 WifiCredentialSyncableService* service_a = GetServiceForBrowserContext(0); | |
| 90 CHECK(service_a); | |
| 91 for (int it = 1; it < test()->num_clients(); ++it) { | |
| 92 WifiCredentialSyncableService* service_b = GetServiceForBrowserContext(it); | |
| 93 CHECK(service_b); | |
| 94 if (!ServicesMatchInternal(*service_a, *service_b)) { | |
| 95 LOG(ERROR) << "WifiCredentialSyncableService " << it << " " | |
| 96 << "does not match with service 0."; | |
| 97 return false; | |
| 98 } | |
| 99 } | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 } // namespace wifi_credentials_helper | |
| OLD | NEW |