Skip to content

Commit

Permalink
Merge pull request #25619 from brave/upstream-ocr-test
Browse files Browse the repository at this point in the history
Consider IDS_PDF_OCR_IN_PROGRESS when checking whether PDF is loaded.
  • Loading branch information
darkdh committed Sep 18, 2024
1 parent 49886f5 commit 81712d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions browser/ai_chat/ai_chat_ui_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,23 @@ IN_PROC_BROWSER_TEST_F(AIChatUIBrowserTest, ExtractionPrintDialog) {
#endif // BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER) &&
// defined(ARCH_CPU_64_BITS)
IN_PROC_BROWSER_TEST_F(AIChatUIBrowserTest, MAYBE_PrintPreviewFallback) {
auto run_loop = std::make_unique<base::RunLoop>();
// TODO(darkdh): Enable text_in_image.pdf when upstream fixes the hanging
// blank page issue. See https://github.com/brave/brave-browser/issues/41113
#if 0
NavigateURL(https_server_.GetURL("a.com", "/text_in_image.pdf"));

auto run_loop = std::make_unique<base::RunLoop>();
chat_tab_helper_->GeneratePageContent(
base::BindLambdaForTesting([&run_loop](std::string text, bool is_video,
std::string invalidation_token) {
EXPECT_FALSE(is_video);
EXPECT_EQ(
text,
"This is the way.\n\nI have spoken.\nWherever I Go, He Goes.");
EXPECT_EQ(text,
"This is the way.\n\nI have spoken.\nWherever I Go, He Goes.");
run_loop->Quit();
}));
run_loop->Run();
run_loop = std::make_unique<base::RunLoop>();
#endif

NavigateURL(https_server_.GetURL("a.com", "/canvas.html"));
chat_tab_helper_->GeneratePageContent(
Expand Down
9 changes: 9 additions & 0 deletions components/ai_chat/content/browser/pdf_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "brave/components/ai_chat/content/browser/pdf_utils.h"

#include "base/strings/strcat.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "pdf/buildflags.h"
Expand Down Expand Up @@ -127,6 +128,14 @@ bool IsPdfLoaded(const ui::AXNode* pdf_root) {
return false;
}

#if BUILDFLAG(ENABLE_PDF)
if (pdf_root->GetChildAtIndex(0)->GetChildAtIndex(0)->GetStringAttribute(
ax::mojom::StringAttribute::kName) ==
l10n_util::GetStringUTF8(IDS_PDF_OCR_IN_PROGRESS)) {
return false;
}
#endif

return true;
}

Expand Down

0 comments on commit 81712d5

Please sign in to comment.