Commit 6d927583 authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Sync networks added in OOBE to first account.

Any networks that are added during OOBE should be considered to be owned
by first user to log in for the purposes of sync.

Bug: 966270
Change-Id: I04495ee36c93cd4ae652e1cf45cfaafaf31224fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231859Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Jon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775795}
parent 61e60c8b
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chromeos/components/sync_wifi/wifi_configuration_sync_service.h" #include "chromeos/components/sync_wifi/wifi_configuration_sync_service.h"
#include "chromeos/network/network_handler.h" #include "chromeos/network/network_handler.h"
#include "chromeos/network/network_metadata_store.h" #include "chromeos/network/network_metadata_store.h"
#include "chromeos/tpm/install_attributes.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
namespace chromeos { namespace chromeos {
...@@ -41,6 +42,8 @@ void NetworkPrefStateObserver::Observe( ...@@ -41,6 +42,8 @@ void NetworkPrefStateObserver::Observe(
// in. Other profiles are ignored because only the primary user's network // in. Other profiles are ignored because only the primary user's network
// configuration is used on Chrome OS. // configuration is used on Chrome OS.
if (ProfileHelper::IsPrimaryProfile(profile)) { if (ProfileHelper::IsPrimaryProfile(profile)) {
NetworkHandler::Get()->set_is_enterprise_managed(
InstallAttributes::Get()->IsEnterpriseManaged());
InitializeNetworkPrefServices(profile); InitializeNetworkPrefServices(profile);
notification_registrar_.RemoveAll(); notification_registrar_.RemoveAll();
......
...@@ -409,9 +409,7 @@ void WifiConfigurationBridge::SaveNetworkToSync( ...@@ -409,9 +409,7 @@ void WifiConfigurationBridge::SaveNetworkToSync(
metrics_recorder_->RecordTotalCount(entries_.size()); metrics_recorder_->RecordTotalCount(entries_.size());
} }
void WifiConfigurationBridge::OnConfigurationCreated( void WifiConfigurationBridge::OnNetworkCreated(const std::string& guid) {
const std::string& service_path,
const std::string& guid) {
if (network_metadata_store_->GetIsConfiguredBySync(guid)) { if (network_metadata_store_->GetIsConfiguredBySync(guid)) {
// Don't have to upload a configuration that came from sync. // Don't have to upload a configuration that came from sync.
NET_LOG(EVENT) << "Not uploading newly configured network " NET_LOG(EVENT) << "Not uploading newly configured network "
......
...@@ -70,12 +70,11 @@ class WifiConfigurationBridge : public syncer::ModelTypeSyncBridge, ...@@ -70,12 +70,11 @@ class WifiConfigurationBridge : public syncer::ModelTypeSyncBridge,
// NetworkMetadataObserver: // NetworkMetadataObserver:
void OnFirstConnectionToNetwork(const std::string& guid) override; void OnFirstConnectionToNetwork(const std::string& guid) override;
void OnNetworkCreated(const std::string& guid) override;
void OnNetworkUpdate(const std::string& guid, void OnNetworkUpdate(const std::string& guid,
base::DictionaryValue* set_properties) override; base::DictionaryValue* set_properties) override;
// NetworkConfigurationObserver:: // NetworkConfigurationObserver::
void OnConfigurationCreated(const std::string& service_path,
const std::string& guid) override;
void OnBeforeConfigurationRemoved(const std::string& service_path, void OnBeforeConfigurationRemoved(const std::string& service_path,
const std::string& guid) override; const std::string& guid) override;
void OnConfigurationRemoved(const std::string& service_path, void OnConfigurationRemoved(const std::string& service_path,
...@@ -113,6 +112,8 @@ class WifiConfigurationBridge : public syncer::ModelTypeSyncBridge, ...@@ -113,6 +112,8 @@ class WifiConfigurationBridge : public syncer::ModelTypeSyncBridge,
// Starts an async request to serialize a network to a proto and save to sync. // Starts an async request to serialize a network to a proto and save to sync.
void OnNetworkConfiguredDelayComplete(const std::string& network_guid); void OnNetworkConfiguredDelayComplete(const std::string& network_guid);
bool IsLastUpdateFromSync(const std::string& network_guid);
// An in-memory list of the proto's that mirrors what is on the sync server. // An in-memory list of the proto's that mirrors what is on the sync server.
// This gets updated when changes are received from the server and after local // This gets updated when changes are received from the server and after local
// changes have been committed. On initialization of this class, it is // changes have been committed. On initialization of this class, it is
......
...@@ -159,7 +159,7 @@ class WifiConfigurationBridgeTest : public testing::Test { ...@@ -159,7 +159,7 @@ class WifiConfigurationBridgeTest : public testing::Test {
/*network_configuration_handler=*/nullptr, /*network_configuration_handler=*/nullptr,
/*network_connection_handler=*/nullptr, /*network_connection_handler=*/nullptr,
/*network_state_handler=*/nullptr, user_prefs_.get(), /*network_state_handler=*/nullptr, user_prefs_.get(),
device_prefs_.get()); device_prefs_.get(), /*is_enterprise_enrolled=*/false);
bridge_ = std::make_unique<WifiConfigurationBridge>( bridge_ = std::make_unique<WifiConfigurationBridge>(
synced_network_updater(), local_network_collector(), synced_network_updater(), local_network_collector(),
...@@ -420,7 +420,7 @@ TEST_F(WifiConfigurationBridgeTest, LocalConfigured) { ...@@ -420,7 +420,7 @@ TEST_F(WifiConfigurationBridgeTest, LocalConfigured) {
EXPECT_CALL(*processor(), Put(_, _, _)) EXPECT_CALL(*processor(), Put(_, _, _))
.WillOnce(testing::SaveArg<0>(&storage_key)); .WillOnce(testing::SaveArg<0>(&storage_key));
std::string guid = meow_network_id().SerializeToString(); std::string guid = meow_network_id().SerializeToString();
bridge()->OnConfigurationCreated("service_path", guid); bridge()->OnNetworkCreated(guid);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
timer_factory()->FireAll(); timer_factory()->FireAll();
...@@ -435,7 +435,7 @@ TEST_F(WifiConfigurationBridgeTest, LocalConfigured_BadPassword) { ...@@ -435,7 +435,7 @@ TEST_F(WifiConfigurationBridgeTest, LocalConfigured_BadPassword) {
EXPECT_CALL(*processor(), Put(_, _, _)).Times(testing::Exactly(0)); EXPECT_CALL(*processor(), Put(_, _, _)).Times(testing::Exactly(0));
std::string guid = meow_network_id().SerializeToString(); std::string guid = meow_network_id().SerializeToString();
bridge()->OnConfigurationCreated("service_path", guid); bridge()->OnNetworkCreated(guid);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
timer_factory()->FireAll(); timer_factory()->FireAll();
......
...@@ -126,7 +126,8 @@ void NetworkHandler::InitializePrefServices( ...@@ -126,7 +126,8 @@ void NetworkHandler::InitializePrefServices(
ui_proxy_config_service_.get()); ui_proxy_config_service_.get());
network_metadata_store_.reset(new NetworkMetadataStore( network_metadata_store_.reset(new NetworkMetadataStore(
network_configuration_handler_.get(), network_connection_handler_.get(), network_configuration_handler_.get(), network_connection_handler_.get(),
network_state_handler_.get(), logged_in_profile_prefs, device_prefs)); network_state_handler_.get(), logged_in_profile_prefs, device_prefs,
is_enterprise_managed_));
} }
void NetworkHandler::ShutdownPrefServices() { void NetworkHandler::ShutdownPrefServices() {
......
...@@ -89,6 +89,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkHandler { ...@@ -89,6 +89,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkHandler {
UIProxyConfigService* ui_proxy_config_service(); UIProxyConfigService* ui_proxy_config_service();
bool has_ui_proxy_config_service() { return ui_proxy_config_service_.get(); } bool has_ui_proxy_config_service() { return ui_proxy_config_service_.get(); }
void set_is_enterprise_managed(bool is_enterprise_managed) {
is_enterprise_managed_ = is_enterprise_managed;
}
private: private:
NetworkHandler(); NetworkHandler();
virtual ~NetworkHandler(); virtual ~NetworkHandler();
...@@ -117,6 +121,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkHandler { ...@@ -117,6 +121,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkHandler {
std::unique_ptr<UIProxyConfigService> ui_proxy_config_service_; std::unique_ptr<UIProxyConfigService> ui_proxy_config_service_;
std::unique_ptr<CellularMetricsLogger> cellular_metrics_logger_; std::unique_ptr<CellularMetricsLogger> cellular_metrics_logger_;
// True when the device is managed by policy.
bool is_enterprise_managed_ = false;
DISALLOW_COPY_AND_ASSIGN(NetworkHandler); DISALLOW_COPY_AND_ASSIGN(NetworkHandler);
}; };
......
...@@ -13,6 +13,8 @@ NetworkMetadataObserver::~NetworkMetadataObserver() = default; ...@@ -13,6 +13,8 @@ NetworkMetadataObserver::~NetworkMetadataObserver() = default;
void NetworkMetadataObserver::OnFirstConnectionToNetwork( void NetworkMetadataObserver::OnFirstConnectionToNetwork(
const std::string& guid) {} const std::string& guid) {}
void NetworkMetadataObserver::OnNetworkCreated(const std::string& guid) {}
void NetworkMetadataObserver::OnNetworkUpdate( void NetworkMetadataObserver::OnNetworkUpdate(
const std::string& guid, const std::string& guid,
base::DictionaryValue* set_properties) {} base::DictionaryValue* set_properties) {}
......
...@@ -21,6 +21,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataObserver ...@@ -21,6 +21,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataObserver
// Called the first time that a network is successfully connected to. // Called the first time that a network is successfully connected to.
virtual void OnFirstConnectionToNetwork(const std::string& guid); virtual void OnFirstConnectionToNetwork(const std::string& guid);
// Called after a network configuration and associated metadata has been
// created.
virtual void OnNetworkCreated(const std::string& guid);
// Called after a network configuration and associated metadata has been // Called after a network configuration and associated metadata has been
// updated. // updated.
virtual void OnNetworkUpdate(const std::string& guid, virtual void OnNetworkUpdate(const std::string& guid,
......
...@@ -61,18 +61,23 @@ NetworkMetadataStore::NetworkMetadataStore( ...@@ -61,18 +61,23 @@ NetworkMetadataStore::NetworkMetadataStore(
NetworkConnectionHandler* network_connection_handler, NetworkConnectionHandler* network_connection_handler,
NetworkStateHandler* network_state_handler, NetworkStateHandler* network_state_handler,
PrefService* profile_pref_service, PrefService* profile_pref_service,
PrefService* device_pref_service) PrefService* device_pref_service,
bool is_enterprise_managed)
: network_configuration_handler_(network_configuration_handler), : network_configuration_handler_(network_configuration_handler),
network_connection_handler_(network_connection_handler), network_connection_handler_(network_connection_handler),
network_state_handler_(network_state_handler), network_state_handler_(network_state_handler),
profile_pref_service_(profile_pref_service), profile_pref_service_(profile_pref_service),
device_pref_service_(device_pref_service) { device_pref_service_(device_pref_service),
is_enterprise_managed_(is_enterprise_managed) {
if (network_connection_handler_) { if (network_connection_handler_) {
network_connection_handler_->AddObserver(this); network_connection_handler_->AddObserver(this);
} }
if (network_configuration_handler_) { if (network_configuration_handler_) {
network_configuration_handler_->AddObserver(this); network_configuration_handler_->AddObserver(this);
} }
if (LoginState::IsInitialized()) {
LoginState::Get()->AddObserver(this);
}
} }
NetworkMetadataStore::~NetworkMetadataStore() { NetworkMetadataStore::~NetworkMetadataStore() {
...@@ -82,6 +87,40 @@ NetworkMetadataStore::~NetworkMetadataStore() { ...@@ -82,6 +87,40 @@ NetworkMetadataStore::~NetworkMetadataStore() {
if (network_configuration_handler_) { if (network_configuration_handler_) {
network_configuration_handler_->RemoveObserver(this); network_configuration_handler_->RemoveObserver(this);
} }
if (LoginState::IsInitialized()) {
LoginState::Get()->RemoveObserver(this);
}
}
void NetworkMetadataStore::LoggedInStateChanged() {
OwnSharedNetworksOnFirstUserLogin();
}
void NetworkMetadataStore::OwnSharedNetworksOnFirstUserLogin() {
if (is_enterprise_managed_ || !network_state_handler_ ||
!user_manager::UserManager::IsInitialized()) {
return;
}
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
if (!user_manager->IsCurrentUserNew() ||
!user_manager->IsCurrentUserOwner()) {
return;
}
NET_LOG(EVENT) << "Taking ownership of shared networks.";
NetworkStateHandler::NetworkStateList networks;
network_state_handler_->GetNetworkListByType(NetworkTypePattern::WiFi(), true,
false, 0, &networks);
for (const chromeos::NetworkState* network : networks) {
if (network->IsPrivate()) {
continue;
}
SetIsCreatedByUser(network->guid());
}
} }
void NetworkMetadataStore::ConnectSucceeded(const std::string& service_path) { void NetworkMetadataStore::ConnectSucceeded(const std::string& service_path) {
...@@ -126,6 +165,10 @@ void NetworkMetadataStore::ConnectFailed(const std::string& service_path, ...@@ -126,6 +165,10 @@ void NetworkMetadataStore::ConnectFailed(const std::string& service_path,
void NetworkMetadataStore::OnConfigurationCreated( void NetworkMetadataStore::OnConfigurationCreated(
const std::string& service_path, const std::string& service_path,
const std::string& guid) { const std::string& guid) {
SetIsCreatedByUser(guid);
}
void NetworkMetadataStore::SetIsCreatedByUser(const std::string& network_guid) {
if (!user_manager::UserManager::IsInitialized()) if (!user_manager::UserManager::IsInitialized())
return; return;
...@@ -137,7 +180,11 @@ void NetworkMetadataStore::OnConfigurationCreated( ...@@ -137,7 +180,11 @@ void NetworkMetadataStore::OnConfigurationCreated(
return; return;
} }
SetPref(guid, kOwner, base::Value(user->username_hash())); SetPref(network_guid, kOwner, base::Value(user->username_hash()));
for (auto& observer : observers_) {
observer.OnNetworkCreated(network_guid);
}
} }
void NetworkMetadataStore::UpdateExternalModifications( void NetworkMetadataStore::UpdateExternalModifications(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/values.h" #include "base/values.h"
#include "chromeos/login/login_state/login_state.h"
#include "chromeos/network/network_configuration_observer.h" #include "chromeos/network/network_configuration_observer.h"
#include "chromeos/network/network_connection_observer.h" #include "chromeos/network/network_connection_observer.h"
#include "chromeos/network/network_metadata_observer.h" #include "chromeos/network/network_metadata_observer.h"
...@@ -32,14 +33,16 @@ class NetworkStateHandler; ...@@ -32,14 +33,16 @@ class NetworkStateHandler;
// networks. // networks.
class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore
: public NetworkConnectionObserver, : public NetworkConnectionObserver,
public NetworkConfigurationObserver { public NetworkConfigurationObserver,
public LoginState::Observer {
public: public:
NetworkMetadataStore( NetworkMetadataStore(
NetworkConfigurationHandler* network_configuration_handler, NetworkConfigurationHandler* network_configuration_handler,
NetworkConnectionHandler* network_connection_handler, NetworkConnectionHandler* network_connection_handler,
NetworkStateHandler* network_state_handler, NetworkStateHandler* network_state_handler,
PrefService* profile_pref_service, PrefService* profile_pref_service,
PrefService* device_pref_service); PrefService* device_pref_service,
bool is_enterprise_managed);
~NetworkMetadataStore() override; ~NetworkMetadataStore() override;
...@@ -48,6 +51,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore ...@@ -48,6 +51,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore
// prior to using this class. // prior to using this class.
static void RegisterPrefs(PrefRegistrySimple* registry); static void RegisterPrefs(PrefRegistrySimple* registry);
// LoginState::Observer overrides.
void LoggedInStateChanged() override;
// NetworkConnectionObserver:: // NetworkConnectionObserver::
void ConnectSucceeded(const std::string& service_path) override; void ConnectSucceeded(const std::string& service_path) override;
void ConnectFailed(const std::string& service_path, void ConnectFailed(const std::string& service_path,
...@@ -87,6 +93,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore ...@@ -87,6 +93,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore
// will always return false. // will always return false.
bool GetHasBadPassword(const std::string& network_guid); bool GetHasBadPassword(const std::string& network_guid);
// When the active user is the device owner and its the first login, this
// marks networks that were added in OOBE to the user's list.
void OwnSharedNetworksOnFirstUserLogin();
// Manage observers. // Manage observers.
void AddObserver(NetworkMetadataObserver* observer); void AddObserver(NetworkMetadataObserver* observer);
void RemoveObserver(NetworkMetadataObserver* observer); void RemoveObserver(NetworkMetadataObserver* observer);
...@@ -106,12 +116,16 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore ...@@ -106,12 +116,16 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkMetadataStore
void UpdateExternalModifications(const std::string& network_guid, void UpdateExternalModifications(const std::string& network_guid,
const std::string& field); const std::string& field);
// Sets the owner metadata when there is an active user, otherwise a no-op.
void SetIsCreatedByUser(const std::string& network_guid);
base::ObserverList<NetworkMetadataObserver> observers_; base::ObserverList<NetworkMetadataObserver> observers_;
NetworkConfigurationHandler* network_configuration_handler_; NetworkConfigurationHandler* network_configuration_handler_;
NetworkConnectionHandler* network_connection_handler_; NetworkConnectionHandler* network_connection_handler_;
NetworkStateHandler* network_state_handler_; NetworkStateHandler* network_state_handler_;
PrefService* profile_pref_service_; PrefService* profile_pref_service_;
PrefService* device_pref_service_; PrefService* device_pref_service_;
bool is_enterprise_managed_;
base::WeakPtrFactory<NetworkMetadataStore> weak_ptr_factory_{this}; base::WeakPtrFactory<NetworkMetadataStore> weak_ptr_factory_{this};
}; };
......
...@@ -93,7 +93,8 @@ class NetworkMetadataStoreTest : public ::testing::Test { ...@@ -93,7 +93,8 @@ class NetworkMetadataStoreTest : public ::testing::Test {
metadata_store_ = std::make_unique<NetworkMetadataStore>( metadata_store_ = std::make_unique<NetworkMetadataStore>(
network_configuration_handler_, network_connection_handler_.get(), network_configuration_handler_, network_connection_handler_.get(),
network_state_handler_, user_prefs_.get(), device_prefs_.get()); network_state_handler_, user_prefs_.get(), device_prefs_.get(),
/*is_enterprise_enrolled=*/false);
metadata_observer_ = std::make_unique<TestNetworkMetadataObserver>(); metadata_observer_ = std::make_unique<TestNetworkMetadataObserver>();
metadata_store_->AddObserver(metadata_observer_.get()); metadata_store_->AddObserver(metadata_observer_.get());
} }
...@@ -110,15 +111,30 @@ class NetworkMetadataStoreTest : public ::testing::Test { ...@@ -110,15 +111,30 @@ class NetworkMetadataStoreTest : public ::testing::Test {
NetworkHandler::Shutdown(); NetworkHandler::Shutdown();
} }
void SetUp() override { LoginUser(primary_user_); } void SetUp() override {
SetIsEnterpriseEnrolled(false);
LoginUser(primary_user_);
}
// This creates a new NetworkMetadataStore object.
void SetIsEnterpriseEnrolled(bool is_enterprise_enrolled) {
metadata_store_.reset(new NetworkMetadataStore(
network_configuration_handler_, network_connection_handler_.get(),
network_state_handler_, user_prefs_.get(), device_prefs_.get(),
is_enterprise_enrolled));
metadata_store_->AddObserver(metadata_observer_.get());
}
void LoginUser(const user_manager::User* user) { void LoginUser(const user_manager::User* user) {
auto* user_manager = static_cast<user_manager::FakeUserManager*>( UserManager()->UserLoggedIn(user->GetAccountId(), user->username_hash(),
true /* browser_restart */,
false /* is_child */);
UserManager()->SwitchActiveUser(user->GetAccountId());
}
user_manager::FakeUserManager* UserManager() {
return static_cast<user_manager::FakeUserManager*>(
user_manager::UserManager::Get()); user_manager::UserManager::Get());
user_manager->UserLoggedIn(user->GetAccountId(), user->username_hash(),
true /* browser_restart */,
false /* is_child */);
user_manager->SwitchActiveUser(user->GetAccountId());
} }
std::string ConfigureService(const std::string& shill_json_string) { std::string ConfigureService(const std::string& shill_json_string) {
...@@ -322,4 +338,61 @@ TEST_F(NetworkMetadataStoreTest, ConfigurationRemoved) { ...@@ -322,4 +338,61 @@ TEST_F(NetworkMetadataStoreTest, ConfigurationRemoved) {
ASSERT_FALSE(metadata_store()->GetIsConfiguredBySync(kGuid)); ASSERT_FALSE(metadata_store()->GetIsConfiguredBySync(kGuid));
} }
TEST_F(NetworkMetadataStoreTest, OwnOobeNetworks) {
UserManager()->LogoutAllUsers();
ConfigureService(kConfigWifi1Shared);
base::RunLoop().RunUntilIdle();
LoginUser(primary_user_);
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
UserManager()->set_is_current_user_new(true);
UserManager()->set_is_current_user_owner(true);
metadata_store()->LoggedInStateChanged();
ASSERT_TRUE(metadata_store()->GetIsCreatedByUser(kGuid));
}
TEST_F(NetworkMetadataStoreTest, OwnOobeNetworks_EnterpriseEnrolled) {
SetIsEnterpriseEnrolled(true);
UserManager()->LogoutAllUsers();
ConfigureService(kConfigWifi1Shared);
base::RunLoop().RunUntilIdle();
LoginUser(primary_user_);
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
UserManager()->set_is_current_user_new(true);
UserManager()->set_is_current_user_owner(true);
metadata_store()->LoggedInStateChanged();
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
}
TEST_F(NetworkMetadataStoreTest, OwnOobeNetworks_NotOwner) {
UserManager()->LogoutAllUsers();
ConfigureService(kConfigWifi1Shared);
base::RunLoop().RunUntilIdle();
LoginUser(primary_user_);
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
UserManager()->set_is_current_user_new(true);
UserManager()->set_is_current_user_owner(false);
metadata_store()->LoggedInStateChanged();
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
}
TEST_F(NetworkMetadataStoreTest, OwnOobeNetworks_NotFirstLogin) {
UserManager()->LogoutAllUsers();
ConfigureService(kConfigWifi1Shared);
base::RunLoop().RunUntilIdle();
LoginUser(primary_user_);
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
UserManager()->set_is_current_user_new(false);
UserManager()->set_is_current_user_owner(true);
metadata_store()->LoggedInStateChanged();
ASSERT_FALSE(metadata_store()->GetIsCreatedByUser(kGuid));
}
} // namespace chromeos } // namespace chromeos
...@@ -120,6 +120,11 @@ void FakeUserManager::UpdateUserAccountData( ...@@ -120,6 +120,11 @@ void FakeUserManager::UpdateUserAccountData(
} }
} }
void FakeUserManager::LogoutAllUsers() {
primary_user_ = nullptr;
active_user_ = nullptr;
}
void FakeUserManager::UserLoggedIn(const AccountId& account_id, void FakeUserManager::UserLoggedIn(const AccountId& account_id,
const std::string& username_hash, const std::string& username_hash,
bool browser_restart, bool browser_restart,
...@@ -230,11 +235,11 @@ base::string16 FakeUserManager::GetUserDisplayName( ...@@ -230,11 +235,11 @@ base::string16 FakeUserManager::GetUserDisplayName(
} }
bool FakeUserManager::IsCurrentUserOwner() const { bool FakeUserManager::IsCurrentUserOwner() const {
return false; return is_current_user_owner_;
} }
bool FakeUserManager::IsCurrentUserNew() const { bool FakeUserManager::IsCurrentUserNew() const {
return false; return is_current_user_new_;
} }
bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const { bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
......
...@@ -39,7 +39,15 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { ...@@ -39,7 +39,15 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase {
virtual const user_manager::User* AddPublicAccountUser( virtual const user_manager::User* AddPublicAccountUser(
const AccountId& account_id); const AccountId& account_id);
void LogoutAllUsers();
void set_local_state(PrefService* local_state) { local_state_ = local_state; } void set_local_state(PrefService* local_state) { local_state_ = local_state; }
void set_is_current_user_new(bool is_current_user_new) {
is_current_user_new_ = is_current_user_new;
}
void set_is_current_user_owner(bool is_current_user_owner) {
is_current_user_owner_ = is_current_user_owner;
}
// UserManager overrides. // UserManager overrides.
const UserList& GetUsers() const override; const UserList& GetUsers() const override;
...@@ -170,6 +178,9 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { ...@@ -170,6 +178,9 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase {
// stub. Always empty. // stub. Always empty.
gfx::ImageSkia empty_image_; gfx::ImageSkia empty_image_;
bool is_current_user_owner_ = false;
bool is_current_user_new_ = false;
DISALLOW_COPY_AND_ASSIGN(FakeUserManager); DISALLOW_COPY_AND_ASSIGN(FakeUserManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment