Commit bdf32134 authored by Olya Kalitova's avatar Olya Kalitova Committed by Commit Bot

ChromeFeaturesServiceProvider reports whether PluginVm is allowed

Based on: https://chromium-review.googlesource.com/c/chromium/src/+/1607641
This extends plugin_vm::IsPluginVmAllowedForProfile with an
alternative condition for testing and adds the whole check to
ChromeFeaturesServiceProvider so that Chrome OS does the proper
checks for PluginVm.

Adapts all relevant PluginVm tests accordingly.
Currently only PluginVm unit tests rely on PluginVmTestHelper - plan to
change it in the future CLs and file a P3 bug for now.

--gtest_filter="PluginVm*"

Bug: 920999
Test: unit_tests --gtest_filter="PluginVm*" && browser_tests
Change-Id: I0e24186fbf4411de423141dfbf33bf2886b2a357
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624192
Commit-Queue: Olya Kalitova <okalitova@chromium.org>
Reviewed-by: default avatarAlex Oldemeier <aoldemeier@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662596}
parent a5e8bc4e
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -145,10 +146,10 @@ void ChromeFeaturesServiceProvider::IsCrostiniEnabled( ...@@ -145,10 +146,10 @@ void ChromeFeaturesServiceProvider::IsCrostiniEnabled(
void ChromeFeaturesServiceProvider::IsPluginVmEnabled( void ChromeFeaturesServiceProvider::IsPluginVmEnabled(
dbus::MethodCall* method_call, dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) { dbus::ExportedObject::ResponseSender response_sender) {
// TODO(dtor): extend the check to include device capabilities Profile* profile = GetSenderProfile(method_call, response_sender);
// and device/user policies. SendResponse(
SendResponse(method_call, response_sender, method_call, response_sender,
base::FeatureList::IsEnabled(features::kPluginVm)); profile ? plugin_vm::IsPluginVmAllowedForProfile(profile) : false);
} }
void ChromeFeaturesServiceProvider::IsUsbguardEnabled( void ChromeFeaturesServiceProvider::IsUsbguardEnabled(
......
...@@ -48,7 +48,6 @@ const char kHashUppercase[] = ...@@ -48,7 +48,6 @@ const char kHashUppercase[] =
"842841A4C75A55AD050D686F4EA5F77E83AE059877FE9B6946AA63D3D057ED32"; "842841A4C75A55AD050D686F4EA5F77E83AE059877FE9B6946AA63D3D057ED32";
const char kHash2[] = const char kHash2[] =
"02f06421ae27144aacdc598aebcd345a5e2e634405e8578300173628fe1574bd"; "02f06421ae27144aacdc598aebcd345a5e2e634405e8578300173628fe1574bd";
const char kLicenseKey[] = "LICENSE_KEY";
// File size set in test_download_service. // File size set in test_download_service.
const int kDownloadedPluginVmImageSizeInMb = 123456789u / (1024 * 1024); const int kDownloadedPluginVmImageSizeInMb = 123456789u / (1024 * 1024);
...@@ -85,9 +84,8 @@ class PluginVmImageManagerTest : public testing::Test { ...@@ -85,9 +84,8 @@ class PluginVmImageManagerTest : public testing::Test {
} }
protected: protected:
chromeos::MockUserManager user_manager_;
chromeos::ScopedCrosSettingsTestHelper settings_helper_;
content::TestBrowserThreadBundle test_browser_thread_bundle_; content::TestBrowserThreadBundle test_browser_thread_bundle_;
std::unique_ptr<PluginVmTestHelper> plugin_vm_test_helper_;
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
PluginVmImageManager* manager_; PluginVmImageManager* manager_;
download::test::TestDownloadService* download_service_; download::test::TestDownloadService* download_service_;
...@@ -100,6 +98,10 @@ class PluginVmImageManagerTest : public testing::Test { ...@@ -100,6 +98,10 @@ class PluginVmImageManagerTest : public testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir());
CreateProfile(); CreateProfile();
plugin_vm_test_helper_ =
std::make_unique<PluginVmTestHelper>(profile_.get());
plugin_vm_test_helper_->AllowPluginVm();
// Sets new PluginVmImage pref for this test.
SetPluginVmImagePref(kUrl, kHash); SetPluginVmImagePref(kUrl, kHash);
manager_ = PluginVmImageManagerFactory::GetForProfile(profile_.get()); manager_ = PluginVmImageManagerFactory::GetForProfile(profile_.get());
...@@ -113,9 +115,6 @@ class PluginVmImageManagerTest : public testing::Test { ...@@ -113,9 +115,6 @@ class PluginVmImageManagerTest : public testing::Test {
fake_downloaded_plugin_vm_image_archive_ = CreateZipFile(); fake_downloaded_plugin_vm_image_archive_ = CreateZipFile();
SetPluginVmDevicePolicies();
SetUserWithAffiliation();
histogram_tester_ = std::make_unique<base::HistogramTester>(); histogram_tester_ = std::make_unique<base::HistogramTester>();
} }
...@@ -124,21 +123,6 @@ class PluginVmImageManagerTest : public testing::Test { ...@@ -124,21 +123,6 @@ class PluginVmImageManagerTest : public testing::Test {
observer_.reset(); observer_.reset();
} }
void SetPluginVmDevicePolicies() {
settings_helper_.ReplaceDeviceSettingsProviderWithStub();
settings_helper_.SetBoolean(chromeos::kPluginVmAllowed, true);
settings_helper_.SetString(chromeos::kPluginVmLicenseKey, kLicenseKey);
}
void SetUserWithAffiliation() {
const AccountId account_id(
AccountId::FromUserEmailGaiaId(profile_->GetProfileUserName(), "id"));
user_manager_.AddUserWithAffiliationAndType(
account_id, true, user_manager::USER_TYPE_REGULAR);
chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(
user_manager_.GetActiveUser());
}
void SetPluginVmImagePref(std::string url, std::string hash) { void SetPluginVmImagePref(std::string url, std::string hash) {
DictionaryPrefUpdate update(profile_->GetPrefs(), DictionaryPrefUpdate update(profile_->GetPrefs(),
plugin_vm::prefs::kPluginVmImage); plugin_vm::prefs::kPluginVmImage);
...@@ -322,7 +306,8 @@ TEST_F(PluginVmImageManagerTest, VerifyDownloadTest) { ...@@ -322,7 +306,8 @@ TEST_F(PluginVmImageManagerTest, VerifyDownloadTest) {
} }
TEST_F(PluginVmImageManagerTest, CannotStartDownloadIfPluginVmGetsDisabled) { TEST_F(PluginVmImageManagerTest, CannotStartDownloadIfPluginVmGetsDisabled) {
settings_helper_.SetBoolean(chromeos::kPluginVmAllowed, false); profile_->ScopedCrosSettingsTestHelper()->SetBoolean(
chromeos::kPluginVmAllowed, false);
EXPECT_CALL(*observer_, OnDownloadFailed()); EXPECT_CALL(*observer_, OnDownloadFailed());
ProcessImageUntilImporting(); ProcessImageUntilImporting();
} }
......
...@@ -9,15 +9,26 @@ ...@@ -9,15 +9,26 @@
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h" #include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace plugin_vm { namespace plugin_vm {
namespace { namespace {
const char kDiskImageImportCommandUuid[] = "3922722bd7394acf85bf4d5a330d4a47"; const char kDiskImageImportCommandUuid[] = "3922722bd7394acf85bf4d5a330d4a47";
const char kPluginVmLicenseKey[] = "LICENSE_KEY";
const char kPluginVmImageHash[] =
"842841a4c75a55ad050d686f4ea5f77e83ae059877fe9b6946aa63d3d057ed32";
const char kDomain[] = "example.com";
const char kDeviceId[] = "device_id";
const char kPluginVmImageUrl[] = "https://example.com/plugin_vm_image";
} // namespace } // namespace
void SetupConciergeForSuccessfulDiskImageImport( void SetupConciergeForSuccessfulDiskImageImport(
...@@ -66,15 +77,13 @@ void PluginVmTestHelper::SetPolicyRequirementsToAllowPluginVm() { ...@@ -66,15 +77,13 @@ void PluginVmTestHelper::SetPolicyRequirementsToAllowPluginVm() {
testing_profile_->ScopedCrosSettingsTestHelper()->SetBoolean( testing_profile_->ScopedCrosSettingsTestHelper()->SetBoolean(
chromeos::kPluginVmAllowed, true); chromeos::kPluginVmAllowed, true);
testing_profile_->ScopedCrosSettingsTestHelper()->SetString( testing_profile_->ScopedCrosSettingsTestHelper()->SetString(
chromeos::kPluginVmLicenseKey, "LICENSE_KEY"); chromeos::kPluginVmLicenseKey, kPluginVmLicenseKey);
testing_profile_->GetPrefs()->Set(plugin_vm::prefs::kPluginVmImage, DictionaryPrefUpdate update(testing_profile_->GetPrefs(),
*base::JSONReader::ReadDeprecated(R"( plugin_vm::prefs::kPluginVmImage);
{ base::DictionaryValue* plugin_vm_image = update.Get();
"url": "https://example.com/plugin_vm_image", plugin_vm_image->SetKey("url", base::Value(kPluginVmImageUrl));
"hash": "842841a4c75a55ad050d686f4ea5f77e83ae059877fe9b6946aa63d3d057ed32" plugin_vm_image->SetKey("hash", base::Value(kPluginVmImageHash));
}
)"));
} }
void PluginVmTestHelper::SetUserRequirementsToAllowPluginVm() { void PluginVmTestHelper::SetUserRequirementsToAllowPluginVm() {
...@@ -87,10 +96,35 @@ void PluginVmTestHelper::SetUserRequirementsToAllowPluginVm() { ...@@ -87,10 +96,35 @@ void PluginVmTestHelper::SetUserRequirementsToAllowPluginVm() {
user_manager_.GetActiveUser()); user_manager_.GetActiveUser());
} }
void PluginVmTestHelper::EnablePluginVmFeature() {
scoped_feature_list_.InitAndEnableFeature(features::kPluginVm);
}
void PluginVmTestHelper::EnableDevMode() {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kSystemDevMode);
}
void PluginVmTestHelper::EnterpriseEnrollDevice() {
testing_profile_->ScopedCrosSettingsTestHelper()
->InstallAttributes()
->SetCloudManaged(kDomain, kDeviceId);
}
void PluginVmTestHelper::AllowPluginVm() { void PluginVmTestHelper::AllowPluginVm() {
ASSERT_FALSE(IsPluginVmAllowedForProfile(testing_profile_)); ASSERT_FALSE(IsPluginVmAllowedForProfile(testing_profile_));
SetUserRequirementsToAllowPluginVm();
EnablePluginVmFeature();
EnterpriseEnrollDevice();
SetPolicyRequirementsToAllowPluginVm(); SetPolicyRequirementsToAllowPluginVm();
ASSERT_TRUE(IsPluginVmAllowedForProfile(testing_profile_));
}
void PluginVmTestHelper::AllowPluginVmForManualTesting() {
ASSERT_FALSE(IsPluginVmAllowedForProfile(testing_profile_));
SetUserRequirementsToAllowPluginVm(); SetUserRequirementsToAllowPluginVm();
EnablePluginVmFeature();
EnableDevMode();
ASSERT_TRUE(IsPluginVmAllowedForProfile(testing_profile_)); ASSERT_TRUE(IsPluginVmAllowedForProfile(testing_profile_));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_PLUGIN_VM_PLUGIN_VM_TEST_HELPER_H_ #ifndef CHROME_BROWSER_CHROMEOS_PLUGIN_VM_PLUGIN_VM_TEST_HELPER_H_
#define CHROME_BROWSER_CHROMEOS_PLUGIN_VM_PLUGIN_VM_TEST_HELPER_H_ #define CHROME_BROWSER_CHROMEOS_PLUGIN_VM_PLUGIN_VM_TEST_HELPER_H_
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chromeos/dbus/fake_concierge_client.h" #include "chromeos/dbus/fake_concierge_client.h"
...@@ -23,11 +24,19 @@ class PluginVmTestHelper { ...@@ -23,11 +24,19 @@ class PluginVmTestHelper {
void SetPolicyRequirementsToAllowPluginVm(); void SetPolicyRequirementsToAllowPluginVm();
void SetUserRequirementsToAllowPluginVm(); void SetUserRequirementsToAllowPluginVm();
void EnablePluginVmFeature();
void EnableDevMode();
void EnterpriseEnrollDevice();
void AllowPluginVm(); void AllowPluginVm();
// Sets the conditions required by PluginVm to be allowed when device is not
// enterprise enrolled so that manual testing of PluginVm is easier.
void AllowPluginVmForManualTesting();
private: private:
TestingProfile* testing_profile_; TestingProfile* testing_profile_;
chromeos::MockUserManager user_manager_; chromeos::MockUserManager user_manager_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(PluginVmTestHelper); DISALLOW_COPY_AND_ASSIGN(PluginVmTestHelper);
}; };
......
...@@ -7,16 +7,33 @@ ...@@ -7,16 +7,33 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/command_line.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_pref_names.h" #include "chrome/browser/chromeos/plugin_vm/plugin_vm_pref_names.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/common/chrome_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/tpm/install_attributes.h"
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
namespace plugin_vm { namespace plugin_vm {
// For PluginVm to be allowed:
// * Profile should be eligible.
// * PluginVm feature should be enabled.
// If device is not enterprise enrolled:
// * Device should be in a dev mode.
// If device is enterprise enrolled:
// * User should be affiliated.
// * All necessary policies should be set (PluginVmAllowed, PluginVmImage
// and PluginVmLicenseKey).
//
// TODO(okalitova, aoldemeier): PluginVm should be disabled in case of
// non-managed devices once it is launched. Currently this conditions are used
// for making manual tests easier.
bool IsPluginVmAllowedForProfile(const Profile* profile) { bool IsPluginVmAllowedForProfile(const Profile* profile) {
// Check that the profile is eligible. // Check that the profile is eligible.
if (!profile || profile->IsChild() || profile->IsLegacySupervised() || if (!profile || profile->IsChild() || profile->IsLegacySupervised() ||
...@@ -26,6 +43,21 @@ bool IsPluginVmAllowedForProfile(const Profile* profile) { ...@@ -26,6 +43,21 @@ bool IsPluginVmAllowedForProfile(const Profile* profile) {
return false; return false;
} }
// Check that PluginVm feature is enabled.
if (!base::FeatureList::IsEnabled(features::kPluginVm))
return false;
// TODO(okalitova, aoldemeier): Remove once PluginVm is ready to be launched.
// Check for alternative condition for manual testing, i.e. the device is in
// developer mode and the device is not enterprise-enrolled.
if (!chromeos::InstallAttributes::Get()->IsEnterpriseManaged()) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kSystemDevMode)) {
return true;
}
return false;
}
// Check that the user is affiliated. // Check that the user is affiliated.
const user_manager::User* const user = const user_manager::User* const user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile); chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/tpm/stub_install_attributes.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -18,34 +19,51 @@ namespace plugin_vm { ...@@ -18,34 +19,51 @@ namespace plugin_vm {
class PluginVmUtilTest : public testing::Test { class PluginVmUtilTest : public testing::Test {
public: public:
PluginVmUtilTest() : test_helper_(&testing_profile_) {} PluginVmUtilTest() = default;
protected: protected:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
TestingProfile testing_profile_; std::unique_ptr<TestingProfile> testing_profile_;
PluginVmTestHelper test_helper_; std::unique_ptr<PluginVmTestHelper> test_helper_;
void SetUp() override {
testing_profile_ = std::make_unique<TestingProfile>();
test_helper_ = std::make_unique<PluginVmTestHelper>(testing_profile_.get());
}
private: private:
DISALLOW_COPY_AND_ASSIGN(PluginVmUtilTest); DISALLOW_COPY_AND_ASSIGN(PluginVmUtilTest);
}; };
TEST_F(PluginVmUtilTest, TEST_F(PluginVmUtilTest, PluginVmShouldBeAllowedOnceAllConditionsAreMet) {
IsPluginVmAllowedForProfileReturnsTrueOnceAllConditionsAreMet) { EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
EXPECT_FALSE(IsPluginVmAllowedForProfile(&testing_profile_));
test_helper_->AllowPluginVm();
EXPECT_TRUE(IsPluginVmAllowedForProfile(testing_profile_.get()));
}
TEST_F(PluginVmUtilTest, PluginVmShouldNotBeAllowedUnlessAllConditionsAreMet) {
EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
test_helper_->SetUserRequirementsToAllowPluginVm();
EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
test_helper_.AllowPluginVm(); test_helper_->EnablePluginVmFeature();
EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
EXPECT_TRUE(IsPluginVmAllowedForProfile(&testing_profile_)); test_helper_->EnterpriseEnrollDevice();
EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
test_helper_->SetPolicyRequirementsToAllowPluginVm();
EXPECT_TRUE(IsPluginVmAllowedForProfile(testing_profile_.get()));
} }
TEST_F(PluginVmUtilTest, TEST_F(PluginVmUtilTest, PluginVmShouldBeConfiguredOnceAllConditionsAreMet) {
IsPluginVmConfiguredReturnsTrueOnceAllConditionsAreMet) { EXPECT_FALSE(IsPluginVmConfigured(testing_profile_.get()));
EXPECT_FALSE(IsPluginVmConfigured(&testing_profile_));
testing_profile_.GetPrefs()->SetBoolean( testing_profile_->GetPrefs()->SetBoolean(
plugin_vm::prefs::kPluginVmImageExists, true); plugin_vm::prefs::kPluginVmImageExists, true);
EXPECT_TRUE(IsPluginVmConfigured(testing_profile_.get()));
EXPECT_TRUE(IsPluginVmConfigured(&testing_profile_));
} }
TEST_F(PluginVmUtilTest, GetPluginVmLicenseKey) { TEST_F(PluginVmUtilTest, GetPluginVmLicenseKey) {
...@@ -53,9 +71,16 @@ TEST_F(PluginVmUtilTest, GetPluginVmLicenseKey) { ...@@ -53,9 +71,16 @@ TEST_F(PluginVmUtilTest, GetPluginVmLicenseKey) {
EXPECT_EQ(std::string(), GetPluginVmLicenseKey()); EXPECT_EQ(std::string(), GetPluginVmLicenseKey());
const std::string kLicenseKey = "LICENSE_KEY"; const std::string kLicenseKey = "LICENSE_KEY";
testing_profile_.ScopedCrosSettingsTestHelper()->SetString( testing_profile_->ScopedCrosSettingsTestHelper()->SetString(
chromeos::kPluginVmLicenseKey, kLicenseKey); chromeos::kPluginVmLicenseKey, kLicenseKey);
EXPECT_EQ(kLicenseKey, GetPluginVmLicenseKey()); EXPECT_EQ(kLicenseKey, GetPluginVmLicenseKey());
} }
TEST_F(PluginVmUtilTest, PluginVmShouldBeAllowedForManualTesting) {
EXPECT_FALSE(IsPluginVmAllowedForProfile(testing_profile_.get()));
test_helper_->AllowPluginVmForManualTesting();
EXPECT_TRUE(IsPluginVmAllowedForProfile(testing_profile_.get()));
}
} // namespace plugin_vm } // namespace plugin_vm
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_pref_names.h" #include "chrome/browser/chromeos/plugin_vm/plugin_vm_pref_names.h"
...@@ -17,10 +18,12 @@ ...@@ -17,10 +18,12 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_concierge_client.h" #include "chromeos/dbus/fake_concierge_client.h"
#include "chromeos/dbus/fake_debug_daemon_client.h" #include "chromeos/dbus/fake_debug_daemon_client.h"
#include "chromeos/tpm/stub_install_attributes.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/download/public/background_service/download_metadata.h" #include "components/download/public/background_service/download_metadata.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -113,6 +116,8 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest { ...@@ -113,6 +116,8 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest {
chromeos::MockUserManager user_manager_; chromeos::MockUserManager user_manager_;
PluginVmLauncherViewForTesting* view_; PluginVmLauncherViewForTesting* view_;
chromeos::ScopedTestingCrosSettings scoped_testing_cros_settings_; chromeos::ScopedTestingCrosSettings scoped_testing_cros_settings_;
base::test::ScopedFeatureList scoped_feature_list_;
chromeos::ScopedStubInstallAttributes scoped_stub_install_attributes_;
SetupObserver* setup_observer_; SetupObserver* setup_observer_;
bool HasAcceptButton() { bool HasAcceptButton() {
...@@ -123,6 +128,27 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest { ...@@ -123,6 +128,27 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest {
return view_->GetDialogClientView()->cancel_button() != nullptr; return view_->GetDialogClientView()->cancel_button() != nullptr;
} }
protected:
chromeos::FakeConciergeClient* fake_concierge_client_;
void AllowPluginVm() {
EnablePluginVmFeature();
EnterpriseEnrollDevice();
SetUserWithAffiliation();
SetPluginVmDevicePolicies();
// Set correct PluginVmImage preference value.
SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(),
kZipFileHash);
}
void SetPluginVmImagePref(std::string url, std::string hash) {
DictionaryPrefUpdate update(browser()->profile()->GetPrefs(),
plugin_vm::prefs::kPluginVmImage);
base::DictionaryValue* plugin_vm_image = update.Get();
plugin_vm_image->SetKey("url", base::Value(url));
plugin_vm_image->SetKey("hash", base::Value(hash));
}
void CheckSetupNotAllowed() { void CheckSetupNotAllowed() {
EXPECT_FALSE(HasAcceptButton()); EXPECT_FALSE(HasAcceptButton());
EXPECT_TRUE(HasCancelButton()); EXPECT_TRUE(HasCancelButton());
...@@ -151,6 +177,16 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest { ...@@ -151,6 +177,16 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest {
l10n_util::GetStringUTF16(IDS_PLUGIN_VM_LAUNCHER_FINISHED_TITLE)); l10n_util::GetStringUTF16(IDS_PLUGIN_VM_LAUNCHER_FINISHED_TITLE));
} }
private:
void EnablePluginVmFeature() {
scoped_feature_list_.InitAndEnableFeature(features::kPluginVm);
}
void EnterpriseEnrollDevice() {
scoped_stub_install_attributes_.Get()->SetCloudManaged("example.com",
"device_id");
}
void SetPluginVmDevicePolicies() { void SetPluginVmDevicePolicies() {
scoped_testing_cros_settings_.device_settings()->Set( scoped_testing_cros_settings_.device_settings()->Set(
chromeos::kPluginVmAllowed, base::Value(true)); chromeos::kPluginVmAllowed, base::Value(true));
...@@ -167,18 +203,6 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest { ...@@ -167,18 +203,6 @@ class PluginVmLauncherViewBrowserTest : public DialogBrowserTest {
user_manager_.GetActiveUser()); user_manager_.GetActiveUser());
} }
void SetPluginVmImagePref(std::string url, std::string hash) {
DictionaryPrefUpdate update(browser()->profile()->GetPrefs(),
plugin_vm::prefs::kPluginVmImage);
base::DictionaryValue* plugin_vm_image = update.Get();
plugin_vm_image->SetKey("url", base::Value(url));
plugin_vm_image->SetKey("hash", base::Value(hash));
}
protected:
chromeos::FakeConciergeClient* fake_concierge_client_;
private:
DISALLOW_COPY_AND_ASSIGN(PluginVmLauncherViewBrowserTest); DISALLOW_COPY_AND_ASSIGN(PluginVmLauncherViewBrowserTest);
}; };
...@@ -189,11 +213,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, InvokeUi_default) { ...@@ -189,11 +213,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, InvokeUi_default) {
IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
SetupShouldFinishSuccessfully) { SetupShouldFinishSuccessfully) {
SetPluginVmDevicePolicies(); AllowPluginVm();
SetUserWithAffiliation();
plugin_vm::SetupConciergeForSuccessfulDiskImageImport(fake_concierge_client_); plugin_vm::SetupConciergeForSuccessfulDiskImageImport(fake_concierge_client_);
SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(),
kZipFileHash);
ShowUi("default"); ShowUi("default");
EXPECT_NE(nullptr, view_); EXPECT_NE(nullptr, view_);
...@@ -205,8 +226,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, ...@@ -205,8 +226,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
SetupShouldFailAsHashesDoNotMatch) { SetupShouldFailAsHashesDoNotMatch) {
SetPluginVmDevicePolicies(); AllowPluginVm();
SetUserWithAffiliation(); // Reset PluginVmImage hash to non-matching.
SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(), SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(),
kNonMatchingHash); kNonMatchingHash);
...@@ -220,8 +241,7 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, ...@@ -220,8 +241,7 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
SetupShouldFailAsUnzippingFails) { SetupShouldFailAsUnzippingFails) {
SetPluginVmDevicePolicies(); AllowPluginVm();
SetUserWithAffiliation();
SetPluginVmImagePref(embedded_test_server()->GetURL(kJpgFile).spec(), SetPluginVmImagePref(embedded_test_server()->GetURL(kJpgFile).spec(),
kJpgFileHash); kJpgFileHash);
...@@ -235,8 +255,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, ...@@ -235,8 +255,8 @@ IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest, IN_PROC_BROWSER_TEST_F(PluginVmLauncherViewBrowserTest,
CouldRetryAfterFailedSetup) { CouldRetryAfterFailedSetup) {
SetPluginVmDevicePolicies(); AllowPluginVm();
SetUserWithAffiliation(); // Reset PluginVmImage hash to non-matching.
SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(), SetPluginVmImagePref(embedded_test_server()->GetURL(kZipFile).spec(),
kNonMatchingHash); kNonMatchingHash);
......
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