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 "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 11 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 12 #include "components/wifi_sync/wifi_credential.h" |
| 13 #include "components/wifi_sync/wifi_security_class.h" |
| 14 |
| 15 #if defined(OS_CHROMEOS) |
| 16 #include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.
h" |
| 17 #endif |
| 18 |
| 19 using wifi_sync::WifiCredential; |
| 20 using sync_datatype_helper::test; |
| 21 |
| 22 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
| 23 |
| 24 namespace wifi_credentials_helper { |
| 25 |
| 26 namespace { |
| 27 |
| 28 WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { |
| 29 #if defined(OS_CHROMEOS) |
| 30 return GetWifiCredentialsForProfileChromeOs(profile); |
| 31 #else |
| 32 NOTIMPLEMENTED(); |
| 33 return WifiCredential::MakeSet(); |
| 34 #endif |
| 35 } |
| 36 |
| 37 bool CredentialsMatch(const WifiCredentialSet& a_credentials, |
| 38 const WifiCredentialSet& b_credentials) { |
| 39 if (a_credentials.size() != b_credentials.size()) { |
| 40 LOG(ERROR) << "CredentialSets a and b do not match in size: " |
| 41 << a_credentials.size() |
| 42 << " vs " << b_credentials.size() << " respectively."; |
| 43 return false; |
| 44 } |
| 45 |
| 46 for (const auto &credential : a_credentials) { |
| 47 if (b_credentials.find(credential) == b_credentials.end()) { |
| 48 LOG(ERROR) |
| 49 << "Network from a not found in b. " |
| 50 << "SSID (hex): " |
| 51 << base::HexEncode(credential.ssid().data(), |
| 52 credential.ssid().size()).c_str() |
| 53 << " SecurityClass: " << credential.security_class() |
| 54 << " Passphrase: " << credential.passphrase(); |
| 55 return false; |
| 56 } |
| 57 } |
| 58 |
| 59 return true; |
| 60 } |
| 61 |
| 62 } // namespace |
| 63 |
| 64 bool VerifierIsEmpty() { |
| 65 return GetWifiCredentialsForProfile(test()->verifier()).empty(); |
| 66 } |
| 67 |
| 68 bool ProfileMatchesVerifier(int profile_index) { |
| 69 WifiCredentialSet verifier_credentials = |
| 70 GetWifiCredentialsForProfile(test()->verifier()); |
| 71 WifiCredentialSet other_credentials = |
| 72 GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); |
| 73 return CredentialsMatch(verifier_credentials, other_credentials); |
| 74 } |
| 75 |
| 76 bool AllProfilesMatch() { |
| 77 if (test()->use_verifier() && !ProfileMatchesVerifier(0)) { |
| 78 LOG(ERROR) << "Profile 0 does not match verifier."; |
| 79 return false; |
| 80 } |
| 81 |
| 82 WifiCredentialSet profile0_credentials = |
| 83 GetWifiCredentialsForProfile(test()->GetProfile(0)); |
| 84 for (int i = 1; i < test()->num_clients(); ++i) { |
| 85 WifiCredentialSet other_profile_credentials = |
| 86 GetWifiCredentialsForProfile(test()->GetProfile(i)); |
| 87 if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { |
| 88 LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; |
| 89 return false; |
| 90 } |
| 91 } |
| 92 return true; |
| 93 } |
| 94 |
| 95 } // namespace wifi_credentials_helper |
OLD | NEW |