| Index: chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler_unittest.cc
|
| diff --git a/chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler_unittest.cc b/chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..154e8dd501fb44a434c93a2cb04ca9d4bdb04f91
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler_unittest.cc
|
| @@ -0,0 +1,151 @@
|
| +// 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 "chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/threading/sequenced_worker_pool.h"
|
| +#include "chrome/browser/chromeos/arc/arc_auth_notification.h"
|
| +#include "chrome/browser/chromeos/arc/arc_session_manager.h"
|
| +#include "chrome/browser/chromeos/arc/arc_util.h"
|
| +#include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h"
|
| +#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
|
| +#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/fake_session_manager_client.h"
|
| +#include "components/arc/arc_session_runner.h"
|
| +#include "components/arc/arc_util.h"
|
| +#include "components/arc/test/fake_arc_session.h"
|
| +#include "components/sync_preferences/testing_pref_service_syncable.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace arc {
|
| +namespace {
|
| +
|
| +class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test {
|
| + public:
|
| + ArcPlayStoreEnabledPreferenceHandlerTest()
|
| + : user_manager_enabler_(new chromeos::FakeChromeUserManager()) {}
|
| +
|
| + void SetUp() override {
|
| + chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
|
| + base::MakeUnique<chromeos::FakeSessionManagerClient>());
|
| + chromeos::DBusThreadManager::Initialize();
|
| +
|
| + SetArcAvailableCommandLineForTesting(
|
| + base::CommandLine::ForCurrentProcess());
|
| + ArcSessionManager::DisableUIForTesting();
|
| + ArcAuthNotification::DisableForTesting();
|
| +
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| + TestingProfile::Builder profile_builder;
|
| + profile_builder.SetProfileName("user@gmail.com");
|
| + profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
|
| + profile_ = profile_builder.Build();
|
| +
|
| + arc_session_manager_ = base::MakeUnique<ArcSessionManager>(
|
| + base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)));
|
| + preference_handler_ =
|
| + base::MakeUnique<ArcPlayStoreEnabledPreferenceHandler>(
|
| + profile_.get(), arc_session_manager_.get());
|
| + const AccountId account_id(AccountId::FromUserEmailGaiaId(
|
| + profile()->GetProfileUserName(), "1234567890"));
|
| + GetFakeUserManager()->AddUser(account_id);
|
| + GetFakeUserManager()->LoginUser(account_id);
|
| + }
|
| +
|
| + void TearDown() override {
|
| + preference_handler_.reset();
|
| + arc_session_manager_.reset();
|
| + profile_.reset();
|
| + chromeos::DBusThreadManager::Shutdown();
|
| + }
|
| +
|
| + TestingProfile* profile() { return profile_.get(); }
|
| + ArcSessionManager* arc_session_manager() {
|
| + return arc_session_manager_.get();
|
| + }
|
| + ArcPlayStoreEnabledPreferenceHandler* preference_handler() {
|
| + return preference_handler_.get();
|
| + }
|
| + chromeos::FakeChromeUserManager* GetFakeUserManager() {
|
| + return static_cast<chromeos::FakeChromeUserManager*>(
|
| + user_manager::UserManager::Get());
|
| + }
|
| +
|
| + private:
|
| + content::TestBrowserThreadBundle thread_bundle_;
|
| + chromeos::ScopedUserManagerEnabler user_manager_enabler_;
|
| + base::ScopedTempDir temp_dir_;
|
| + std::unique_ptr<TestingProfile> profile_;
|
| + std::unique_ptr<ArcSessionManager> arc_session_manager_;
|
| + std::unique_ptr<ArcPlayStoreEnabledPreferenceHandler> preference_handler_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreEnabledPreferenceHandlerTest);
|
| +};
|
| +
|
| +TEST_F(ArcPlayStoreEnabledPreferenceHandlerTest, PrefChangeTriggersService) {
|
| + ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
|
| + arc_session_manager()->SetProfile(profile());
|
| + preference_handler()->Start();
|
| +
|
| + EXPECT_FALSE(
|
| + profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
|
| + EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
|
| +
|
| + SetArcPlayStoreEnabledForProfile(profile(), true);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
|
| + arc_session_manager()->state());
|
| +
|
| + SetArcPlayStoreEnabledForProfile(profile(), false);
|
| +
|
| + ArcDataRemovedWaiter().Wait();
|
| + ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
|
| +}
|
| +
|
| +TEST_F(ArcPlayStoreEnabledPreferenceHandlerTest,
|
| + PrefChangeTriggersService_Restart) {
|
| + // Sets the Google Play Store preference at beginning.
|
| + SetArcPlayStoreEnabledForProfile(profile(), true);
|
| +
|
| + arc_session_manager()->SetProfile(profile());
|
| + preference_handler()->Start();
|
| +
|
| + // Setting profile initiates a code fetching process.
|
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
|
| + arc_session_manager()->state());
|
| +
|
| + content::BrowserThread::GetBlockingPool()->FlushForTesting();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // UI is disabled in unit tests and this code is unchanged.
|
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
|
| + arc_session_manager()->state());
|
| +}
|
| +
|
| +TEST_F(ArcPlayStoreEnabledPreferenceHandlerTest, RemoveDataDir_Managed) {
|
| + // Set ARC to be managed and disabled.
|
| + profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled,
|
| + new base::Value(false));
|
| +
|
| + // Starting session manager with prefs::kArcEnabled off in a managed profile
|
| + // does automatically remove Android's data folder.
|
| + arc_session_manager()->SetProfile(profile());
|
| + preference_handler()->Start();
|
| + EXPECT_TRUE(
|
| + profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace arc
|
|
|