Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Unified Diff: chrome/browser/chromeos/login/kiosk_browsertest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify a bit. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/kiosk_browsertest.cc
diff --git a/chrome/browser/chromeos/login/kiosk_browsertest.cc b/chrome/browser/chromeos/login/kiosk_browsertest.cc
index 890a1b7f17fad43bc683b178fb587a483f8c27d0..3ced10a24659ed46aceb01cfa9f30436ed79c501 100644
--- a/chrome/browser/chromeos/login/kiosk_browsertest.cc
+++ b/chrome/browser/chromeos/login/kiosk_browsertest.cc
@@ -35,6 +35,8 @@
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
+#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
@@ -42,6 +44,7 @@
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile_impl.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -469,8 +472,10 @@ void CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted() {
class KioskTest : public OobeBaseTest {
public:
- KioskTest() : use_consumer_kiosk_mode_(true),
- fake_cws_(new FakeCWS) {
+ KioskTest()
+ : settings_helper_(false),
+ use_consumer_kiosk_mode_(true),
+ fake_cws_(new FakeCWS) {
set_exit_when_last_browser_closes(false);
}
@@ -500,9 +505,13 @@ class KioskTest : public OobeBaseTest {
// Needed to avoid showing Gaia screen instead of owner signin for
// consumer network down test cases.
StartupUtils::MarkDeviceRegistered(base::Closure());
+ settings_helper_.ReplaceProvider(kAccountsPrefDeviceLocalAccounts);
+ owner_settings_service_.reset(settings_helper_.CreateOwnerSettingsService(
+ ProfileManager::GetPrimaryUserProfile()));
}
void TearDownOnMainThread() override {
+ settings_helper_.RestoreProvider();
AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
AppLaunchSigninScreen::SetUserManagerForTesting(NULL);
@@ -530,8 +539,9 @@ class KioskTest : public OobeBaseTest {
SetupTestAppUpdateCheck();
// Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires.
- KioskAppManager::Get()->RemoveApp(test_app_id_);
- KioskAppManager::Get()->AddApp(test_app_id_);
+ KioskAppManager::Get()->RemoveApp(test_app_id_,
+ owner_settings_service_.get());
+ KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
}
void FireKioskAppSettingsChanged() {
@@ -548,8 +558,9 @@ class KioskTest : public OobeBaseTest {
void ReloadAutolaunchKioskApps() {
SetupTestAppUpdateCheck();
- KioskAppManager::Get()->AddApp(test_app_id_);
- KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_);
+ KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
+ KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_,
+ owner_settings_service_.get());
}
void StartUIForAppLaunch() {
@@ -793,6 +804,9 @@ class KioskTest : public OobeBaseTest {
use_consumer_kiosk_mode_ = use;
}
+ ScopedCrosSettingsTestHelper settings_helper_;
+ scoped_ptr<FakeOwnerSettingsService> owner_settings_service_;
+
private:
bool use_consumer_kiosk_mode_;
std::string test_app_id_;
@@ -1207,6 +1221,8 @@ IN_PROC_BROWSER_TEST_F(KioskTest, DoNotLaunchWhenUntrusted) {
SimulateNetworkOnline();
// Make cros settings untrusted.
+ settings_helper_.SetTrustedStatus(
+ CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
CrosSettingsPermanentlyUntrustedMaker();
// Check that the attempt to start a kiosk app fails with an error.
@@ -1246,6 +1262,8 @@ IN_PROC_BROWSER_TEST_F(KioskTest, NoConsumerAutoLaunchWhenUntrusted) {
base::FundamentalValue(true));
// Make cros settings untrusted.
+ settings_helper_.SetTrustedStatus(
+ CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
CrosSettingsPermanentlyUntrustedMaker();
// Check that the attempt to auto-launch a kiosk app fails with an error.
@@ -1259,6 +1277,8 @@ IN_PROC_BROWSER_TEST_F(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) {
SimulateNetworkOnline();
// Make cros settings untrusted.
+ settings_helper_.SetTrustedStatus(
+ CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
CrosSettingsPermanentlyUntrustedMaker();
// Trigger the code that handles auto-launch on enterprise devices. This would
@@ -1291,7 +1311,15 @@ class KioskUpdateTest : public KioskTest {
KioskTest::TearDown();
}
- void SetUpOnMainThread() override { KioskTest::SetUpOnMainThread(); }
+ void SetUpOnMainThread() override {
+ settings_helper_.CopyStoredValue(kAccountsPrefDeviceLocalAccounts);
+ KioskTest::SetUpOnMainThread();
+ }
+
+ void TearDownOnMainThread() override {
+ settings_helper_.StoreDeviceSetting(kAccountsPrefDeviceLocalAccounts);
+ KioskTest::TearDownOnMainThread();
+ }
void PreCacheApp(const std::string& app_id,
const std::string& version,
@@ -1735,6 +1763,7 @@ class KioskEnterpriseTest : public KioskTest {
void SetUpInProcessBrowserTestFixture() override {
device_policy_test_helper_.MarkAsEnterpriseOwned();
device_policy_test_helper_.InstallOwnerKey();
+ settings_helper_.SetCurrentUserIsOwner(false);
KioskTest::SetUpInProcessBrowserTestFixture();
}
@@ -1785,30 +1814,17 @@ class KioskEnterpriseTest : public KioskTest {
void ConfigureKioskAppInPolicy(const std::string& account_id,
const std::string& app_id,
const std::string& update_url) {
- em::DeviceLocalAccountsProto* accounts =
- device_policy_test_helper_.device_policy()->payload()
- .mutable_device_local_accounts();
- em::DeviceLocalAccountInfoProto* account = accounts->add_account();
- account->set_account_id(account_id);
- account->set_type(
- em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP);
- account->mutable_kiosk_app()->set_app_id(app_id);
- if (!update_url.empty())
- account->mutable_kiosk_app()->set_update_url(update_url);
- accounts->set_auto_login_id(account_id);
- em::PolicyData& policy_data =
- device_policy_test_helper_.device_policy()->policy_data();
- policy_data.set_service_account_identity(kTestEnterpriseServiceAccountId);
- device_policy_test_helper_.device_policy()->Build();
-
- base::RunLoop run_loop;
- DBusThreadManager::Get()->GetSessionManagerClient()->StoreDevicePolicy(
- device_policy_test_helper_.device_policy()->GetBlob(),
- base::Bind(&KioskEnterpriseTest::StorePolicyCallback,
- run_loop.QuitClosure()));
- run_loop.Run();
-
- DeviceSettingsService::Get()->Load();
+ settings_helper_.SetCurrentUserIsOwner(true);
+ std::vector<policy::DeviceLocalAccount> accounts;
+ accounts.push_back(
+ policy::DeviceLocalAccount(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
+ account_id, app_id, update_url));
+ policy::SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
+ settings_helper_.SetString(kAccountsPrefDeviceLocalAccountAutoLoginId,
+ account_id);
+ settings_helper_.SetString(kServiceAccountIdentity,
+ kTestEnterpriseServiceAccountId);
+ settings_helper_.SetCurrentUserIsOwner(false);
}
policy::DevicePolicyCrosTestHelper device_policy_test_helper_;
Mattias Nissler (ping if slow) 2015/04/07 12:59:18 It doesn't make sense for a test to have both your
Ivan Podogov 2015/04/07 14:14:48 Had to leave it here for now (though moved it out

Powered by Google App Engine
This is Rietveld 408576698