Commit 4516de02 authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Use PathService to determine demo mode resources path

Updates chromeos::DemoSession to use
chromeos::DIR_PREINSTALLED_COMPONENTS to determine the preinstalled demo
mode resources path.

TEST=existing unittests
BUG=869455

Change-Id: Idd63ae0893b4fa3966d69bb295fbdb0290456bca
Reviewed-on: https://chromium-review.googlesource.com/1180729
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585373}
parent e3a969c8
......@@ -13,15 +13,14 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/scoped_path_override.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/stub_install_attributes.h"
#include "chrome/browser/extensions/external_policy_loader.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cryptohome_client.h"
#include "components/prefs/testing_pref_service.h"
......@@ -67,10 +66,11 @@ class DemoModeResourcesRemoverTest : public testing::Test {
std::move(cryptohome_client));
ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
demo_resources_path_ =
scoped_temp_dir_.GetPath().AppendASCII("demo-mode-resources");
DemoSession::OverridePreInstalledDemoResourcesPathForTesting(
&demo_resources_path_);
components_path_override_ = std::make_unique<base::ScopedPathOverride>(
chromeos::DIR_PREINSTALLED_COMPONENTS, scoped_temp_dir_.GetPath());
demo_resources_path_ = scoped_temp_dir_.GetPath()
.AppendASCII("cros-components")
.AppendASCII("demo-mode-resources");
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
std::make_unique<FakeChromeUserManager>());
......@@ -83,7 +83,6 @@ class DemoModeResourcesRemoverTest : public testing::Test {
void TearDown() override {
DemoSession::ShutDownIfInitialized();
DemoSession::OverridePreInstalledDemoResourcesPathForTesting(nullptr);
DemoSession::SetDemoModeEnrollmentTypeForTesting(
DemoSession::EnrollmentType::kNone);
chromeos::DBusThreadManager::Shutdown();
......@@ -190,6 +189,7 @@ class DemoModeResourcesRemoverTest : public testing::Test {
std::unique_ptr<ScopedStubInstallAttributes> install_attributes_;
base::ScopedTempDir scoped_temp_dir_;
std::unique_ptr<base::ScopedPathOverride> components_path_override_;
base::FilePath demo_resources_path_;
std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_;
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/sys_info.h"
#include "chrome/browser/apps/platform_apps/app_load_service.h"
#include "chrome/browser/browser_process.h"
......@@ -17,6 +18,7 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/settings/install_attributes.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h"
#include "components/session_manager/core/session_manager.h"
......@@ -35,16 +37,6 @@ DemoSession::EnrollmentType g_force_enrollment_type =
// The name of the offline demo resource image loader component.
constexpr char kDemoResourcesComponentName[] = "demo-mode-resources";
// The path from which the offline demo mode resources component should be
// loaded by the image loader service.
constexpr base::FilePath::CharType kPreInstalledDemoResourcesComponentPath[] =
FILE_PATH_LITERAL(
"/mnt/stateful_partition/unencrypted/demo_mode_resources");
// Can be set in test to override location of preinstalled offline resources
// component path.
const base::FilePath* g_pre_installed_demo_resources_path_override = nullptr;
// Path relative to the path at which offline demo resources are loaded that
// contains image with demo Android apps.
constexpr base::FilePath::CharType kDemoAppsPath[] =
......@@ -71,15 +63,11 @@ bool IsDemoModeOfflineEnrolled() {
// static
base::FilePath DemoSession::GetPreInstalledDemoResourcesPath() {
if (g_pre_installed_demo_resources_path_override)
return *g_pre_installed_demo_resources_path_override;
return base::FilePath(kPreInstalledDemoResourcesComponentPath);
}
// static
void DemoSession::OverridePreInstalledDemoResourcesPathForTesting(
base::FilePath* overriden_path) {
g_pre_installed_demo_resources_path_override = overriden_path;
base::FilePath preinstalled_components_root;
base::PathService::Get(DIR_PREINSTALLED_COMPONENTS,
&preinstalled_components_root);
return preinstalled_components_root.AppendASCII("cros-components")
.AppendASCII(kDemoResourcesComponentName);
}
// static
......
......@@ -44,8 +44,6 @@ class DemoSession : public session_manager::SessionManagerObserver {
// Location on disk where pre-installed demo mode resources are expected to be
// found.
static base::FilePath GetPreInstalledDemoResourcesPath();
static void OverridePreInstalledDemoResourcesPathForTesting(
base::FilePath* overriden_path);
// Whether the device is set up to run demo sessions.
static bool IsDeviceInDemoMode();
......
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