1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/drive/file_system_util.h"
#include "ash/constants/ash_features.h"
#include "base/files/file_path.h"
#include "base/test/test_file_util.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/test/base/fake_gaia_mixin.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/ash/components/login/login_state/login_state.h"
#include "components/account_id/account_id.h"
#include "components/drive/drive_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "google_apis/gaia/gaia_id.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive::util {
namespace {
using ash::features::kFeatureManagementDriveFsBulkPinning;
using base::test::ScopedFeatureList;
// Marks the current thread as UI by BrowserTaskEnvironment. We need the task
// environment since Profile objects must be touched from UI and hence has
// CHECK/DCHECKs for it.
class ProfileRelatedFileSystemUtilTest : public testing::Test {
private:
content::BrowserTaskEnvironment task_environment_;
};
} // namespace
TEST_F(ProfileRelatedFileSystemUtilTest, IsUnderDriveMountPoint) {
EXPECT_FALSE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/wherever/foo.txt")));
EXPECT_FALSE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/media/fuse/foo.txt")));
EXPECT_FALSE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("media/fuse/drivefs/foo.txt")));
EXPECT_TRUE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/media/fuse/drivefs")));
EXPECT_TRUE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/media/fuse/drivefs/foo.txt")));
EXPECT_TRUE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/media/fuse/drivefs/subdir/foo.txt")));
EXPECT_TRUE(IsUnderDriveMountPoint(
base::FilePath::FromUTF8Unsafe("/media/fuse/drivefs-xxx/foo.txt")));
}
TEST_F(ProfileRelatedFileSystemUtilTest, GetCacheRootPath) {
TestingProfile profile(base::CreateUniqueTempDirectoryScopedToTest());
base::FilePath profile_path = profile.GetPath();
EXPECT_EQ(profile_path.AppendASCII("GCache/v1"),
util::GetCacheRootPath(&profile));
}
TEST_F(ProfileRelatedFileSystemUtilTest, SetDriveConnectionStatusForTesting) {
TestingProfile profile;
using enum ConnectionStatus;
EXPECT_EQ(GetDriveConnectionStatus(&profile), kNoService);
for (const ConnectionStatus status :
{kNoNetwork, kNotReady, kNoService, kMetered, kConnected}) {
SetDriveConnectionStatusForTesting(status);
EXPECT_EQ(GetDriveConnectionStatus(&profile), status);
}
}
TEST_F(ProfileRelatedFileSystemUtilTest, IsDriveFsBulkPinningAvailable) {
TestingProfile profile;
PrefService* const prefs = profile.GetPrefs();
DCHECK(prefs);
EXPECT_TRUE(prefs->GetBoolean(prefs::kDriveFsBulkPinningVisible));
{
ScopedFeatureList features;
features.InitWithFeatures({kFeatureManagementDriveFsBulkPinning}, {});
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(&profile));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(nullptr));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable());
}
{
ScopedFeatureList features;
features.InitWithFeatures({}, {kFeatureManagementDriveFsBulkPinning});
EXPECT_FALSE(IsDriveFsBulkPinningAvailable(&profile));
EXPECT_FALSE(IsDriveFsBulkPinningAvailable(nullptr));
EXPECT_FALSE(IsDriveFsBulkPinningAvailable());
}
prefs->SetBoolean(prefs::kDriveFsBulkPinningVisible, false);
{
ScopedFeatureList features;
features.InitWithFeatures({kFeatureManagementDriveFsBulkPinning}, {});
EXPECT_FALSE(IsDriveFsBulkPinningAvailable(&profile));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(nullptr));
}
prefs->SetBoolean(prefs::kDriveFsBulkPinningVisible, true);
{
ScopedFeatureList features;
features.InitWithFeatures({kFeatureManagementDriveFsBulkPinning}, {});
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(&profile));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(nullptr));
}
// Test for Googler account.
{
ScopedFeatureList features;
features.InitWithFeatures({}, {kFeatureManagementDriveFsBulkPinning});
EXPECT_FALSE(IsDriveFsBulkPinningAvailable(nullptr));
EXPECT_FALSE(IsDriveFsBulkPinningAvailable(&profile));
const user_manager::TypedScopedUserManager<ash::FakeChromeUserManager>
user_manager(std::make_unique<ash::FakeChromeUserManager>());
user_manager->AddUser(AccountId::FromUserEmailGaiaId(
"foobar@google.com", GaiaId(FakeGaiaMixin::kEnterpriseUser1GaiaId)));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(nullptr));
EXPECT_TRUE(IsDriveFsBulkPinningAvailable(&profile));
}
}
TEST_F(ProfileRelatedFileSystemUtilTest,
CheckDriveEnabledAndDriveAvailabilityForProfile) {
TestingProfile profile;
PrefService* const prefs = profile.GetPrefs();
DCHECK(prefs);
// Set disable Drive preference to true.
prefs->SetBoolean(prefs::kDisableDrive, true);
// Check kNotAvailableWhenDisableDrivePreferenceSet.
EXPECT_EQ(CheckDriveEnabledAndDriveAvailabilityForProfile(&profile),
DriveAvailability::kNotAvailableWhenDisableDrivePreferenceSet);
// Set disable Drive preference to false.
prefs->SetBoolean(prefs::kDisableDrive, false);
// Check kNotAvailableForUninitialisedLoginState.
EXPECT_EQ(CheckDriveEnabledAndDriveAvailabilityForProfile(&profile),
DriveAvailability::kNotAvailableForUninitialisedLoginState);
// Initialise login state.
ash::LoginState::Initialize();
// Check kNotAvailableForAccountType.
EXPECT_EQ(CheckDriveEnabledAndDriveAvailabilityForProfile(&profile),
DriveAvailability::kNotAvailableForAccountType);
// Login gaia user.
const user_manager::TypedScopedUserManager<ash::FakeChromeUserManager>
user_manager(std::make_unique<ash::FakeChromeUserManager>());
const AccountId account_id(AccountId::FromUserEmailGaiaId(
"foobar@google.com", GaiaId(FakeGaiaMixin::kEnterpriseUser1GaiaId)));
user_manager->AddUser(account_id);
user_manager->LoginUser(account_id);
ash::ProfileHelper::Get()->SetUserToProfileMappingForTesting(
user_manager->GetPrimaryUser(), &profile);
// Check kAvailable.
EXPECT_EQ(CheckDriveEnabledAndDriveAvailabilityForProfile(&profile),
DriveAvailability::kAvailable);
// Get incognito profile.
Profile* incongnito_profile = profile.GetOffTheRecordProfile(
Profile::OTRProfileID::CreateUniqueForTesting(),
/*create_if_needed=*/true);
// Check kNotAvailableInIncognito.
EXPECT_EQ(CheckDriveEnabledAndDriveAvailabilityForProfile(incongnito_profile),
DriveAvailability::kNotAvailableInIncognito);
}
} // namespace drive::util
|