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
|
// Copyright 2024 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/policy/skyvault/policy_utils.h"
#include <tuple>
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace policy::local_user_files {
class LocalUserFilesPolicyUtilsBrowserTest
: public policy::PolicyTest,
public ::testing::WithParamInterface<
std::tuple</*enable_skyvault*/ bool, /*policy_value*/ bool>> {
public:
static std::string ParamToString(
const testing::TestParamInfo<ParamType> info) {
auto [enable_skyvault, policy_value] = info.param;
std::string name =
(enable_skyvault ? "SkyVaultEnabled" : "SkyVaultDisabled");
name += (policy_value ? "PolicyTrue" : "PolicyFalse");
return name;
}
LocalUserFilesPolicyUtilsBrowserTest() {
if (EnableSkyvault()) {
scoped_feature_list_.InitAndEnableFeature(features::kSkyVault);
} else {
scoped_feature_list_.InitAndDisableFeature(features::kSkyVault);
}
}
~LocalUserFilesPolicyUtilsBrowserTest() override = default;
protected:
bool EnableSkyvault() { return std::get<0>(GetParam()); }
bool PolicyValue() { return std::get<1>(GetParam()); }
void SetPolicyValue(bool local_user_files_allowed) {
policy::PolicyMap policies;
policy::PolicyTest::SetPolicy(&policies,
policy::key::kLocalUserFilesAllowed,
base::Value(local_user_files_allowed));
provider_.UpdateChromePolicy(policies);
}
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_P(LocalUserFilesPolicyUtilsBrowserTest, CheckPolicyValue) {
// Before setting the policy, local files should always be allowed.
ASSERT_TRUE(LocalUserFilesAllowed());
// Set the policy.
bool allowed = PolicyValue();
SetPolicyValue(allowed);
if (!EnableSkyvault()) {
// Policy value doesn't matter.
ASSERT_TRUE(LocalUserFilesAllowed());
} else {
ASSERT_EQ(LocalUserFilesAllowed(), allowed);
}
}
INSTANTIATE_TEST_SUITE_P(LocalUserFiles,
LocalUserFilesPolicyUtilsBrowserTest,
testing::Combine(
/*enable_skyvault*/ testing::Bool(),
/*policy_value*/ testing::Bool()),
LocalUserFilesPolicyUtilsBrowserTest::ParamToString);
class DownloadsDestinationUtilsTest : public policy::PolicyTest {
protected:
void SetDownloadsPolicy(const std::string& destination) {
policy::PolicyMap policies;
policy::PolicyTest::SetPolicy(&policies, policy::key::kDownloadDirectory,
base::Value(destination));
provider_.UpdateChromePolicy(policies);
}
};
IN_PROC_BROWSER_TEST_F(DownloadsDestinationUtilsTest, DownloadsDestination) {
EXPECT_EQ(FileSaveDestination::kNotSpecified,
GetDownloadsDestination(browser()->profile()));
SetDownloadsPolicy("");
EXPECT_EQ(FileSaveDestination::kDownloads,
GetDownloadsDestination(browser()->profile()));
SetDownloadsPolicy(kGoogleDrivePolicyVariableName);
EXPECT_EQ(FileSaveDestination::kGoogleDrive,
GetDownloadsDestination(browser()->profile()));
SetDownloadsPolicy(kOneDrivePolicyVariableName);
EXPECT_EQ(FileSaveDestination::kOneDrive,
GetDownloadsDestination(browser()->profile()));
}
class ScreenCaptureDestinationUtilsTest : public policy::PolicyTest {
protected:
void SetScreenCapturePolicy(const std::string& destination) {
policy::PolicyMap policies;
policy::PolicyTest::SetPolicy(&policies,
policy::key::kScreenCaptureLocation,
base::Value(destination));
provider_.UpdateChromePolicy(policies);
}
base::test::ScopedFeatureList scoped_feature_list_{features::kSkyVault};
};
IN_PROC_BROWSER_TEST_F(ScreenCaptureDestinationUtilsTest,
ScreenCaptureDestination) {
EXPECT_EQ(FileSaveDestination::kNotSpecified,
GetScreenCaptureDestination(browser()->profile()));
SetScreenCapturePolicy("");
EXPECT_EQ(FileSaveDestination::kDownloads,
GetScreenCaptureDestination(browser()->profile()));
SetScreenCapturePolicy(kGoogleDrivePolicyVariableName);
EXPECT_EQ(FileSaveDestination::kGoogleDrive,
GetScreenCaptureDestination(browser()->profile()));
SetScreenCapturePolicy(kOneDrivePolicyVariableName);
EXPECT_EQ(FileSaveDestination::kOneDrive,
GetScreenCaptureDestination(browser()->profile()));
}
class DownloadsDestinationUtilsTestWithSkyvault
: public DownloadsDestinationUtilsTest {
protected:
base::test::ScopedFeatureList scoped_feature_list_{features::kSkyVault};
};
IN_PROC_BROWSER_TEST_F(DownloadsDestinationUtilsTestWithSkyvault,
DownloadToTemp) {
EXPECT_EQ(false, DownloadToTemp(browser()->profile()));
SetDownloadsPolicy(kGoogleDrivePolicyVariableName);
EXPECT_EQ(false, DownloadToTemp(browser()->profile()));
SetDownloadsPolicy(kOneDrivePolicyVariableName);
EXPECT_EQ(true, DownloadToTemp(browser()->profile()));
}
} // namespace policy::local_user_files
|