chromium/components/user_education/common/tutorial_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/user_education/common/tutorial.h"

#include <optional>
#include <string>
#include <string_view>

#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/task_environment.h"
#include "components/strings/grit/components_strings.h"
#include "components/user_education/common/events.h"
#include "components/user_education/common/help_bubble_factory_registry.h"
#include "components/user_education/common/help_bubble_params.h"
#include "components/user_education/common/tutorial_description.h"
#include "components/user_education/common/tutorial_identifier.h"
#include "components/user_education/common/tutorial_registry.h"
#include "components/user_education/common/tutorial_service.h"
#include "components/user_education/test/test_help_bubble.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_test_util.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/expect_call_in_scope.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/interaction/interaction_sequence_test_util.h"
#include "ui/base/interaction/interactive_test.h"
#include "ui/base/l10n/l10n_util.h"

namespace user_education {

namespace {

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE();

const char kTestElementName1[] =;

const ui::ElementContext kTestContext1(1);

const TutorialIdentifier kTestTutorial1{};
const TutorialIdentifier kTestTutorial2{};
const TutorialIdentifier kTestTutorial3{};

const char kHistogramName1[] =;
const char kHistogramName2[] =;

class TestTutorialService : public TutorialService {};

class ScopedTestTutorialState : public user_education::ScopedTutorialState {};

std::unique_ptr<HelpBubbleFactoryRegistry>
CreateTestTutorialBubbleFactoryRegistry() {}

void ClickDismissButton(HelpBubble* bubble) {}

void ClickCloseButton(HelpBubble* bubble) {}

void ClickNextButton(HelpBubble* bubble) {}

void ClickRestartButton(HelpBubble* bubble) {}

bool HasButtonWithText(HelpBubble* bubble, int message_id) {}

}  // namespace

class TutorialTest : public testing::Test {};

TEST_F(TutorialTest, TutorialBuilder) {}

TEST_F(TutorialTest, RegisterTutorial) {}

TEST_F(TutorialTest, RegisterMultipleTutorials) {}

TEST_F(TutorialTest, RegisterSameTutorialTwice) {}

TEST_F(TutorialTest, RegisterTutorialsWithAndWithoutHistograms) {}

TEST_F(TutorialTest, RegisterSameTutorialInMultipleRegistries) {}

TEST_F(TutorialTest, SingleInteractionTutorialRuns) {}

TEST_F(TutorialTest, MultipleInteractionTutorialRuns) {}

TEST_F(TutorialTest, StartTutorialAbortsExistingTutorial) {}

TEST_F(TutorialTest, StartTutorialCompletesExistingTutorial) {}

TEST_F(TutorialTest, TutorialWithCustomEvent) {}

TEST_F(TutorialTest, TutorialWithNamedElement) {}

TEST_F(TutorialTest, TutorialWithExtendedProperties) {}

TEST_F(TutorialTest, SingleStepRestartTutorial) {}

// Clicks restart tutorial a few times. Then closes the tutorial from the close
// button. Expects to call the restarted callback multiple times.
TEST_F(TutorialTest, SingleStepRestartTutorialCanRestartMultipleTimes) {}

// Starts a tutorial with 3 steps, completes steps, then clicks restart tutorial
// then completes the tutorial again and closes it from the close button.
// Expects to call the completed callback.
TEST_F(TutorialTest, MultiStepRestartTutorialWithCloseOnComplete) {}

// Starts a tutorial with 3 steps, completes steps, then clicks restart tutorial
// then closes the tutorial on the first step. Expects to call the completed
// callback.
TEST_F(TutorialTest, MultiStepRestartTutorialWithDismissAfterRestart) {}

// Starts a tutorial with 3 steps. Completes steps and clicks restart tutorial a
// few times. Then closes the tutorial on the first step. Expects to call the
// restarted callback multiple times.
TEST_F(TutorialTest, MultiStepRestartTutorialCanRestartMultipleTimes) {}

// Verify that when the final bubble of a tutorial is forced to close without
// being dismissed by the user (e.g. because its anchor element disappears, or
// it's programmatically closed) the tutorial ends.
TEST_F(TutorialTest, BubbleClosingProgrammaticallyOnlyEndsTutorialOnLastStep) {}

TEST_F(TutorialTest, TimeoutBeforeFirstBubble) {}

TEST_F(TutorialTest, TimeoutBetweenBubbles) {}

TEST_F(TutorialTest, NoTimeoutIfBubbleShowing) {}

TEST_F(TutorialTest, RegisterTutorialWithCreate) {}

TEST_F(TutorialTest, RegisterTutorialWithCreateFromVector) {}

TEST_F(TutorialTest, SetupTemporaryStateCallback) {}

TEST_F(TutorialTest, CleanupTemporaryStateOnAbort) {}

// Test where the parameter is a bitfield describing choices the test will make
// at each branch.
class ConditionalTutorialTest : public ui::test::InteractiveTestT<TutorialTest>,
                                public testing::WithParamInterface<int> {};

ConditionalTutorialTest1;
INSTANTIATE_TEST_SUITE_P();

TEST_P(ConditionalTutorialTest1, ConditionalAtStartOfTutorial) {}

TEST_P(ConditionalTutorialTest1, ConditionalInMiddleOfTutorial) {}

TEST_P(ConditionalTutorialTest1, ConditionalAtEndOfTutorial) {}

TEST_P(ConditionalTutorialTest1, ConditionalAtEndOfTutorialUnevenSteps) {}

TEST_P(ConditionalTutorialTest1, OptionalStep) {}

TEST_P(ConditionalTutorialTest1, WaitForAnyOf) {}

ConditionalTutorialTest2;
INSTANTIATE_TEST_SUITE_P();

TEST_P(ConditionalTutorialTest2, NestedConditionals) {}

}  // namespace user_education