Commit 0a3f5bfd authored by Roger Tawa's avatar Roger Tawa Committed by Commit Bot

Don't enable RLZ until the device is locked.

Change-Id: I51fc5a42dfcd9a67e5e5f7985e53849644002414
Bug: 846033
Reviewed-on: https://chromium-review.googlesource.com/1181930Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Roger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593285}
parent 2721ec4a
......@@ -12,15 +12,21 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/screens/gaia_view.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/settings/stub_install_attributes.h"
#include "chrome/browser/google/google_brand_chromeos.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/system/fake_statistics_provider.h"
#include "chromeos/system/statistics_provider.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/fake_gaia.h"
#include "rlz/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
......@@ -166,4 +172,76 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) {
}
}
#if BUILDFLAG(ENABLE_RLZ)
class ChromeSessionManagerRlzTest : public ChromeSessionManagerTest {
protected:
StubInstallAttributes* stub_install_attributes() {
return scoped_stub_install_attributes_->Get();
}
void StartUserSession() {
// Verify that session state is OOBE and no user sessions in fresh start.
session_manager::SessionManager* manager =
session_manager::SessionManager::Get();
EXPECT_EQ(session_manager::SessionState::OOBE, manager->session_state());
EXPECT_EQ(0u, manager->sessions().size());
// Login via fake gaia to add a new user.
fake_gaia_.SetFakeMergeSessionParams(kTestUsers[0].email, "fake_sid",
"fake_lsid");
StartSignInScreen();
content::WindowedNotificationObserver session_start_waiter(
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
LoginDisplayHost::default_host()
->GetOobeUI()
->GetGaiaScreenView()
->ShowSigninScreenForTest(kTestUsers[0].email, "fake_password", "[]");
session_start_waiter.Wait();
// Verify that session state is ACTIVE with one user session.
EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state());
EXPECT_EQ(1u, manager->sessions().size());
}
private:
void SetUpInProcessBrowserTestFixture() override {
// Set the default brand code to a known value.
scoped_fake_statistics_provider_.reset(
new system::ScopedFakeStatisticsProvider());
scoped_fake_statistics_provider_->SetMachineStatistic(
system::kRlzBrandCodeKey, "TEST");
scoped_stub_install_attributes_ =
std::make_unique<ScopedStubInstallAttributes>(
StubInstallAttributes::CreateUnset());
ChromeSessionManagerTest::SetUpInProcessBrowserTestFixture();
}
std::unique_ptr<system::ScopedFakeStatisticsProvider>
scoped_fake_statistics_provider_;
std::unique_ptr<ScopedStubInstallAttributes> scoped_stub_install_attributes_;
};
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerRlzTest, DeviceIsLocked) {
// When the device is locked, the brand should stick after session start.
stub_install_attributes()->set_device_locked(true);
StartUserSession();
EXPECT_EQ("TEST", google_brand::chromeos::GetBrand());
}
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerRlzTest, DeviceIsUnlocked) {
// When the device is unlocked, the brand should be cleared after session
// start.
stub_install_attributes()->set_device_locked(false);
StartUserSession();
EXPECT_EQ("", google_brand::chromeos::GetBrand());
}
#endif // BUILDFLAG(ENABLE_RLZ)
} // namespace chromeos
......@@ -70,6 +70,7 @@
#include "chrome/browser/chromeos/policy/app_install_event_log_manager_wrapper.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/install_attributes.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/tether/tether_service.h"
#include "chrome/browser/chromeos/tpm_firmware_update_notification.h"
......@@ -1665,8 +1666,9 @@ void UserSessionManager::RestoreAuthSessionImpl(
void UserSessionManager::InitRlzImpl(Profile* profile,
const RlzInitParams& params) {
#if BUILDFLAG(ENABLE_RLZ)
// RLZ is disabled if disabled explicitly or if the device is not yet locked.
PrefService* local_state = g_browser_process->local_state();
if (params.disabled) {
if (params.disabled || !InstallAttributes::Get()->IsDeviceLocked()) {
// Empty brand code means an organic install (no RLZ pings are sent).
google_brand::chromeos::ClearBrandForCurrentSession();
}
......
......@@ -49,6 +49,8 @@ class StubInstallAttributes : public InstallAttributes {
// configuration.
void SetDemoMode(const std::string& device_id);
void set_device_locked(bool is_locked) { device_locked_ = is_locked; }
private:
DISALLOW_COPY_AND_ASSIGN(StubInstallAttributes);
};
......
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