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

Unified Diff: chrome/browser/chromeos/login/screens/device_disabled_screen_unittest.cc

Issue 676773002: Add device disabling to OOBE flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update browser tests. Created 6 years, 2 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/screens/device_disabled_screen_unittest.cc
diff --git a/chrome/browser/chromeos/login/screens/device_disabled_screen_unittest.cc b/chrome/browser/chromeos/login/screens/device_disabled_screen_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bbe2a33c91c0125eb7eb9248af977a36da9fb129
--- /dev/null
+++ b/chrome/browser/chromeos/login/screens/device_disabled_screen_unittest.cc
@@ -0,0 +1,214 @@
+// Copyright 2014 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/login/screens/device_disabled_screen.h"
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/prefs/scoped_user_pref_update.h"
+#include "base/prefs/testing_pref_service.h"
+#include "chrome/browser/browser_process_platform_part.h"
+#include "chrome/browser/chromeos/login/screens/mock_device_disabled_screen_actor.h"
+#include "chrome/browser/chromeos/login/screens/screen_observer.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
+#include "chrome/browser/chromeos/policy/server_backed_device_state.h"
+#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chromeos/chromeos_switches.h"
+#include "components/policy/core/common/cloud/cloud_policy_constants.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+
+namespace chromeos {
+
+namespace {
+
+const char kDisabledMessage[] = "Device disabled.";
+
+}
+
+class DeviceDisabledScreenTest : public testing::Test, public ScreenObserver {
+ public:
+ DeviceDisabledScreenTest();
+ ~DeviceDisabledScreenTest() override;
+
+ // testing::Test:
+ void SetUp() override;
+ void TearDown() override;
+
+ // ScreenObserver:
+ MOCK_METHOD1(OnExit, void(ExitCodes));
+ void ShowCurrentScreen() override;
+ void OnSetUserNamePassword(const std::string& username,
+ const std::string& password) override;
+ void SetUsageStatisticsReporting(bool val) override;
+ bool GetUsageStatisticsReporting() const override;
+ void SetHostConfiguration() override;
+ void ConfigureHost(bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) override;
+ ErrorScreen* GetErrorScreen() override;
+ void ShowErrorScreen() override;
+ void HideErrorScreen(BaseScreen* parent_screen) override;
+
+ void SetDeviceDisabled(bool disabled);
+ void SetDeviceMode(policy::DeviceMode device_mode);
+
+ void ExpectScreenToNotShow();
+ void ExpectScreenToShow();
+
+ void TryToShowScreen();
+
+ private:
+ scoped_ptr<DeviceDisabledScreen> screen_;
+ scoped_ptr<MockDeviceDisabledScreenActor> actor_;
+ TestingPrefServiceSimple local_state_;
+ policy::ScopedStubEnterpriseInstallAttributes install_attributes_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceDisabledScreenTest);
+};
+
+DeviceDisabledScreenTest::DeviceDisabledScreenTest()
+ : install_attributes_("", "", "", policy::DEVICE_MODE_NOT_SET) {
+}
+
+DeviceDisabledScreenTest::~DeviceDisabledScreenTest() {
+}
+
+void DeviceDisabledScreenTest::SetUp() {
+ TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
+ policy::DeviceCloudPolicyManagerChromeOS::RegisterPrefs(
+ local_state_.registry());
+
+ actor_.reset(new MockDeviceDisabledScreenActor);
+ screen_.reset(new DeviceDisabledScreen(this, actor_.get()));
+}
+
+void DeviceDisabledScreenTest::TearDown() {
+ TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
+}
+
+void DeviceDisabledScreenTest::ShowCurrentScreen() {
+}
+
+void DeviceDisabledScreenTest::OnSetUserNamePassword(
+ const std::string& username,
+ const std::string& password) {
+}
+
+void DeviceDisabledScreenTest::SetUsageStatisticsReporting(bool val) {
+}
+
+bool DeviceDisabledScreenTest::GetUsageStatisticsReporting() const {
+ return false;
+}
+
+void DeviceDisabledScreenTest::SetHostConfiguration() {
+}
+
+void DeviceDisabledScreenTest::ConfigureHost(
+ bool accepted_eula,
+ const std::string& lang,
+ const std::string& timezone,
+ bool send_reports,
+ const std::string& keyboard_layout) {
+}
+
+ErrorScreen* DeviceDisabledScreenTest::GetErrorScreen() {
+ return nullptr;
+}
+
+void DeviceDisabledScreenTest::ShowErrorScreen() {
+}
+
+void DeviceDisabledScreenTest::HideErrorScreen(BaseScreen* parent_screen) {
+}
+
+void DeviceDisabledScreenTest::SetDeviceDisabled(bool disabled) {
+ DictionaryPrefUpdate dict(&local_state_, prefs::kServerBackedDeviceState);
+ dict->SetBoolean(policy::kDeviceStateDisabled, disabled);
+ if (disabled)
+ dict->SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage);
+}
+
+void DeviceDisabledScreenTest::SetDeviceMode(policy::DeviceMode device_mode) {
+ reinterpret_cast<policy::StubEnterpriseInstallAttributes*>(
+ TestingBrowserProcess::GetGlobal()->platform_part()->
+ browser_policy_connector_chromeos()->GetInstallAttributes())->
+ SetMode(device_mode);
+}
+
+void DeviceDisabledScreenTest::ExpectScreenToNotShow() {
+ EXPECT_CALL(*actor_, Show(_)).Times(0);
+ EXPECT_CALL(*this, OnExit(ScreenObserver::DEVICE_NOT_DISABLED)).Times(1);
+}
+
+void DeviceDisabledScreenTest::ExpectScreenToShow() {
+ EXPECT_CALL(*actor_, Show(kDisabledMessage)).Times(1);
+ EXPECT_CALL(*this, OnExit(ScreenObserver::DEVICE_NOT_DISABLED)).Times(0);
+}
+
+void DeviceDisabledScreenTest::TryToShowScreen() {
+ screen_->Show();
+}
+
+// Verifies that the device disabled screen is not shown by default.
+TEST_F(DeviceDisabledScreenTest, DoNotShowByDefault) {
+ ExpectScreenToNotShow();
+ TryToShowScreen();
+}
+
+// Verifies that the device disabled screen is not shown when the device is
+// explicitly marked as not disabled.
+TEST_F(DeviceDisabledScreenTest, DoNotShowWhenNotDisabled) {
+ SetDeviceDisabled(false);
+ ExpectScreenToNotShow();
+ TryToShowScreen();
+}
+
+// Verifies that the device disabled screen is not shown when device disabling
+// is turned off by flag, even if the device is marked as disabled.
+TEST_F(DeviceDisabledScreenTest, DoNotShowWhenTurnedOffByFlag) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kDisableDeviceDisabling);
+ SetDeviceDisabled(true);
+ ExpectScreenToNotShow();
+ TryToShowScreen();
+}
+
+// Verifies that the device disabled screen is not shown when the device is
+// already enrolled, even if the device is marked as disabled.
+TEST_F(DeviceDisabledScreenTest, DoNotShowWhenEnterpriseOwned) {
+ SetDeviceMode(policy::DEVICE_MODE_ENTERPRISE);
+ SetDeviceDisabled(true);
+ ExpectScreenToNotShow();
+ TryToShowScreen();
+}
+
+// Verifies that the device disabled screen is not shown when the device is
+// already owned by a consumer, even if the device is marked as disabled.
+TEST_F(DeviceDisabledScreenTest, DoNotShowWhenConsumerOwned) {
+ SetDeviceMode(policy::DEVICE_MODE_CONSUMER);
+ SetDeviceDisabled(true);
+ ExpectScreenToNotShow();
+ TryToShowScreen();
+}
+
+// Verifies that the device disabled screen is shown when the device is marked
+// as disabled, device disabling is not turned off by flag and the device is not
+// owned yet.
+TEST_F(DeviceDisabledScreenTest, ShowWhenDisabledAndNotOwned) {
+ SetDeviceDisabled(true);
+ ExpectScreenToShow();
+ TryToShowScreen();
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698