forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new component for WiFi credential sync. Populate the
new component with a stub SyncableService, and its corresponding factory. This SyncableService is plumbed into sync iff "--enable-wifi-credential-sync" is present in the command-line. Also: - add sync integration tests (single client, and two client) - add WifiSecurityClass: an enum to provide an internal representation of WiFi security classes (e.g. WEP, PSK). - add WifiCredential: an abstraction of the parameters required to find and connect to a WiFi network - add conversions between ModelType and NotificationType, for WIFI_CREDENTIALS BUG=chromium:426693 BUG=chromium:426696 BUG=chromium:427595 TEST=sync_integration_tests --gtest_filter="*Wifi*" TEST=components_unittests --gtest_filter="Wifi*" Review URL: https://codereview.chromium.org/709683004 Cr-Commit-Position: refs/heads/master@{#309333}
- Loading branch information
quiche
authored and
Commit bot
committed
Dec 20, 2014
1 parent
7608f02
commit 271c6cc
Showing
33 changed files
with
879 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
chrome/browser/sync/test/integration/single_client_wifi_credentials_sync_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 "base/command_line.h" | ||
#include "base/macros.h" | ||
#include "chrome/browser/sync/test/integration/sync_test.h" | ||
#include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" | ||
#include "chrome/common/chrome_switches.h" | ||
|
||
class SingleClientWifiCredentialsSyncTest : public SyncTest { | ||
public: | ||
SingleClientWifiCredentialsSyncTest() : SyncTest(SINGLE_CLIENT) {} | ||
~SingleClientWifiCredentialsSyncTest() override {} | ||
|
||
void SetUpCommandLine(CommandLine* command_line) override { | ||
SyncTest::SetUpCommandLine(command_line); | ||
command_line->AppendSwitch(switches::kEnableWifiCredentialSync); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(SingleClientWifiCredentialsSyncTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(SingleClientWifiCredentialsSyncTest, NoCredentials) { | ||
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | ||
ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty()); | ||
ASSERT_TRUE(wifi_credentials_helper::ProfileMatchesVerifier(0)); | ||
} |
29 changes: 29 additions & 0 deletions
29
chrome/browser/sync/test/integration/two_client_wifi_credentials_sync_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 "base/command_line.h" | ||
#include "base/macros.h" | ||
#include "chrome/browser/sync/test/integration/sync_test.h" | ||
#include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" | ||
#include "chrome/common/chrome_switches.h" | ||
|
||
class TwoClientWifiCredentialsSyncTest : public SyncTest { | ||
public: | ||
TwoClientWifiCredentialsSyncTest() : SyncTest(TWO_CLIENT) {} | ||
~TwoClientWifiCredentialsSyncTest() override {} | ||
|
||
void SetUpCommandLine(CommandLine* command_line) override { | ||
SyncTest::SetUpCommandLine(command_line); | ||
command_line->AppendSwitch(switches::kEnableWifiCredentialSync); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(TwoClientWifiCredentialsSyncTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(TwoClientWifiCredentialsSyncTest, NoCredentials) { | ||
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | ||
ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty()); | ||
ASSERT_TRUE(wifi_credentials_helper::AllProfilesMatch()); | ||
} |
95 changes: 95 additions & 0 deletions
95
chrome/browser/sync/test/integration/wifi_credentials_helper.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// 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 "base/logging.h" | ||
#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.h" | ||
#include "components/wifi_sync/wifi_security_class.h" | ||
|
||
#if defined(OS_CHROMEOS) | ||
#include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.h" | ||
#endif | ||
|
||
using wifi_sync::WifiCredential; | ||
using sync_datatype_helper::test; | ||
|
||
using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; | ||
|
||
namespace wifi_credentials_helper { | ||
|
||
namespace { | ||
|
||
WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) { | ||
#if defined(OS_CHROMEOS) | ||
return GetWifiCredentialsForProfileChromeOs(profile); | ||
#else | ||
NOTIMPLEMENTED(); | ||
return WifiCredential::MakeSet(); | ||
#endif | ||
} | ||
|
||
bool CredentialsMatch(const WifiCredentialSet& a_credentials, | ||
const WifiCredentialSet& b_credentials) { | ||
if (a_credentials.size() != b_credentials.size()) { | ||
LOG(ERROR) << "CredentialSets a and b do not match in size: " | ||
<< a_credentials.size() | ||
<< " vs " << b_credentials.size() << " respectively."; | ||
return false; | ||
} | ||
|
||
for (const auto &credential : a_credentials) { | ||
if (b_credentials.find(credential) == b_credentials.end()) { | ||
LOG(ERROR) | ||
<< "Network from a not found in b. " | ||
<< "SSID (hex): " | ||
<< base::HexEncode(credential.ssid().data(), | ||
credential.ssid().size()).c_str() | ||
<< " SecurityClass: " << credential.security_class() | ||
<< " Passphrase: " << credential.passphrase(); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace | ||
|
||
bool VerifierIsEmpty() { | ||
return GetWifiCredentialsForProfile(test()->verifier()).empty(); | ||
} | ||
|
||
bool ProfileMatchesVerifier(int profile_index) { | ||
WifiCredentialSet verifier_credentials = | ||
GetWifiCredentialsForProfile(test()->verifier()); | ||
WifiCredentialSet other_credentials = | ||
GetWifiCredentialsForProfile(test()->GetProfile(profile_index)); | ||
return CredentialsMatch(verifier_credentials, other_credentials); | ||
} | ||
|
||
bool AllProfilesMatch() { | ||
if (test()->use_verifier() && !ProfileMatchesVerifier(0)) { | ||
LOG(ERROR) << "Profile 0 does not match verifier."; | ||
return false; | ||
} | ||
|
||
WifiCredentialSet profile0_credentials = | ||
GetWifiCredentialsForProfile(test()->GetProfile(0)); | ||
for (int i = 1; i < test()->num_clients(); ++i) { | ||
WifiCredentialSet other_profile_credentials = | ||
GetWifiCredentialsForProfile(test()->GetProfile(i)); | ||
if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) { | ||
LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0."; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace wifi_credentials_helper |
26 changes: 26 additions & 0 deletions
26
chrome/browser/sync/test/integration/wifi_credentials_helper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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. | ||
|
||
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_ | ||
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_ | ||
|
||
// Functions needed by multiple wifi_credentials integration | ||
// tests. This module is platfrom-agnostic, and calls out to | ||
// platform-specific code as needed. | ||
namespace wifi_credentials_helper { | ||
|
||
// Checks if the verifier has any items in it. Returns true iff the | ||
// verifier has no items. | ||
bool VerifierIsEmpty(); | ||
|
||
// Compares the BrowserContext for |profile_index| with the | ||
// verifier. Returns true iff their WiFi credentials match. | ||
bool ProfileMatchesVerifier(int profile_index); | ||
|
||
// Returns true iff all BrowserContexts match with the verifier. | ||
bool AllProfilesMatch(); | ||
|
||
} // namespace wifi_credentials_helper | ||
|
||
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_ |
49 changes: 49 additions & 0 deletions
49
chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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_chromeos.h" | ||
|
||
#include <string> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/logging.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chromeos/network/network_handler.h" | ||
#include "chromeos/network/network_state.h" | ||
#include "chromeos/network/network_state_handler.h" | ||
#include "components/wifi_sync/network_state_helper_chromeos.h" | ||
#include "components/wifi_sync/wifi_security_class.h" | ||
|
||
using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; | ||
|
||
namespace wifi_credentials_helper { | ||
|
||
namespace { | ||
|
||
const char kProfilePrefix[] = "/profile/"; | ||
|
||
std::string ChromeOsUserHashForBrowserContext( | ||
const content::BrowserContext& context) { | ||
return context.GetPath().BaseName().value(); | ||
} | ||
|
||
std::string ShillProfilePathForBrowserContext( | ||
const content::BrowserContext& context) { | ||
return kProfilePrefix + ChromeOsUserHashForBrowserContext(context); | ||
} | ||
|
||
chromeos::NetworkStateHandler* GetNetworkStateHandler() { | ||
DCHECK(chromeos::NetworkHandler::Get()->network_state_handler()); | ||
return chromeos::NetworkHandler::Get()->network_state_handler(); | ||
} | ||
|
||
} // namespace | ||
|
||
WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) { | ||
DCHECK(profile); | ||
return wifi_sync::GetWifiCredentialsForShillProfile( | ||
GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile)); | ||
} | ||
|
||
} // namespace wifi_credentials_helper |
20 changes: 20 additions & 0 deletions
20
chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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. | ||
|
||
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_ | ||
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_ | ||
|
||
#include "components/wifi_sync/wifi_credential.h" | ||
|
||
class Profile; | ||
|
||
namespace wifi_credentials_helper { | ||
|
||
// Returns the ChromeOS WiFi credentials associated with |profile|. | ||
wifi_sync::WifiCredential::CredentialSet GetWifiCredentialsForProfileChromeOs( | ||
const Profile* profile); | ||
|
||
} // namespace wifi_credentials_helper | ||
|
||
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.