Commit fe25b3e2 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Do not display error message when token enrollment failed if admin choose to do so

Bug: 904983
Change-Id: I204ff2ba026c4f0b5f24cadc0382051f53d09e14
Reviewed-on: https://chromium-review.googlesource.com/c/1336002Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609343}
parent ce4bc3cb
...@@ -610,33 +610,6 @@ bool IsSiteIsolationEnterprisePolicyApplicable() { ...@@ -610,33 +610,6 @@ bool IsSiteIsolationEnterprisePolicyApplicable() {
#endif #endif
} }
bool WaitUntilMachineLevelUserCloudPolicyEnrollmentFinished(
policy::ChromeBrowserPolicyConnector* connector) {
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
using RegisterResult =
policy::MachineLevelUserCloudPolicyController::RegisterResult;
switch (connector->machine_level_user_cloud_policy_controller()
->WaitUntilPolicyEnrollmentFinished()) {
case RegisterResult::kNoEnrollmentNeeded:
case RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed:
return true;
case RegisterResult::kEnrollmentSuccess:
#if defined(OS_MACOSX)
app_controller_mac::EnterpriseStartupDialogClosed();
#endif
return true;
case RegisterResult::kRestartDueToFailure:
chrome::AttemptRestart();
return false;
case RegisterResult::kQuitDueToFailure:
chrome::AttemptExit();
return false;
}
#else
return true;
#endif
}
// Sets up the ThreadProfiler for the browser process, runs it, and returns the // Sets up the ThreadProfiler for the browser process, runs it, and returns the
// profiler. // profiler.
std::unique_ptr<ThreadProfiler> CreateAndStartBrowserMainThreadProfiler() { std::unique_ptr<ThreadProfiler> CreateAndStartBrowserMainThreadProfiler() {
...@@ -1373,13 +1346,16 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1373,13 +1346,16 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// running. // running.
browser_process_->PreMainMessageLoopRun(); browser_process_->PreMainMessageLoopRun();
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
// Wait for the result of machine level user cloud policy enrollment after // Wait for the result of machine level user cloud policy enrollment after
// we start the enrollment process in browser_porcess_->PreMainMessageLoopRun. // we start the enrollment process in browser_porcess_->PreMainMessageLoopRun.
// Abort the launch process if the enrollment is failed. // Abort the launch process if the enrollment is failed.
if (!WaitUntilMachineLevelUserCloudPolicyEnrollmentFinished( if (!browser_process_->browser_policy_connector()
browser_process_->browser_policy_connector())) { ->machine_level_user_cloud_policy_controller()
->WaitUntilPolicyEnrollmentFinished()) {
return chrome::RESULT_CODE_CLOUD_POLICY_ENROLLMENT_FAILED; return chrome::RESULT_CODE_CLOUD_POLICY_ENROLLMENT_FAILED;
} }
#endif
// Record last shutdown time into a histogram. // Record last shutdown time into a histogram.
browser_shutdown::ReadLastShutdownInfo(); browser_shutdown::ReadLastShutdownInfo();
......
...@@ -73,7 +73,7 @@ class MachineLevelUserCloudPolicyControllerObserver ...@@ -73,7 +73,7 @@ class MachineLevelUserCloudPolicyControllerObserver
: public MachineLevelUserCloudPolicyController::Observer { : public MachineLevelUserCloudPolicyController::Observer {
public: public:
void OnPolicyRegisterFinished(bool succeeded) override { void OnPolicyRegisterFinished(bool succeeded) override {
if (!succeeded) { if (!succeeded && should_display_error_message_) {
EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); EXPECT_EQ(0u, chrome::GetTotalBrowserCount());
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
PostAppControllerNSNotifications(); PostAppControllerNSNotifications();
...@@ -93,11 +93,16 @@ class MachineLevelUserCloudPolicyControllerObserver ...@@ -93,11 +93,16 @@ class MachineLevelUserCloudPolicyControllerObserver
should_succeed_ = should_succeed; should_succeed_ = should_succeed;
} }
void SetShouldDisplayErrorMessage(bool should_display) {
should_display_error_message_ = should_display;
}
bool IsFinished() { return is_finished_; } bool IsFinished() { return is_finished_; }
private: private:
bool is_finished_ = false; bool is_finished_ = false;
bool should_succeed_ = false; bool should_succeed_ = false;
bool should_display_error_message_ = false;
}; };
class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage { class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage {
...@@ -116,11 +121,16 @@ class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage { ...@@ -116,11 +121,16 @@ class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage {
std::move(callback).Run(storage_enabled_); std::move(callback).Run(storage_enabled_);
} }
std::string RetrieveDMToken() override { return dm_token_; } std::string RetrieveDMToken() override { return dm_token_; }
bool ShouldDisplayErrorMessageOnFailure() override { return true; } bool ShouldDisplayErrorMessageOnFailure() override {
return should_display_error_message_on_failure_;
}
void SetEnrollmentToken(const std::string& enrollment_token) { void SetEnrollmentToken(const std::string& enrollment_token) {
enrollment_token_ = enrollment_token; enrollment_token_ = enrollment_token;
} }
void SetErrorMessageOption(bool should_displayed) {
should_display_error_message_on_failure_ = should_displayed;
}
void SetClientId(std::string client_id) { client_id_ = client_id; } void SetClientId(std::string client_id) { client_id_ = client_id; }
...@@ -152,6 +162,7 @@ class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage { ...@@ -152,6 +162,7 @@ class FakeBrowserDMTokenStorage : public BrowserDMTokenStorage {
std::string client_id_; std::string client_id_;
std::string dm_token_; std::string dm_token_;
bool storage_enabled_ = true; bool storage_enabled_ = true;
bool should_display_error_message_on_failure_ = true;
DISALLOW_COPY_AND_ASSIGN(FakeBrowserDMTokenStorage); DISALLOW_COPY_AND_ASSIGN(FakeBrowserDMTokenStorage);
}; };
...@@ -383,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(MachineLevelUserCloudPolicyManagerTest, WithDmToken) { ...@@ -383,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(MachineLevelUserCloudPolicyManagerTest, WithDmToken) {
class MachineLevelUserCloudPolicyEnrollmentTest class MachineLevelUserCloudPolicyEnrollmentTest
: public InProcessBrowserTest, : public InProcessBrowserTest,
public ::testing::WithParamInterface<std::tuple<bool, bool>> { public ::testing::WithParamInterface<std::tuple<bool, bool, bool>> {
public: public:
MachineLevelUserCloudPolicyEnrollmentTest() { MachineLevelUserCloudPolicyEnrollmentTest() {
BrowserDMTokenStorage::SetForTesting(&storage_); BrowserDMTokenStorage::SetForTesting(&storage_);
...@@ -392,8 +403,12 @@ class MachineLevelUserCloudPolicyEnrollmentTest ...@@ -392,8 +403,12 @@ class MachineLevelUserCloudPolicyEnrollmentTest
: kInvalidEnrollmentToken); : kInvalidEnrollmentToken);
storage_.SetClientId("client_id"); storage_.SetClientId("client_id");
storage_.EnableStorage(storage_enabled()); storage_.EnableStorage(storage_enabled());
storage_.SetErrorMessageOption(should_display_error_message());
observer_.SetShouldSucceed(is_enrollment_token_valid()); observer_.SetShouldSucceed(is_enrollment_token_valid());
if (!is_enrollment_token_valid()) { observer_.SetShouldDisplayErrorMessage(should_display_error_message());
if (!is_enrollment_token_valid() && should_display_error_message()) {
set_expected_exit_code( set_expected_exit_code(
chrome::RESULT_CODE_CLOUD_POLICY_ENROLLMENT_FAILED); chrome::RESULT_CODE_CLOUD_POLICY_ENROLLMENT_FAILED);
} }
...@@ -455,6 +470,7 @@ class MachineLevelUserCloudPolicyEnrollmentTest ...@@ -455,6 +470,7 @@ class MachineLevelUserCloudPolicyEnrollmentTest
protected: protected:
bool is_enrollment_token_valid() const { return std::get<0>(GetParam()); } bool is_enrollment_token_valid() const { return std::get<0>(GetParam()); }
bool storage_enabled() const { return std::get<1>(GetParam()); } bool storage_enabled() const { return std::get<1>(GetParam()); }
bool should_display_error_message() const { return std::get<2>(GetParam()); }
base::HistogramTester histogram_tester_; base::HistogramTester histogram_tester_;
...@@ -467,8 +483,9 @@ class MachineLevelUserCloudPolicyEnrollmentTest ...@@ -467,8 +483,9 @@ class MachineLevelUserCloudPolicyEnrollmentTest
}; };
IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) { IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) {
// Test body is ran only if enrollment is succeeded. // Test body is run only if enrollment is succeeded or failed without error
EXPECT_TRUE(is_enrollment_token_valid()); // message.
EXPECT_TRUE(is_enrollment_token_valid() || !should_display_error_message());
EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
...@@ -485,6 +502,7 @@ IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) { ...@@ -485,6 +502,7 @@ IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) {
INSTANTIATE_TEST_CASE_P(, INSTANTIATE_TEST_CASE_P(,
MachineLevelUserCloudPolicyEnrollmentTest, MachineLevelUserCloudPolicyEnrollmentTest,
::testing::Combine(::testing::Bool(), ::testing::Combine(::testing::Bool(),
::testing::Bool(),
::testing::Bool())); ::testing::Bool()));
} // namespace policy } // namespace policy
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/policy/browser_dm_token_storage.h" #include "chrome/browser/policy/browser_dm_token_storage.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h" #include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/policy/cloud/machine_level_user_cloud_policy_helper.h" #include "chrome/browser/policy/cloud/machine_level_user_cloud_policy_helper.h"
...@@ -38,6 +39,10 @@ ...@@ -38,6 +39,10 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#endif #endif
#if defined(OS_MACOSX)
#include "chrome/browser/app_controller_mac.h"
#endif
namespace policy { namespace policy {
namespace { namespace {
...@@ -194,12 +199,30 @@ void MachineLevelUserCloudPolicyController::Init( ...@@ -194,12 +199,30 @@ void MachineLevelUserCloudPolicyController::Init(
} }
} }
MachineLevelUserCloudPolicyController::RegisterResult bool MachineLevelUserCloudPolicyController::
MachineLevelUserCloudPolicyController::WaitUntilPolicyEnrollmentFinished() { WaitUntilPolicyEnrollmentFinished() {
if (policy_register_watcher_) { if (policy_register_watcher_) {
return policy_register_watcher_->WaitUntilCloudPolicyEnrollmentFinished(); switch (
policy_register_watcher_->WaitUntilCloudPolicyEnrollmentFinished()) {
case RegisterResult::kNoEnrollmentNeeded:
case RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed:
case RegisterResult::kEnrollmentFailedSilentlyBeforeDialogDisplayed:
return true;
case RegisterResult::kEnrollmentSuccess:
case RegisterResult::kEnrollmentFailedSilently:
#if defined(OS_MACOSX)
app_controller_mac::EnterpriseStartupDialogClosed();
#endif
return true;
case RegisterResult::kRestartDueToFailure:
chrome::AttemptRestart();
return false;
case RegisterResult::kQuitDueToFailure:
chrome::AttemptExit();
return false;
}
} }
return RegisterResult::kNoEnrollmentNeeded; return true;
} }
void MachineLevelUserCloudPolicyController::AddObserver(Observer* observer) { void MachineLevelUserCloudPolicyController::AddObserver(Observer* observer) {
......
...@@ -40,6 +40,13 @@ class MachineLevelUserCloudPolicyController { ...@@ -40,6 +40,13 @@ class MachineLevelUserCloudPolicyController {
kQuitDueToFailure, // The enrollment has failed or aborted, user choose to kQuitDueToFailure, // The enrollment has failed or aborted, user choose to
// quit Chrome. // quit Chrome.
kRestartDueToFailure, // The enrollment has failed, user choose to restart kRestartDueToFailure, // The enrollment has failed, user choose to restart
kEnrollmentFailedSilently, // The enrollment has failed, admin choose to
// ignore the error message.
kEnrollmentFailedSilentlyBeforeDialogDisplayed, // The enrollment has
// failed before dialog
// displayed, admin choose
// to ignore the error
// message.
}; };
class Observer { class Observer {
...@@ -63,7 +70,7 @@ class MachineLevelUserCloudPolicyController { ...@@ -63,7 +70,7 @@ class MachineLevelUserCloudPolicyController {
void Init(PrefService* local_state, void Init(PrefService* local_state,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
RegisterResult WaitUntilPolicyEnrollmentFinished(); bool WaitUntilPolicyEnrollmentFinished();
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
......
...@@ -38,14 +38,12 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher:: ...@@ -38,14 +38,12 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher::
WaitUntilCloudPolicyEnrollmentFinished() { WaitUntilCloudPolicyEnrollmentFinished() {
BrowserDMTokenStorage* token_storage = BrowserDMTokenStorage::Get(); BrowserDMTokenStorage* token_storage = BrowserDMTokenStorage::Get();
if (token_storage->RetrieveEnrollmentToken().empty()) { if (token_storage->RetrieveEnrollmentToken().empty())
return RegisterResult::kNoEnrollmentNeeded; return RegisterResult::kNoEnrollmentNeeded;
}
// We are already enrolled successfully. // We are already enrolled successfully.
if (!token_storage->RetrieveDMToken().empty()) { if (!token_storage->RetrieveDMToken().empty())
return RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed; return RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed;
}
EnterpriseStartupDialog::DialogResultCallback callback = base::BindOnce( EnterpriseStartupDialog::DialogResultCallback callback = base::BindOnce(
&MachineLevelUserCloudPolicyRegisterWatcher::OnDialogClosed, &MachineLevelUserCloudPolicyRegisterWatcher::OnDialogClosed,
...@@ -56,27 +54,38 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher:: ...@@ -56,27 +54,38 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher::
dialog_ = EnterpriseStartupDialog::CreateAndShowDialog(std::move(callback)); dialog_ = EnterpriseStartupDialog::CreateAndShowDialog(std::move(callback));
visible_start_time_ = base::Time::Now(); visible_start_time_ = base::Time::Now();
RecordEnrollmentStartDialog(EnrollmentStartupDialog::kShown);
if (register_result_) { if (register_result_) {
// |register_result_| has been set only if the enrollment has finihsed. // |register_result_| has been set only if the enrollment has finished.
// And it must be failed if it's finished without a DM token which is // And it must be failed if it's finished without a DM token which is
// checked above. Show the error message directly. // checked above. Show the error message directly.
DCHECK(!register_result_.value()); DCHECK(!register_result_.value());
if (!token_storage->ShouldDisplayErrorMessageOnFailure())
return RegisterResult::kEnrollmentFailedSilentlyBeforeDialogDisplayed;
DisplayErrorMessage(); DisplayErrorMessage();
} else { } else {
// Display the loading dialog and wait for the enrollment process. // Display the loading dialog and wait for the enrollment process.
dialog_->DisplayLaunchingInformationWithThrobber(l10n_util::GetStringUTF16( dialog_->DisplayLaunchingInformationWithThrobber(l10n_util::GetStringUTF16(
IDS_ENTERPRISE_STARTUP_CLOUD_POLICY_ENROLLMENT_TOOLTIP)); IDS_ENTERPRISE_STARTUP_CLOUD_POLICY_ENROLLMENT_TOOLTIP));
} }
RecordEnrollmentStartDialog(EnrollmentStartupDialog::kShown);
run_loop_.Run(); run_loop_.Run();
if (register_result_.value_or(false)) if (register_result_.value_or(false))
return RegisterResult::kEnrollmentSuccess; return RegisterResult::kEnrollmentSuccess;
if (!token_storage->ShouldDisplayErrorMessageOnFailure() &&
register_result_) {
SYSLOG(ERROR) << "Machine level user cloud policy enrollment has failed.";
return RegisterResult::kEnrollmentFailedSilently;
}
SYSLOG(ERROR) << "Can not start Chrome as machine level user cloud policy " SYSLOG(ERROR) << "Can not start Chrome as machine level user cloud policy "
"enrollment has failed. Please double check network " "enrollment has failed. Please double check network "
"connection and the status of enrollment token then open " "connection and the status of enrollment token then open "
"Chrome again."; "Chrome again.";
if (is_restart_needed_) if (is_restart_needed_)
return RegisterResult::kRestartDueToFailure; return RegisterResult::kRestartDueToFailure;
return RegisterResult::kQuitDueToFailure; return RegisterResult::kQuitDueToFailure;
...@@ -105,7 +114,8 @@ void MachineLevelUserCloudPolicyRegisterWatcher::OnPolicyRegisterFinished( ...@@ -105,7 +114,8 @@ void MachineLevelUserCloudPolicyRegisterWatcher::OnPolicyRegisterFinished(
// show the error message. If dialog has been closed before enrollment // show the error message. If dialog has been closed before enrollment
// finished, Chrome should already be in the shutdown process. // finished, Chrome should already be in the shutdown process.
if (dialog_ && dialog_->IsShowing()) { if (dialog_ && dialog_->IsShowing()) {
if (register_result_.value()) { if (register_result_.value() ||
!BrowserDMTokenStorage::Get()->ShouldDisplayErrorMessageOnFailure()) {
dialog_.reset(); dialog_.reset();
} else { } else {
DisplayErrorMessage(); DisplayErrorMessage();
...@@ -118,7 +128,12 @@ void MachineLevelUserCloudPolicyRegisterWatcher::OnDialogClosed( ...@@ -118,7 +128,12 @@ void MachineLevelUserCloudPolicyRegisterWatcher::OnDialogClosed(
bool can_show_browser_window) { bool can_show_browser_window) {
if (can_show_browser_window) { if (can_show_browser_window) {
// Chrome startup can continue normally. // Chrome startup can continue normally.
RecordEnrollmentStartDialog(EnrollmentStartupDialog::kClosedSuccess); if (register_result_.value()) {
RecordEnrollmentStartDialog(EnrollmentStartupDialog::kClosedSuccess);
} else {
RecordEnrollmentStartDialog(
EnrollmentStartupDialog::kClosedFailAndIgnore);
}
} else if (is_accepted) { } else if (is_accepted) {
// User chose to restart chrome and try re-enrolling. // User chose to restart chrome and try re-enrolling.
RecordEnrollmentStartDialog(EnrollmentStartupDialog::kClosedRelaunch); RecordEnrollmentStartDialog(EnrollmentStartupDialog::kClosedRelaunch);
......
...@@ -47,14 +47,24 @@ class MachineLevelUserCloudPolicyRegisterWatcher ...@@ -47,14 +47,24 @@ class MachineLevelUserCloudPolicyRegisterWatcher
private: private:
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest, FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentSucceed); EnrollmentSucceed);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentSucceedWithNoErrorMessageSetup);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest, FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedAndQuit); EnrollmentFailedAndQuit);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest, FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedAndRestart); EnrollmentFailedAndRestart);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest, FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentCanceledBeforeFinish); EnrollmentCanceledBeforeFinish);
FRIEND_TEST_ALL_PREFIXES(
MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentCanceledBeforeFinishWithNoErrorMessageSetup);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest, FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedBeforeDialogDisplay); EnrollmentFailedBeforeDialogDisplay);
FRIEND_TEST_ALL_PREFIXES(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedWithoutErrorMessage);
FRIEND_TEST_ALL_PREFIXES(
MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedBeforeDialogDisplayWithoutErrorMessage);
// Enum used with kStartupDialogHistogramName. // Enum used with kStartupDialogHistogramName.
enum class EnrollmentStartupDialog { enum class EnrollmentStartupDialog {
...@@ -77,7 +87,11 @@ class MachineLevelUserCloudPolicyRegisterWatcher ...@@ -77,7 +87,11 @@ class MachineLevelUserCloudPolicyRegisterWatcher
// before the user gave up and closed the dialog. // before the user gave up and closed the dialog.
kClosedAbort = 4, kClosedAbort = 4,
kMaxValue = kClosedAbort, // The dialog was closed automatically because enrollment failed but admin
// choose to ignore the error and show the browser window.
kClosedFailAndIgnore = 5,
kMaxValue = kClosedFailAndIgnore,
}; };
static const char kStartupDialogHistogramName[]; static const char kStartupDialogHistogramName[];
......
...@@ -38,7 +38,9 @@ class FakeDMTokenStorage : public BrowserDMTokenStorage { ...@@ -38,7 +38,9 @@ class FakeDMTokenStorage : public BrowserDMTokenStorage {
std::string RetrieveDMToken() override { return dm_token_; } std::string RetrieveDMToken() override { return dm_token_; }
std::string RetrieveEnrollmentToken() override { return enrollment_token_; } std::string RetrieveEnrollmentToken() override { return enrollment_token_; }
std::string RetrieveClientId() override { return kClientId; } std::string RetrieveClientId() override { return kClientId; }
bool ShouldDisplayErrorMessageOnFailure() override { return true; } bool ShouldDisplayErrorMessageOnFailure() override {
return should_display_error_message_on_failure_;
}
std::string InitClientId() override { std::string InitClientId() override {
NOTREACHED(); NOTREACHED();
...@@ -63,10 +65,14 @@ class FakeDMTokenStorage : public BrowserDMTokenStorage { ...@@ -63,10 +65,14 @@ class FakeDMTokenStorage : public BrowserDMTokenStorage {
void set_enrollment_token(const std::string& enrollment_token) { void set_enrollment_token(const std::string& enrollment_token) {
enrollment_token_ = enrollment_token; enrollment_token_ = enrollment_token;
} }
void set_should_display_error_message_on_failure(bool should_display) {
should_display_error_message_on_failure_ = should_display;
}
private: private:
std::string enrollment_token_; std::string enrollment_token_;
std::string dm_token_; std::string dm_token_;
bool should_display_error_message_on_failure_ = true;
DISALLOW_COPY_AND_ASSIGN(FakeDMTokenStorage); DISALLOW_COPY_AND_ASSIGN(FakeDMTokenStorage);
}; };
...@@ -203,6 +209,32 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, EnrollmentSucceed) { ...@@ -203,6 +209,32 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, EnrollmentSucceed) {
1); 1);
} }
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentSucceedWithNoErrorMessageSetup) {
base::HistogramTester histogram_tester;
EXPECT_CALL(*dialog(), DisplayLaunchingInformationWithThrobber(_));
EXPECT_CALL(*dialog(), IsShowing()).WillOnce(Return(true));
storage()->set_should_display_error_message_on_failure(false);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
&FakeMachineLevelUserCloudPolicyController::FireNotification,
base::Unretained(controller()), true));
EXPECT_EQ(RegisterResult::kEnrollmentSuccess,
watcher()->WaitUntilCloudPolicyEnrollmentFinished());
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kShown,
1);
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kClosedSuccess,
1);
}
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedAndQuit) { EnrollmentFailedAndQuit) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
...@@ -282,6 +314,31 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, ...@@ -282,6 +314,31 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
1); 1);
} }
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentCanceledBeforeFinishWithNoErrorMessageSetup) {
base::HistogramTester histogram_tester;
EXPECT_CALL(*dialog(), DisplayLaunchingInformationWithThrobber(_));
storage()->set_should_display_error_message_on_failure(false);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&MockEnterpriseStartupDialog::UserClickedTheButton,
base::Unretained(dialog()), false));
EXPECT_EQ(RegisterResult::kQuitDueToFailure,
watcher()->WaitUntilCloudPolicyEnrollmentFinished());
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kShown,
1);
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kClosedAbort,
1);
}
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedBeforeDialogDisplay) { EnrollmentFailedBeforeDialogDisplay) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
...@@ -304,4 +361,43 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, ...@@ -304,4 +361,43 @@ TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
1); 1);
} }
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedWithoutErrorMessage) {
base::HistogramTester histogram_tester;
EXPECT_CALL(*dialog(), DisplayLaunchingInformationWithThrobber(_));
EXPECT_CALL(*dialog(), IsShowing()).WillOnce(Return(true));
storage()->set_should_display_error_message_on_failure(false);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
&FakeMachineLevelUserCloudPolicyController::FireNotification,
base::Unretained(controller()), false));
EXPECT_EQ(RegisterResult::kEnrollmentFailedSilently,
watcher()->WaitUntilCloudPolicyEnrollmentFinished());
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kShown,
1);
histogram_tester.ExpectBucketCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
MachineLevelUserCloudPolicyRegisterWatcher::EnrollmentStartupDialog::
kClosedFailAndIgnore,
1);
}
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
EnrollmentFailedBeforeDialogDisplayWithoutErrorMessage) {
base::HistogramTester histogram_tester;
storage()->set_should_display_error_message_on_failure(false);
controller()->FireNotification(false);
EXPECT_EQ(RegisterResult::kEnrollmentFailedSilentlyBeforeDialogDisplayed,
watcher()->WaitUntilCloudPolicyEnrollmentFinished());
histogram_tester.ExpectTotalCount(
MachineLevelUserCloudPolicyRegisterWatcher::kStartupDialogHistogramName,
0);
}
} // namespace policy } // namespace policy
...@@ -31653,6 +31653,7 @@ from previous Chrome versions. ...@@ -31653,6 +31653,7 @@ from previous Chrome versions.
<int value="2" label="ClosedRelaunch"/> <int value="2" label="ClosedRelaunch"/>
<int value="3" label="ClosedFail"/> <int value="3" label="ClosedFail"/>
<int value="4" label="ClosedAbort"/> <int value="4" label="ClosedAbort"/>
<int value="5" label="ClosedFailAndIgnore"/>
</enum> </enum>
<enum name="MachKernReturn"> <enum name="MachKernReturn">
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