Commit 0380a339 authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

marketing_opt_in_screen: Add browser test and remove toggles by default

Hides marketing opt-in toggles from marketing opt-in screen - seems
weird, but the screen is also used as the final screen in the flow, with
pieces to force shelf navigation buttons in tablet mode.
Marketing opt in toggle implementation is slipping to M-83, so hide the
toggle by default (a follow-up will update the screen UI to address the
white space where the opt-in toggle should be).

Adds browser tests for the screen.

BUG=976949

Change-Id: If4c9db85be2607f99be15c9aef27f7b67fc41367
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083952
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarMatthew Mourgos <mmourgos@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746487}
parent db5cab6e
......@@ -32,6 +32,10 @@ class ASH_EXPORT ShelfTestApi {
views::View* GetHomeButton();
// Whether the shelf has a login shelf gesture handler set up, which would
// imply that swipe from shelf gesture detection is active.
bool HasLoginShelfGestureHandler() const;
// Returns ui information of scrollable shelf for the given state. If |state|
// specifies the scroll distance, the target offset, which is the offset value
// after scrolling by the distance, is also calculated. It is useful if you
......
......@@ -51,6 +51,10 @@ views::View* ShelfTestApi::GetHomeButton() {
return GetShelfWidget()->navigation_widget()->GetHomeButton();
}
bool ShelfTestApi::HasLoginShelfGestureHandler() const {
return GetShelfWidget()->login_shelf_gesture_controller_for_testing();
}
ScrollableShelfInfo ShelfTestApi::GetScrollableShelfInfoForState(
const ScrollableShelfState& state) {
const auto* scrollable_shelf_view = GetScrollableShelfView();
......
......@@ -32,6 +32,11 @@ class MarketingOptInScreen : public BaseScreen,
// ash::ShelfCondif::Observer:
void OnShelfConfigUpdated() override;
void set_exit_callback_for_testing(
const base::RepeatingClosure& exit_callback) {
exit_callback_ = exit_callback;
}
protected:
// BaseScreen:
void ShowImpl() override;
......
// Copyright 2020 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/marketing_opt_in_screen.h"
#include <string>
#include <vector>
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/shelf_test_api.h"
#include "ash/public/cpp/test/shell_test_api.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/login/screen_manager.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/oobe_base_test.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/wizard_controller.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/webui/chromeos/login/marketing_opt_in_screen_handler.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chromeos {
class MarketingOptInScreenTest : public OobeBaseTest {
public:
MarketingOptInScreenTest() {
feature_list_.InitAndEnableFeature(
ash::features::kHideShelfControlsInTabletMode);
}
~MarketingOptInScreenTest() override = default;
// OobeBaseTest:
void SetUpOnMainThread() override {
ash::ShellTestApi().SetTabletModeEnabledForTest(true);
MarketingOptInScreen* marketing_screen = static_cast<MarketingOptInScreen*>(
WizardController::default_controller()->screen_manager()->GetScreen(
MarketingOptInScreenView::kScreenId));
marketing_screen->set_exit_callback_for_testing(base::BindRepeating(
&MarketingOptInScreenTest::HandleScreenExit, base::Unretained(this)));
OobeBaseTest::SetUpOnMainThread();
}
// Shows the gesture navigation screen.
void ShowMarketingOptInScreen() {
WizardController::default_controller()->AdvanceToScreen(
MarketingOptInScreenView::kScreenId);
}
void WaitForScreenExit() {
if (screen_exited_)
return;
base::RunLoop run_loop;
screen_exit_callback_ = run_loop.QuitClosure();
run_loop.Run();
}
void SimulateFlingFromShelf() {
aura::Window* oobe_window = LoginDisplayHost::default_host()
->GetOobeWebContents()
->GetTopLevelNativeWindow();
display::Screen* const screen = display::Screen::GetScreen();
const display::Display display =
screen->GetDisplayNearestWindow(oobe_window);
// Start at the center of the expected shelf bounds.
const int shelf_size = ash::ShelfConfig::Get()->shelf_size();
const gfx::Point start =
gfx::Point(display.bounds().x() + display.bounds().width() / 2,
display.bounds().bottom() - shelf_size / 2);
// Swipe upwards.
const gfx::Point end = start + gfx::Vector2d(0, -shelf_size);
const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(10);
const int kNumScrollSteps = 4;
ui::test::EventGenerator event_generator(oobe_window->GetRootWindow());
event_generator.GestureScrollSequence(start, end, kTimeDelta,
kNumScrollSteps);
}
private:
void HandleScreenExit() {
ASSERT_FALSE(screen_exited_);
screen_exited_ = true;
if (screen_exit_callback_)
std::move(screen_exit_callback_).Run();
}
bool screen_exited_ = false;
base::RepeatingClosure screen_exit_callback_;
base::test::ScopedFeatureList feature_list_;
};
// Tests that marketing opt in toggles are hidden by default (as the command
// line switch to show marketing opt in is not set).
IN_PROC_BROWSER_TEST_F(MarketingOptInScreenTest, MarketingTogglesHidden) {
ShowMarketingOptInScreen();
OobeScreenWaiter(MarketingOptInScreenView::kScreenId).Wait();
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-subtitle"});
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-toggles"});
ash::ShellTestApi().SetTabletModeEnabledForTest(false);
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-subtitle"});
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-toggles"});
ash::ShellTestApi().SetTabletModeEnabledForTest(true);
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-subtitle"});
test::OobeJS().ExpectHiddenPath(
{"marketing-opt-in", "marketing-opt-in-toggles"});
}
// Tests that fling from shelf exits the screen in tablet mode.
IN_PROC_BROWSER_TEST_F(MarketingOptInScreenTest, FlingFromShelfInTabletMode) {
ShowMarketingOptInScreen();
OobeScreenWaiter(MarketingOptInScreenView::kScreenId).Wait();
ASSERT_TRUE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
SimulateFlingFromShelf();
WaitForScreenExit();
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
}
// Tests that fling from shelf is not enabled in tablet mode if shelf
// navigation buttons are forced by the accessibility setting to show the
// buttons.
IN_PROC_BROWSER_TEST_F(MarketingOptInScreenTest,
ShelfButtonsEnabledInTabletMode) {
ShowMarketingOptInScreen();
OobeScreenWaiter(MarketingOptInScreenView::kScreenId).Wait();
ASSERT_TRUE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
// If the setting to always show shelf navigation buttons is enabled, the
// shelf gesture detection should be disabled on the screen, and the user
// should be able to use "next" button to exit the screen.
ProfileManager::GetActiveUserProfile()->GetPrefs()->SetBoolean(
ash::prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled, true);
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
test::OobeJS()
.CreateVisibilityWaiter(
true, {"marketing-opt-in", "marketing-opt-in-next-button"})
->Wait();
test::OobeJS().TapOnPath(
{"marketing-opt-in", "marketing-opt-in-next-button"});
WaitForScreenExit();
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
}
// Tests that login shelf does not have fling handler in clamshell, and that
// the user can exit the screen using a button in the OOBE screen to exit the
// screen.
IN_PROC_BROWSER_TEST_F(MarketingOptInScreenTest,
ExitScreenUsingButtonInClamshell) {
ShowMarketingOptInScreen();
OobeScreenWaiter(MarketingOptInScreenView::kScreenId).Wait();
ash::ShellTestApi().SetTabletModeEnabledForTest(false);
// When not in tablet mode, the shelf gesture detection should be disabled,
// and the user should be able to exit the screen using "next" button in the
// screen.
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
test::OobeJS()
.CreateVisibilityWaiter(
true, {"marketing-opt-in", "marketing-opt-in-next-button"})
->Wait();
test::OobeJS().TapOnPath(
{"marketing-opt-in", "marketing-opt-in-next-button"});
WaitForScreenExit();
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
}
// Tests that enabling tablet mode while on the screen will enable login shelf
// gestures as well.
IN_PROC_BROWSER_TEST_F(MarketingOptInScreenTest,
FlingFromGestureEnabledOnTabletModeEnter) {
ShowMarketingOptInScreen();
OobeScreenWaiter(MarketingOptInScreenView::kScreenId).Wait();
ash::ShellTestApi().SetTabletModeEnabledForTest(false);
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
test::OobeJS()
.CreateVisibilityWaiter(
true, {"marketing-opt-in", "marketing-opt-in-next-button"})
->Wait();
// Enter tablet mode and verify shelf gesture detection gets re-enabled.
ash::ShellTestApi().SetTabletModeEnabledForTest(true);
ASSERT_TRUE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
SimulateFlingFromShelf();
WaitForScreenExit();
EXPECT_FALSE(ash::ShelfTestApi().HasLoginShelfGestureHandler());
}
} // namespace chromeos
......@@ -15,10 +15,12 @@
<hd-iron-icon slot="oobe-icon" icon1x="oobe-32:checkmark"
icon2x="oobe-32:checkmark">
</hd-iron-icon>
<div slot="subtitle">
<div slot="subtitle" id="marketing-opt-in-subtitle"
hidden="[[!marketingOptInEnabled_]]">
[[i18nRecursive(locale, 'marketingOptInScreenSubtitle', 'productName')]]
</div>
<div slot="footer" class="layout vertical">
<div slot="footer" class="layout vertical" id="marketing-opt-in-toggles"
hidden="[[!marketingOptInEnabled_]]">
<div class="marketing-option layout horizontal center">
<hd-iron-icon icon1x="oobe-32:checkmark" icon2x="oobe-64:checkmark">
</hd-iron-icon>
......
......@@ -15,6 +15,20 @@ Polymer({
type: Boolean,
value: true,
},
/**
* Whether the marketing opt in toggles should be shown, which will be the
* case only if marketing opt in feature is enabled.
* When this is false, the screen will only contain UI related to the
* tablet mode gestural navigation settings.
*/
marketingOptInEnabled_: {
type: Boolean,
readOnly: true,
value() {
return loadTimeData.getBoolean('enableMarketingOptIn');
},
},
},
behaviors: [OobeI18nBehavior, OobeDialogHostBehavior, LoginScreenBehavior],
......
......@@ -4,8 +4,10 @@
#include "chrome/browser/ui/webui/chromeos/login/marketing_opt_in_screen_handler.h"
#include "base/command_line.h"
#include "chrome/browser/chromeos/login/screens/marketing_opt_in_screen.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/login/localized_values_builder.h"
namespace chromeos {
......@@ -55,6 +57,14 @@ void MarketingOptInScreenHandler::RegisterMessages() {
&MarketingOptInScreenHandler::HandleAllSet);
}
void MarketingOptInScreenHandler::GetAdditionalParameters(
base::DictionaryValue* parameters) {
parameters->SetBoolean("enableMarketingOptIn",
base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableMarketingOptInScreen));
BaseScreenHandler::GetAdditionalParameters(parameters);
}
void MarketingOptInScreenHandler::HandleAllSet(
bool play_communications_opt_in,
bool tips_communications_opt_in) {
......
......@@ -56,6 +56,7 @@ class MarketingOptInScreenHandler : public BaseScreenHandler,
// BaseScreenHandler:
void Initialize() override;
void RegisterMessages() override;
void GetAdditionalParameters(base::DictionaryValue* parameters) override;
// WebUI event handler.
void HandleAllSet(bool play_communications_opt_in,
......
......@@ -2274,6 +2274,7 @@ if (!is_android) {
"../browser/chromeos/login/screens/fingerprint_setup_browsertest.cc",
"../browser/chromeos/login/screens/gesture_navigation_screen_browsertest.cc",
"../browser/chromeos/login/screens/hid_detection_screen_browsertest.cc",
"../browser/chromeos/login/screens/marketing_opt_in_screen_browsertest.cc",
"../browser/chromeos/login/screens/mock_arc_terms_of_service_screen.cc",
"../browser/chromeos/login/screens/mock_arc_terms_of_service_screen.h",
"../browser/chromeos/login/screens/mock_demo_preferences_screen.cc",
......
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