1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/tabs/glic_actor_task_icon_manager.h"
#include "chrome/browser/actor/actor_keyed_service_fake.h"
#include "chrome/browser/glic/host/host.h"
#include "chrome/browser/glic/test_support/mock_glic_window_controller.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tabs {
using actor::ActorKeyedServiceFake;
using actor::TaskId;
using glic::GlicWindowController;
using glic::Host;
using glic::MockGlicWindowController;
using glic::mojom::CurrentView;
using testing::AllOf;
using testing::Field;
using testing::Values;
class MockTaskIconStateChangeSubscriber {
public:
MOCK_METHOD(void,
OnStateChanged,
(glic::GlicWindowController::State floaty_state,
glic::mojom::CurrentView current_view,
const ActorTaskIconState& actor_task_icon_state));
};
class GlicActorTaskIconManagerTest : public testing::Test {
public:
GlicActorTaskIconManagerTest()
: task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}
// testing::Test:
void SetUp() override {
profile_ = std::make_unique<TestingProfile>();
actor_service_ = std::make_unique<ActorKeyedServiceFake>(profile_.get());
window_controller_ = std::make_unique<MockGlicWindowController>();
host_ = std::make_unique<Host>(profile_.get());
manager_ = std::make_unique<GlicActorTaskIconManager>(
profile_.get(), actor_service_.get(), *window_controller_.get(),
*host_.get());
}
ActorKeyedServiceFake* actor_service() { return actor_service_.get(); }
GlicActorTaskIconManager* manager() { return manager_.get(); }
content::BrowserTaskEnvironment& task_environment() {
return task_environment_;
}
protected:
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<ActorKeyedServiceFake> actor_service_;
std::unique_ptr<MockGlicWindowController> window_controller_;
std::unique_ptr<Host> host_;
std::unique_ptr<GlicActorTaskIconManager> manager_;
};
TEST_F(GlicActorTaskIconManagerTest, DefaultState) {
EXPECT_FALSE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
}
TEST_F(GlicActorTaskIconManagerTest, NoActiveTasks_ReturnDefaultState) {
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kConversation);
EXPECT_FALSE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
}
TEST_F(GlicActorTaskIconManagerTest, CancelledTask_ReturnDefaultText) {
TaskId task_id = actor_service()->CreateTaskForTesting();
actor_service()->StopTask(task_id, /*success=*/false);
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kConversation);
EXPECT_FALSE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
}
TEST_F(GlicActorTaskIconManagerTest,
CompletedTaskAfterExpiry_ReturnDefaultState) {
TaskId task_id = actor_service()->CreateTaskForTesting();
actor_service()->StopTask(task_id, /*success=*/true);
task_environment().FastForwardBy(base::Seconds(
features::kGlicActorUiCompletedTaskExpiryDelaySeconds.Get()));
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kConversation);
EXPECT_FALSE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
}
TEST_F(GlicActorTaskIconManagerTest, SuppressedText_ReturnDefaultText) {
TaskId task_id = actor_service()->CreateTaskForTesting();
actor_service()->StopTask(task_id, /*success=*/true);
// Conversation/Open: show text.
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kConversation);
EXPECT_TRUE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kCompleteTasks);
// Conversation -> Actuation/Open: Hide text.
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kActuation);
EXPECT_TRUE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
// Actuation -> Conversation/Open: Since we've already been on the actuation
// view we continue to clear the text.
manager()->UpdateTaskIcon(GlicWindowController::State::kOpen,
CurrentView::kConversation);
EXPECT_TRUE(manager()->GetCurrentActorTaskIconState().is_visible);
EXPECT_EQ(manager()->GetCurrentActorTaskIconState().text,
ActorTaskIconState::Text::kDefault);
}
class GlicActorTaskIconManagerPausedTasksTest
: public GlicActorTaskIconManagerTest,
public testing::WithParamInterface<std::tuple<GlicWindowController::State,
CurrentView,
ActorTaskIconState::Text>> {
public:
// testing::Test:
void SetUp() override {
GlicActorTaskIconManagerTest::SetUp();
actor::TaskId task_id = actor_service()->CreateTaskForTesting();
actor_service()->GetTask(task_id)->Pause(/*from_actor=*/true);
}
};
TEST_P(GlicActorTaskIconManagerPausedTasksTest, PausedTasks) {
GlicWindowController::State floaty_state = std::get<0>(GetParam());
CurrentView current_view = std::get<1>(GetParam());
ActorTaskIconState::Text expected_text = std::get<2>(GetParam());
MockTaskIconStateChangeSubscriber subscriber;
base::CallbackListSubscription subscription =
manager_->RegisterTaskIconStateChange(base::BindRepeating(
&MockTaskIconStateChangeSubscriber::OnStateChanged,
base::Unretained(&subscriber)));
EXPECT_CALL(
subscriber,
OnStateChanged(floaty_state, current_view,
AllOf(Field(&ActorTaskIconState::is_visible, true),
Field(&ActorTaskIconState::text, expected_text))));
manager()->UpdateTaskIcon(floaty_state, current_view);
}
INSTANTIATE_TEST_SUITE_P(
All,
GlicActorTaskIconManagerPausedTasksTest,
Values(std::make_tuple(GlicWindowController::State::kOpen,
CurrentView::kActuation,
ActorTaskIconState::Text::kDefault),
std::make_tuple(GlicWindowController::State::kClosed,
CurrentView::kActuation,
ActorTaskIconState::Text::kNeedsAttention),
std::make_tuple(GlicWindowController::State::kClosed,
CurrentView::kConversation,
ActorTaskIconState::Text::kNeedsAttention),
std::make_tuple(GlicWindowController::State::kOpen,
CurrentView::kConversation,
ActorTaskIconState::Text::kNeedsAttention)));
class GlicActorTaskIconManagerCompletedTasksTest
: public GlicActorTaskIconManagerTest,
public testing::WithParamInterface<std::tuple<GlicWindowController::State,
CurrentView,
ActorTaskIconState::Text>> {
public:
// testing::Test:
void SetUp() override {
GlicActorTaskIconManagerTest::SetUp();
TaskId task_id = actor_service()->CreateTaskForTesting();
actor_service()->StopTask(task_id, /*success=*/true);
}
};
TEST_P(GlicActorTaskIconManagerCompletedTasksTest, CompletedTasks) {
GlicWindowController::State floaty_state = std::get<0>(GetParam());
CurrentView current_view = std::get<1>(GetParam());
ActorTaskIconState::Text expected_text = std::get<2>(GetParam());
MockTaskIconStateChangeSubscriber subscriber;
base::CallbackListSubscription subscription =
manager_->RegisterTaskIconStateChange(base::BindRepeating(
&MockTaskIconStateChangeSubscriber::OnStateChanged,
base::Unretained(&subscriber)));
EXPECT_CALL(
subscriber,
OnStateChanged(floaty_state, current_view,
AllOf(Field(&ActorTaskIconState::is_visible, true),
Field(&ActorTaskIconState::text, expected_text))));
manager()->UpdateTaskIcon(floaty_state, current_view);
}
INSTANTIATE_TEST_SUITE_P(
All,
GlicActorTaskIconManagerCompletedTasksTest,
testing::Values(std::make_tuple(GlicWindowController::State::kOpen,
CurrentView::kActuation,
ActorTaskIconState::Text::kDefault),
std::make_tuple(GlicWindowController::State::kClosed,
CurrentView::kActuation,
ActorTaskIconState::Text::kCompleteTasks),
std::make_tuple(GlicWindowController::State::kClosed,
CurrentView::kConversation,
ActorTaskIconState::Text::kCompleteTasks),
std::make_tuple(GlicWindowController::State::kOpen,
CurrentView::kConversation,
ActorTaskIconState::Text::kCompleteTasks)));
} // namespace tabs
|