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