123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614 |
- // Copyright 2017 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ash/components/arc/arc_util.h"
- #include <memory>
- #include <string>
- #include <utility>
- #include <vector>
- #include "ash/components/arc/arc_features.h"
- #include "ash/components/arc/test/arc_util_test_support.h"
- #include "ash/constants/app_types.h"
- #include "base/base_switches.h"
- #include "base/command_line.h"
- #include "base/files/file_util.h"
- #include "base/files/scoped_temp_dir.h"
- #include "base/memory/ptr_util.h"
- #include "base/run_loop.h"
- #include "base/test/bind.h"
- #include "base/test/scoped_feature_list.h"
- #include "chromeos/ash/components/dbus/upstart/fake_upstart_client.h"
- #include "components/account_id/account_id.h"
- #include "components/exo/shell_surface_util.h"
- #include "components/prefs/testing_pref_service.h"
- #include "components/user_manager/fake_user_manager.h"
- #include "components/user_manager/scoped_user_manager.h"
- #include "components/user_manager/user.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "ui/aura/client/aura_constants.h"
- #include "ui/aura/test/test_windows.h"
- #include "ui/aura/window.h"
- #include "ui/display/types/display_constants.h"
- namespace arc {
- namespace {
- // If an instance is created, based on the value passed to the constructor,
- // EnableARC feature is enabled/disabled in the scope.
- class ScopedArcFeature {
- public:
- explicit ScopedArcFeature(bool enabled) {
- constexpr char kArcFeatureName[] = "EnableARC";
- if (enabled) {
- feature_list.InitFromCommandLine(kArcFeatureName, std::string());
- } else {
- feature_list.InitFromCommandLine(std::string(), kArcFeatureName);
- }
- }
- ScopedArcFeature(const ScopedArcFeature&) = delete;
- ScopedArcFeature& operator=(const ScopedArcFeature&) = delete;
- ~ScopedArcFeature() = default;
- private:
- base::test::ScopedFeatureList feature_list;
- };
- class ScopedRtVcpuFeature {
- public:
- ScopedRtVcpuFeature(bool dual_core_enabled, bool quad_core_enabled) {
- std::vector<base::Feature> enabled_features;
- std::vector<base::Feature> disabled_features;
- if (dual_core_enabled)
- enabled_features.push_back(kRtVcpuDualCore);
- else
- disabled_features.push_back(kRtVcpuDualCore);
- if (quad_core_enabled)
- enabled_features.push_back(kRtVcpuQuadCore);
- else
- disabled_features.push_back(kRtVcpuQuadCore);
- feature_list.InitWithFeatures(enabled_features, disabled_features);
- }
- ~ScopedRtVcpuFeature() = default;
- ScopedRtVcpuFeature(const ScopedRtVcpuFeature&) = delete;
- ScopedRtVcpuFeature& operator=(const ScopedRtVcpuFeature&) = delete;
- private:
- base::test::ScopedFeatureList feature_list;
- };
- // Fake user that can be created with a specified type.
- class FakeUser : public user_manager::User {
- public:
- explicit FakeUser(user_manager::UserType user_type)
- : User(AccountId::FromUserEmailGaiaId("user@test.com", "1234567890")),
- user_type_(user_type) {}
- FakeUser(const FakeUser&) = delete;
- FakeUser& operator=(const FakeUser&) = delete;
- ~FakeUser() override = default;
- // user_manager::User:
- user_manager::UserType GetType() const override { return user_type_; }
- private:
- const user_manager::UserType user_type_;
- };
- class ArcUtilTest : public testing::Test {
- public:
- ArcUtilTest() { ash::UpstartClient::InitializeFake(); }
- ArcUtilTest(const ArcUtilTest&) = delete;
- ArcUtilTest& operator=(const ArcUtilTest&) = delete;
- ~ArcUtilTest() override = default;
- void SetUp() override {
- run_loop_ = std::make_unique<base::RunLoop>();
- RemoveUpstartStartStopJobFailures();
- }
- void TearDown() override { run_loop_.reset(); }
- protected:
- void InjectUpstartStartJobFailure(const std::string& job_name_to_fail) {
- auto* upstart_client = ash::FakeUpstartClient::Get();
- upstart_client->set_start_job_cb(base::BindLambdaForTesting(
- [job_name_to_fail](const std::string& job_name,
- const std::vector<std::string>& env) {
- // Return success unless |job_name| is |job_name_to_fail|.
- return job_name != job_name_to_fail;
- }));
- }
- void InjectUpstartStopJobFailure(const std::string& job_name_to_fail) {
- auto* upstart_client = ash::FakeUpstartClient::Get();
- upstart_client->set_stop_job_cb(base::BindLambdaForTesting(
- [job_name_to_fail](const std::string& job_name,
- const std::vector<std::string>& env) {
- // Return success unless |job_name| is |job_name_to_fail|.
- return job_name != job_name_to_fail;
- }));
- }
- void StartRecordingUpstartOperations() {
- auto* upstart_client = ash::FakeUpstartClient::Get();
- upstart_client->set_start_job_cb(
- base::BindLambdaForTesting([this](const std::string& job_name,
- const std::vector<std::string>& env) {
- upstart_operations_.emplace_back(job_name, true);
- return true;
- }));
- upstart_client->set_stop_job_cb(
- base::BindLambdaForTesting([this](const std::string& job_name,
- const std::vector<std::string>& env) {
- upstart_operations_.emplace_back(job_name, false);
- return true;
- }));
- }
- void RecreateRunLoop() { run_loop_ = std::make_unique<base::RunLoop>(); }
- base::RunLoop* run_loop() { return run_loop_.get(); }
- const std::vector<std::pair<std::string, bool>>& upstart_operations() const {
- return upstart_operations_;
- }
- private:
- void RemoveUpstartStartStopJobFailures() {
- auto* upstart_client = ash::FakeUpstartClient::Get();
- upstart_client->set_start_job_cb(
- ash::FakeUpstartClient::StartStopJobCallback());
- upstart_client->set_stop_job_cb(
- ash::FakeUpstartClient::StartStopJobCallback());
- }
- std::unique_ptr<base::RunLoop> run_loop_;
- base::test::TaskEnvironment task_environment_;
- // List of upstart operations recorded. When it's "start" the boolean is set
- // to true.
- std::vector<std::pair<std::string, bool>> upstart_operations_;
- };
- TEST_F(ArcUtilTest, IsArcAvailable_None) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--arc-availability=none"});
- EXPECT_FALSE(IsArcAvailable());
- // If --arc-availability flag is set to "none", even if Finch experiment is
- // turned on, ARC cannot be used.
- {
- ScopedArcFeature feature(true);
- EXPECT_FALSE(IsArcAvailable());
- }
- }
- // Test --arc-available with EnableARC feature combination.
- TEST_F(ArcUtilTest, IsArcAvailable_Installed) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- // If ARC is not installed, IsArcAvailable() should return false,
- // regardless of EnableARC feature.
- command_line->InitFromArgv({""});
- // Not available, by-default.
- EXPECT_FALSE(IsArcAvailable());
- EXPECT_FALSE(IsArcKioskAvailable());
- {
- ScopedArcFeature feature(true);
- EXPECT_FALSE(IsArcAvailable());
- EXPECT_FALSE(IsArcKioskAvailable());
- }
- {
- ScopedArcFeature feature(false);
- EXPECT_FALSE(IsArcAvailable());
- EXPECT_FALSE(IsArcKioskAvailable());
- }
- // If ARC is installed, IsArcAvailable() should return true when EnableARC
- // feature is set.
- command_line->InitFromArgv({"", "--arc-available"});
- // Not available, by-default, too.
- EXPECT_FALSE(IsArcAvailable());
- // ARC is available in kiosk mode if installed.
- EXPECT_TRUE(IsArcKioskAvailable());
- {
- ScopedArcFeature feature(true);
- EXPECT_TRUE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- }
- {
- ScopedArcFeature feature(false);
- EXPECT_FALSE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- }
- // If ARC is installed, IsArcAvailable() should return true when EnableARC
- // feature is set.
- command_line->InitFromArgv({"", "--arc-availability=installed"});
- // Not available, by-default, too.
- EXPECT_FALSE(IsArcAvailable());
- // ARC is available in kiosk mode if installed.
- EXPECT_TRUE(IsArcKioskAvailable());
- {
- ScopedArcFeature feature(true);
- EXPECT_TRUE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- }
- {
- ScopedArcFeature feature(false);
- EXPECT_FALSE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- }
- }
- TEST_F(ArcUtilTest, IsArcAvailable_OfficiallySupported) {
- // Regardless of FeatureList, IsArcAvailable() should return true.
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--enable-arc"});
- EXPECT_TRUE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- command_line->InitFromArgv({"", "--arc-availability=officially-supported"});
- EXPECT_TRUE(IsArcAvailable());
- EXPECT_TRUE(IsArcKioskAvailable());
- }
- TEST_F(ArcUtilTest, IsArcVmEnabled) {
- EXPECT_FALSE(IsArcVmEnabled());
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--enable-arcvm"});
- EXPECT_TRUE(IsArcVmEnabled());
- }
- TEST_F(ArcUtilTest, IsArcVmRtVcpuEnabled) {
- {
- ScopedRtVcpuFeature feature(false, false);
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(2));
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(4));
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(8));
- }
- {
- ScopedRtVcpuFeature feature(true, false);
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(2));
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(4));
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(8));
- }
- {
- ScopedRtVcpuFeature feature(false, true);
- EXPECT_FALSE(IsArcVmRtVcpuEnabled(2));
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(4));
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(8));
- }
- {
- ScopedRtVcpuFeature feature(true, true);
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(2));
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(4));
- EXPECT_TRUE(IsArcVmRtVcpuEnabled(8));
- }
- }
- TEST_F(ArcUtilTest, IsArcVmUseHugePages) {
- EXPECT_FALSE(IsArcVmUseHugePages());
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--arcvm-use-hugepages"});
- EXPECT_TRUE(IsArcVmUseHugePages());
- }
- TEST_F(ArcUtilTest, IsArcVmDevConfIgnored) {
- EXPECT_FALSE(IsArcVmDevConfIgnored());
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--ignore-arcvm-dev-conf"});
- EXPECT_TRUE(IsArcVmDevConfIgnored());
- }
- TEST_F(ArcUtilTest, GetArcVmUreadaheadMode) {
- constexpr char kArcMemProfile4GbName[] = "4G";
- constexpr char kArcMemProfile8GbName[] = "8G";
- auto callback_disabled = base::BindRepeating(&GetSystemMemoryInfoForTesting,
- kArcMemProfile4GbName);
- auto callback_readahead = base::BindRepeating(&GetSystemMemoryInfoForTesting,
- kArcMemProfile8GbName);
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({""});
- EXPECT_EQ(ArcVmUreadaheadMode::READAHEAD,
- GetArcVmUreadaheadMode(callback_readahead));
- command_line->InitFromArgv({"", "--arc-disable-ureadahead"});
- EXPECT_EQ(ArcVmUreadaheadMode::DISABLED,
- GetArcVmUreadaheadMode(callback_readahead));
- EXPECT_EQ(ArcVmUreadaheadMode::DISABLED,
- GetArcVmUreadaheadMode(callback_disabled));
- command_line->InitFromArgv({"", "--arcvm-ureadahead-mode=generate"});
- EXPECT_EQ(ArcVmUreadaheadMode::GENERATE,
- GetArcVmUreadaheadMode(callback_readahead));
- command_line->InitFromArgv({"", "--arcvm-ureadahead-mode=disabled"});
- EXPECT_EQ(ArcVmUreadaheadMode::DISABLED,
- GetArcVmUreadaheadMode(callback_readahead));
- }
- TEST_F(ArcUtilTest, UreadaheadDefault) {
- EXPECT_FALSE(IsUreadaheadDisabled());
- }
- TEST_F(ArcUtilTest, UreadaheadDisabled) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--arc-disable-ureadahead"});
- EXPECT_TRUE(IsUreadaheadDisabled());
- }
- // TODO(hidehiko): Add test for IsArcKioskMode().
- // It depends on UserManager, but a utility to inject fake instance is
- // available only in chrome/. To use it in components/, refactoring is needed.
- TEST_F(ArcUtilTest, IsArcOptInVerificationDisabled) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({""});
- EXPECT_FALSE(IsArcOptInVerificationDisabled());
- command_line->InitFromArgv({"", "--disable-arc-opt-in-verification"});
- EXPECT_TRUE(IsArcOptInVerificationDisabled());
- }
- TEST_F(ArcUtilTest, IsArcAllowedForUser) {
- user_manager::FakeUserManager* fake_user_manager =
- new user_manager::FakeUserManager();
- user_manager::ScopedUserManager scoped_user_manager(
- base::WrapUnique(fake_user_manager));
- TestingPrefServiceSimple local_state;
- fake_user_manager->set_local_state(&local_state);
- struct {
- user_manager::UserType user_type;
- bool expected_allowed;
- } const kTestCases[] = {
- {user_manager::USER_TYPE_REGULAR, true},
- {user_manager::USER_TYPE_GUEST, false},
- {user_manager::USER_TYPE_PUBLIC_ACCOUNT, true},
- {user_manager::USER_TYPE_KIOSK_APP, false},
- {user_manager::USER_TYPE_CHILD, true},
- {user_manager::USER_TYPE_ARC_KIOSK_APP, true},
- {user_manager::USER_TYPE_ACTIVE_DIRECTORY, true},
- };
- for (const auto& test_case : kTestCases) {
- const FakeUser user(test_case.user_type);
- EXPECT_EQ(test_case.expected_allowed, IsArcAllowedForUser(&user))
- << "User type=" << test_case.user_type;
- }
- // An ephemeral user is a logged in user but unknown to UserManager when
- // ephemeral policy is set.
- fake_user_manager->SetEphemeralUsersEnabled(true);
- fake_user_manager->UserLoggedIn(
- AccountId::FromUserEmailGaiaId("test@test.com", "9876543210"),
- "test@test.com-hash", false /* browser_restart */, false /* is_child */);
- const user_manager::User* ephemeral_user = fake_user_manager->GetActiveUser();
- ASSERT_TRUE(ephemeral_user);
- ASSERT_TRUE(fake_user_manager->IsUserCryptohomeDataEphemeral(
- ephemeral_user->GetAccountId()));
- // Ephemeral user is also allowed for ARC.
- EXPECT_TRUE(IsArcAllowedForUser(ephemeral_user));
- }
- TEST_F(ArcUtilTest, ArcStartModeDefault) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--arc-availability=installed"});
- EXPECT_FALSE(ShouldArcAlwaysStart());
- EXPECT_FALSE(ShouldArcAlwaysStartWithNoPlayStore());
- }
- TEST_F(ArcUtilTest, ArcStartModeWithoutPlayStore) {
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv(
- {"", "--arc-availability=installed",
- "--arc-start-mode=always-start-with-no-play-store"});
- EXPECT_TRUE(ShouldArcAlwaysStart());
- EXPECT_TRUE(ShouldArcAlwaysStartWithNoPlayStore());
- }
- // Verifies that ARC manual start is activated by switch.
- TEST_F(ArcUtilTest, ArcStartModeManually) {
- base::CommandLine::ForCurrentProcess()->InitFromArgv(
- {"", "--arc-start-mode=manual"});
- EXPECT_FALSE(ShouldArcAlwaysStart());
- EXPECT_TRUE(ShouldArcStartManually());
- }
- // Verifies that ARC manual start is disabled by default.
- TEST_F(ArcUtilTest, ArcStartModeManuallyDisabledByDefault) {
- EXPECT_FALSE(ShouldArcAlwaysStart());
- EXPECT_FALSE(ShouldArcStartManually());
- }
- TEST_F(ArcUtilTest, ScaleFactorToDensity) {
- // Test all standard scale factors
- EXPECT_EQ(160, GetLcdDensityForDeviceScaleFactor(1.0f));
- EXPECT_EQ(160, GetLcdDensityForDeviceScaleFactor(1.25f));
- EXPECT_EQ(213, GetLcdDensityForDeviceScaleFactor(1.6f));
- EXPECT_EQ(240, GetLcdDensityForDeviceScaleFactor(display::kDsf_1_777));
- EXPECT_EQ(240, GetLcdDensityForDeviceScaleFactor(display::kDsf_1_8));
- EXPECT_EQ(240, GetLcdDensityForDeviceScaleFactor(2.0f));
- EXPECT_EQ(280, GetLcdDensityForDeviceScaleFactor(display::kDsf_2_252));
- EXPECT_EQ(280, GetLcdDensityForDeviceScaleFactor(2.4f));
- EXPECT_EQ(320, GetLcdDensityForDeviceScaleFactor(display::kDsf_2_666));
- // Bad scale factors shouldn't blow up.
- EXPECT_EQ(160, GetLcdDensityForDeviceScaleFactor(0.5f));
- EXPECT_EQ(160, GetLcdDensityForDeviceScaleFactor(-0.1f));
- EXPECT_EQ(180, GetLcdDensityForDeviceScaleFactor(1.5f));
- EXPECT_EQ(1200, GetLcdDensityForDeviceScaleFactor(10.f));
- auto* command_line = base::CommandLine::ForCurrentProcess();
- command_line->InitFromArgv({"", "--arc-scale=280"});
- EXPECT_EQ(280, GetLcdDensityForDeviceScaleFactor(1.234f));
- command_line->InitFromArgv({"", "--arc-scale=120"});
- EXPECT_EQ(120, GetLcdDensityForDeviceScaleFactor(1.234f));
- command_line->InitFromArgv({"", "--arc-scale=abc"});
- EXPECT_EQ(240, GetLcdDensityForDeviceScaleFactor(2.0));
- }
- TEST_F(ArcUtilTest, ConfigureUpstartJobs_Success) {
- std::deque<JobDesc> jobs{
- JobDesc{"Job_2dA", UpstartOperation::JOB_STOP, {}},
- JobDesc{"Job_2dB", UpstartOperation::JOB_STOP_AND_START, {}},
- JobDesc{"Job_2dC", UpstartOperation::JOB_START, {}},
- };
- bool result = false;
- StartRecordingUpstartOperations();
- ConfigureUpstartJobs(jobs,
- base::BindLambdaForTesting([&result, this](bool r) {
- result = r;
- run_loop()->Quit();
- }));
- run_loop()->Run();
- EXPECT_TRUE(result);
- auto ops = upstart_operations();
- ASSERT_EQ(4u, ops.size());
- EXPECT_EQ(ops[0].first, "Job_2dA");
- EXPECT_FALSE(ops[0].second);
- EXPECT_EQ(ops[1].first, "Job_2dB");
- EXPECT_FALSE(ops[1].second);
- EXPECT_EQ(ops[2].first, "Job_2dB");
- EXPECT_TRUE(ops[2].second);
- EXPECT_EQ(ops[3].first, "Job_2dC");
- EXPECT_TRUE(ops[3].second);
- }
- TEST_F(ArcUtilTest, ConfigureUpstartJobs_StopFail) {
- std::deque<JobDesc> jobs{
- JobDesc{"Job_2dA", UpstartOperation::JOB_STOP, {}},
- JobDesc{"Job_2dB", UpstartOperation::JOB_STOP_AND_START, {}},
- JobDesc{"Job_2dC", UpstartOperation::JOB_START, {}},
- };
- // Confirm that failing to stop a job is ignored.
- bool result = false;
- InjectUpstartStopJobFailure("Job_2dA");
- ConfigureUpstartJobs(jobs,
- base::BindLambdaForTesting([&result, this](bool r) {
- result = r;
- run_loop()->Quit();
- }));
- run_loop()->Run();
- EXPECT_TRUE(result);
- // Do the same for the second task.
- RecreateRunLoop();
- result = false;
- InjectUpstartStopJobFailure("Job_2dB");
- ConfigureUpstartJobs(jobs,
- base::BindLambdaForTesting([&result, this](bool r) {
- result = r;
- run_loop()->Quit();
- }));
- run_loop()->Run();
- EXPECT_TRUE(result);
- }
- TEST_F(ArcUtilTest, ConfigureUpstartJobs_StartFail) {
- std::deque<JobDesc> jobs{
- JobDesc{"Job_2dA", UpstartOperation::JOB_STOP, {}},
- JobDesc{"Job_2dB", UpstartOperation::JOB_STOP_AND_START, {}},
- JobDesc{"Job_2dC", UpstartOperation::JOB_START, {}},
- };
- // Confirm that failing to start a job is not ignored.
- bool result = true;
- InjectUpstartStartJobFailure("Job_2dB");
- ConfigureUpstartJobs(jobs,
- base::BindLambdaForTesting([&result, this](bool r) {
- result = r;
- run_loop()->Quit();
- }));
- run_loop()->Run();
- EXPECT_FALSE(result);
- // Do the same for the third task.
- RecreateRunLoop();
- result = true;
- InjectUpstartStartJobFailure("Job_2dC");
- ConfigureUpstartJobs(std::move(jobs),
- base::BindLambdaForTesting([&result, this](bool r) {
- result = r;
- run_loop()->Quit();
- }));
- run_loop()->Run();
- EXPECT_FALSE(result);
- }
- TEST_F(ArcUtilTest, GetArcWindowTaskId) {
- std::unique_ptr<aura::Window> window(
- aura::test::CreateTestWindowWithId(100, nullptr));
- exo::SetShellApplicationId(window.get(), "org.chromium.arc.100");
- {
- auto task_id = GetWindowTaskId(window.get());
- EXPECT_TRUE(task_id.has_value());
- EXPECT_EQ(task_id.value(), 100);
- }
- {
- auto session_id = GetWindowSessionId(window.get());
- EXPECT_FALSE(session_id.has_value());
- }
- {
- auto task_or_session_id = GetWindowTaskOrSessionId(window.get());
- EXPECT_TRUE(task_or_session_id.has_value());
- EXPECT_EQ(task_or_session_id.value(), 100);
- }
- }
- TEST_F(ArcUtilTest, GetArcWindowSessionId) {
- std::unique_ptr<aura::Window> window(
- aura::test::CreateTestWindowWithId(200, nullptr));
- exo::SetShellApplicationId(window.get(), "org.chromium.arc.session.200");
- {
- auto task_id = GetWindowTaskId(window.get());
- EXPECT_FALSE(task_id.has_value());
- }
- {
- auto session_id = GetWindowSessionId(window.get());
- EXPECT_TRUE(session_id.has_value());
- EXPECT_EQ(session_id.value(), 200);
- }
- {
- auto task_or_session_id = GetWindowTaskOrSessionId(window.get());
- EXPECT_TRUE(task_or_session_id.has_value());
- EXPECT_EQ(task_or_session_id.value(), 200);
- }
- }
- } // namespace
- } // namespace arc
|