Commit 491b092b authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

[Nearby] Add test for stored active profile

Adds a missing test for when the active profile is stored on disk but
not currently loaded. This is only relevant for Chrome browser as this
doesn't happen on CrOS.

Bug: None
Change-Id: I4f691f97ed7de882ec8f7f0886f6ebfff762a899
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388624Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803889}
parent f01b6883
...@@ -136,7 +136,6 @@ ProfileAttributesEntry* NearbyProcessManager::GetActiveProfile() const { ...@@ -136,7 +136,6 @@ ProfileAttributesEntry* NearbyProcessManager::GetActiveProfile() const {
bool NearbyProcessManager::IsActiveProfile(Profile* profile) const { bool NearbyProcessManager::IsActiveProfile(Profile* profile) const {
// If the active profile is not loaded yet, try looking in prefs. // If the active profile is not loaded yet, try looking in prefs.
// TODO(knollr): Add a test for this.
if (!active_profile_) if (!active_profile_)
return IsStoredNearbyProfile(profile); return IsStoredNearbyProfile(profile);
......
...@@ -12,10 +12,14 @@ ...@@ -12,10 +12,14 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
#include "chrome/browser/nearby_sharing/mock_nearby_connections.h" #include "chrome/browser/nearby_sharing/mock_nearby_connections.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h" #include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/services/sharing/public/mojom/nearby_connections.mojom.h" #include "chrome/services/sharing/public/mojom/nearby_connections.mojom.h"
#include "chrome/services/sharing/public/mojom/nearby_connections_types.mojom.h" #include "chrome/services/sharing/public/mojom/nearby_connections_types.mojom.h"
#include "chrome/services/sharing/public/mojom/nearby_decoder.mojom.h" #include "chrome/services/sharing/public/mojom/nearby_decoder.mojom.h"
...@@ -24,6 +28,8 @@ ...@@ -24,6 +28,8 @@
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
...@@ -99,9 +105,15 @@ class NearbyProcessManagerTest : public testing::Test { ...@@ -99,9 +105,15 @@ class NearbyProcessManagerTest : public testing::Test {
NearbyProcessManagerTest() = default; NearbyProcessManagerTest() = default;
~NearbyProcessManagerTest() override = default; ~NearbyProcessManagerTest() override = default;
void SetUp() override { ASSERT_TRUE(testing_profile_manager_.SetUp()); } void SetUp() override {
ASSERT_TRUE(testing_profile_manager_.SetUp());
NearbyProcessManager::GetInstance().ClearActiveProfile();
}
void TearDown() override { DeleteAllProfiles(); } void TearDown() override {
NearbyProcessManager::GetInstance().ClearActiveProfile();
DeleteAllProfiles();
}
Profile* CreateProfile(const std::string& name) { Profile* CreateProfile(const std::string& name) {
Profile* profile = testing_profile_manager_.CreateTestingProfile(name); Profile* profile = testing_profile_manager_.CreateTestingProfile(name);
...@@ -109,6 +121,19 @@ class NearbyProcessManagerTest : public testing::Test { ...@@ -109,6 +121,19 @@ class NearbyProcessManagerTest : public testing::Test {
return profile; return profile;
} }
base::FilePath CreateProfileOnDisk(const std::string& name) {
base::FilePath file_path =
testing_profile_manager_.profiles_dir().AppendASCII(name);
ProfileAttributesStorage* storage =
testing_profile_manager_.profile_attributes_storage();
storage->AddProfile(file_path, base::ASCIIToUTF16(name),
/*gaia_id=*/std::string(),
/*user_name=*/base::string16(),
/*is_consented_primary_account=*/false,
/*icon_index=*/0, "TEST_ID", EmptyAccountId());
return file_path;
}
void DeleteProfile(Profile* profile) { void DeleteProfile(Profile* profile) {
DoDeleteProfile(profile); DoDeleteProfile(profile);
profiles_.erase(profile); profiles_.erase(profile);
...@@ -178,6 +203,23 @@ TEST_F(NearbyProcessManagerTest, IsActiveProfile) { ...@@ -178,6 +203,23 @@ TEST_F(NearbyProcessManagerTest, IsActiveProfile) {
EXPECT_FALSE(manager.IsActiveProfile(profile_2)); EXPECT_FALSE(manager.IsActiveProfile(profile_2));
} }
TEST_F(NearbyProcessManagerTest, IsActiveProfile_Unloaded) {
auto& manager = NearbyProcessManager::GetInstance();
Profile* profile_1 = CreateProfile("name 1");
base::FilePath file_path_profile_2 = CreateProfileOnDisk("name 2");
EXPECT_FALSE(manager.IsAnyProfileActive());
g_browser_process->local_state()->SetFilePath(
prefs::kNearbySharingActiveProfilePrefName, file_path_profile_2);
EXPECT_TRUE(manager.IsAnyProfileActive());
EXPECT_FALSE(manager.IsActiveProfile(profile_1));
ProfileAttributesEntry* active_profile = manager.GetActiveProfile();
ASSERT_TRUE(active_profile);
EXPECT_EQ(file_path_profile_2, active_profile->GetPath());
}
TEST_F(NearbyProcessManagerTest, IsAnyProfileActive) { TEST_F(NearbyProcessManagerTest, IsAnyProfileActive) {
auto& manager = NearbyProcessManager::GetInstance(); auto& manager = NearbyProcessManager::GetInstance();
Profile* profile = CreateProfile("name"); Profile* profile = CreateProfile("name");
......
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