diff --git a/components/ai_chat/core/browser/conversation_handler.cc b/components/ai_chat/core/browser/conversation_handler.cc index 744a10afd914..df092782e3e1 100644 --- a/components/ai_chat/core/browser/conversation_handler.cc +++ b/components/ai_chat/core/browser/conversation_handler.cc @@ -1047,8 +1047,7 @@ void ConversationHandler::MaybeFetchOrClearContentStagedConversation() { } const bool can_check_for_staged_conversation = - ai_chat_service_->HasUserOptedIn() && IsContentAssociationPossible() && - should_send_page_contents_; + IsContentAssociationPossible() && should_send_page_contents_; if (!can_check_for_staged_conversation) { // Clear any staged conversation entries since user might have unassociated // content with this conversation @@ -1071,7 +1070,7 @@ void ConversationHandler::OnGetStagedEntriesFromContent( const std::optional>& entries) { // Check if all requirements are still met. if (is_request_in_progress_ || !entries || !IsContentAssociationPossible() || - !should_send_page_contents_ || !ai_chat_service_->HasUserOptedIn()) { + !should_send_page_contents_) { return; } diff --git a/components/ai_chat/core/browser/conversation_handler_unittest.cc b/components/ai_chat/core/browser/conversation_handler_unittest.cc index 975b1bb580d7..381b9c9fcace 100644 --- a/components/ai_chat/core/browser/conversation_handler_unittest.cc +++ b/components/ai_chat/core/browser/conversation_handler_unittest.cc @@ -1093,13 +1093,6 @@ TEST_F(ConversationHandlerUnitTest, conversation_handler_->OnGetStagedEntriesFromContent(entries); task_environment_.RunUntilIdle(); EXPECT_EQ(conversation_handler_->GetConversationHistory().size(), 0u); - - // No staged entries if user opt-out. - conversation_handler_->SetShouldSendPageContents(true); - EmulateUserOptedOut(); - conversation_handler_->OnGetStagedEntriesFromContent(entries); - task_environment_.RunUntilIdle(); - EXPECT_EQ(conversation_handler_->GetConversationHistory().size(), 0u); } TEST_F(ConversationHandlerUnitTest, OnGetStagedEntriesFromContent) { @@ -1135,19 +1128,15 @@ TEST_F(ConversationHandlerUnitTest, OnGetStagedEntriesFromContent) { EXPECT_EQ(history[5]->text, "summary2"); } -TEST_F(ConversationHandlerUnitTest_OptedOut, +TEST_F(ConversationHandlerUnitTest, MaybeFetchOrClearSearchQuerySummary_NotOptedIn) { - // Content will have staged entries, but we want to make sure that - // ConversationHandler won't ask for them when not opted-in yet. + // Staged entries could be retrieved before user opts in. SetAssociatedContentStagedEntries(/*empty=*/false); - EXPECT_CALL(*associated_content_, GetStagedEntriesFromContent).Times(0); - // Modifying whether page contents should be sent should trigger content - // staging. + EXPECT_CALL(*associated_content_, GetStagedEntriesFromContent).Times(1); // Don't get a false positive because no client is automatically connected. + // Connecting a client will trigger content staging. NiceMock client(conversation_handler_.get()); EXPECT_TRUE(conversation_handler_->IsAnyClientConnected()); - conversation_handler_->SetShouldSendPageContents(false); - conversation_handler_->SetShouldSendPageContents(true); conversation_handler_->GetAssociatedContentInfo(base::BindLambdaForTesting( [&](mojom::SiteInfoPtr site_info, bool should_send_page_contents) { EXPECT_TRUE(should_send_page_contents); @@ -1156,7 +1145,7 @@ TEST_F(ConversationHandlerUnitTest_OptedOut, task_environment_.RunUntilIdle(); testing::Mock::VerifyAndClearExpectations(conversation_handler_.get()); - EXPECT_TRUE(conversation_handler_->GetConversationHistory().empty()); + EXPECT_FALSE(conversation_handler_->GetConversationHistory().empty()); } TEST_F(ConversationHandlerUnitTest, diff --git a/components/ai_chat/resources/page/components/main/index.tsx b/components/ai_chat/resources/page/components/main/index.tsx index d290fa2cd8bc..8ad6789a1935 100644 --- a/components/ai_chat/resources/page/components/main/index.tsx +++ b/components/ai_chat/resources/page/components/main/index.tsx @@ -248,7 +248,7 @@ function Main() {
} - {!aiChatContext.hasAcceptedAgreement && } + {!aiChatContext.hasAcceptedAgreement && !conversationContext.conversationHistory.length && }