Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2588)

Unified Diff: chrome/browser/sync/test/integration/wifi_credentials_helper.cc

Issue 709683004: components: add wifi_sync component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-1-security-class
Patch Set: update BUILD.gn and commit message Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ 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

Powered by Google App Engine
This is Rietveld 408576698