Added test cases for focus APIs of class BAAnnotHandler.

1. These test cases verify the current behaviour of focus APIs of
class BAAnnotHandler.

2. Same test cases will be updated for new behaviour of these APIs
once class BAAnnotHandler becomes capable of tabbing over links and
highlights.

3. Related PR
(https://pdfium-review.googlesource.com/c/pdfium/+/60011/).


Bug: chromium:994500
Change-Id: Icd3d1c72354ffd02d92b4e98675fe1aebec59bce
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62950
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Neha Gupta <negupta@microsoft.com>
diff --git a/fpdfsdk/BUILD.gn b/fpdfsdk/BUILD.gn
index 3c1b39c..1c77fee 100644
--- a/fpdfsdk/BUILD.gn
+++ b/fpdfsdk/BUILD.gn
@@ -128,6 +128,7 @@
 pdfium_embeddertest_source_set("embeddertests") {
   sources = [
     "cpdfsdk_annotiterator_embeddertest.cpp",
+    "cpdfsdk_baannothandler_embeddertest.cpp",
     "fpdf_annot_embeddertest.cpp",
     "fpdf_attachment_embeddertest.cpp",
     "fpdf_dataavail_embeddertest.cpp",
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.h b/fpdfsdk/cpdfsdk_annothandlermgr.h
index 2136555..b88f613 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.h
@@ -116,6 +116,8 @@
                        const CFX_PointF& point);
 
  private:
+  friend class CPDFSDK_BAAnnotHandlerTest;
+
   IPDFSDK_AnnotHandler* GetAnnotHandler(CPDFSDK_Annot* pAnnot) const;
   IPDFSDK_AnnotHandler* GetAnnotHandlerOfType(
       CPDF_Annot::Subtype nAnnotSubtype) const;
diff --git a/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp b/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp
new file mode 100644
index 0000000..9a26e83
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_baannothandler_embeddertest.cpp
@@ -0,0 +1,88 @@
+// Copyright 2019 The PDFium 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 "fpdfsdk/cpdfsdk_annotiterator.h"
+#include "fpdfsdk/cpdfsdk_baannothandler.h"
+#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
+#include "fpdfsdk/cpdfsdk_helpers.h"
+#include "fpdfsdk/cpdfsdk_pageview.h"
+#include "public/fpdf_annot.h"
+#include "testing/embedder_test.h"
+
+class CPDFSDK_BAAnnotHandlerTest : public EmbedderTest {
+ public:
+  void SetUp() override {
+    // Test behaviour with currently supported annot i.e. Widget.
+    // TODO(crbug.com/994500): Add an API that can set list of focusable
+    // subtypes once other annots(links & highlights) are also supported.
+    EmbedderTest::SetUp();
+    SetUpBAAnnotHandler();
+  }
+
+  void TearDown() override {
+    UnloadPage(m_page);
+    EmbedderTest::TearDown();
+  }
+
+  void SetUpBAAnnotHandler() {
+    EXPECT_TRUE(OpenDocument("links_highlights_annots.pdf"));
+    m_page = LoadPage(0);
+    ASSERT_TRUE(m_page);
+
+    CPDFSDK_FormFillEnvironment* pFormFillEnv =
+        CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle());
+    ASSERT_TRUE(pFormFillEnv);
+    m_pPageView = pFormFillEnv->GetPageView(IPDFPageFromFPDFPage(m_page), true);
+    ASSERT_TRUE(m_pPageView);
+
+    CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
+        pFormFillEnv->GetAnnotHandlerMgr();
+    ASSERT_TRUE(pAnnotHandlerMgr);
+    m_pBAAnnotHandler = pAnnotHandlerMgr->m_pBAAnnotHandler.get();
+    ASSERT_TRUE(m_pBAAnnotHandler);
+  }
+
+  CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
+  CPDFSDK_BAAnnotHandler* GetBAAnnotHandler() const {
+    return m_pBAAnnotHandler;
+  }
+
+ private:
+  FPDF_PAGE m_page = nullptr;
+  CPDFSDK_PageView* m_pPageView = nullptr;
+  CPDFSDK_BAAnnotHandler* m_pBAAnnotHandler = nullptr;
+};
+
+TEST_F(CPDFSDK_BAAnnotHandlerTest, TabToLinkOrHighlightAnnot) {
+  // TODO(crbug.com/994500): Create annot iterator with list of supported
+  // focusable subtypes as provided by host.
+  CPDFSDK_AnnotIterator ai(GetPageView(), CPDF_Annot::Subtype::LINK);
+  CPDFSDK_Annot* pAnnot = ai.GetFirstAnnot();
+  ASSERT_TRUE(pAnnot);
+  EXPECT_EQ(pAnnot->GetAnnotSubtype(), CPDF_Annot::Subtype::LINK);
+
+  ObservedPtr<CPDFSDK_Annot> pNonWidgetAnnot(pAnnot);
+
+  // TODO(crbug.com/994500): Change expected value as true once
+  // links & highlights are supported.
+  EXPECT_FALSE(GetBAAnnotHandler()->OnSetFocus(&pNonWidgetAnnot, 0));
+
+  EXPECT_FALSE(GetBAAnnotHandler()->OnKillFocus(&pNonWidgetAnnot, 0));
+}
+
+TEST_F(CPDFSDK_BAAnnotHandlerTest, TabToInvalidAnnot) {
+  // TODO(crbug.com/994500): Create annot iterator with list of supported
+  // focusable subtypes as provided by host.
+  CPDFSDK_AnnotIterator ai(GetPageView(), CPDF_Annot::Subtype::WIDGET);
+  CPDFSDK_Annot* pAnnot = ai.GetFirstAnnot();
+  ASSERT_TRUE(pAnnot);
+  EXPECT_EQ(pAnnot->GetAnnotSubtype(), CPDF_Annot::Subtype::WIDGET);
+
+  ObservedPtr<CPDFSDK_Annot> pWidgetAnnot(pAnnot);
+
+  // Passing wrong subtype to BAAnnotHandler, API should return false.
+  EXPECT_FALSE(GetBAAnnotHandler()->OnSetFocus(&pWidgetAnnot, 0));
+
+  EXPECT_FALSE(GetBAAnnotHandler()->OnKillFocus(&pWidgetAnnot, 0));
+}
diff --git a/testing/resources/links_highlights_annots.in b/testing/resources/links_highlights_annots.in
new file mode 100644
index 0000000..9a5e2ec
--- /dev/null
+++ b/testing/resources/links_highlights_annots.in
@@ -0,0 +1,139 @@
+{{header}}
+{{object 1 0}} <<
+  /Type /Catalog
+  /Pages 2 0 R
+  /AcroForm 6 0 R
+>>
+endobj
+{{object 2 0}} <<
+  /Type /Pages
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+% Page number 0.
+{{object 3 0}} <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Resources <<
+    /Font <<
+      /F1 5 0 R
+    >>
+  >>
+  /MediaBox [0 0 612 792]
+  /Annots [
+    8 0 R
+    9 0 R
+    10 0 R
+    11 0 R
+    12 0 R
+    13 0 R
+  ]
+  /Tabs /R
+>>
+endobj
+{{object 4 0}} <<
+  {{streamlen}}
+>>
+stream
+BT
+70 700 Td
+/F1 18 Tf
+(Link Annotations) Tj
+0 -65 Td
+/F1 14 Tf
+(External Link ) Tj
+0 -104 Td
+/F1 10 Tf
+(PDF Reference, Version 1.7, Section 8.4.5 defines Annotations) Tj
+ET
+endstream
+endobj
+{{object 5 0}} <<
+  /Type /Font
+  /Subtype /Type1
+  /BaseFont /Helvetica
+>>
+endobj
+% Forms
+{{object 6 0}} <<
+  /Fields [7 0 R]
+>>
+endobj
+% Fields
+{{object 7 0}} <<
+  /Kids [
+    8 0 R
+    9 0 R
+    10 0 R
+    11 0 R
+  ]
+>>
+endobj
+{{object 8 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_LeftBottom)
+  /Rect [69 670 220 690]
+>>
+endobj
+{{object 9 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_RightTop)
+  /Rect [69 440 220 460]
+>>
+endobj
+{{object 10 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_LeftTop)
+  /Rect [69 600 221 620]
+>>
+endobj
+{{object 11 0}} <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_RightBottom)
+  /Rect [69 400 220 420]
+>>
+endobj
+{{object 12 0}} <<
+  /Type /Annot
+  /Subtype /Link
+  /BS <<
+    /W 0
+  >>
+  /Rect [69 633 542 653]
+  /A <<
+    /Type /Action
+    /S /URI
+    /URI (https://www.google.com/)
+  >>
+  /F 4
+>>
+endobj
+{{object 13 0}} <<
+  /Type /Annot
+  /Subtype /Highlight
+  /NM (Highlight-1)
+  /F 4
+  /QuadPoints [293 542 349 542 293 530 349 530]
+  /P 3 0 R
+  /C [1 0.90196 0]
+  /Rect [293 530 349 542]
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
\ No newline at end of file
diff --git a/testing/resources/links_highlights_annots.pdf b/testing/resources/links_highlights_annots.pdf
new file mode 100644
index 0000000..7f392b4
--- /dev/null
+++ b/testing/resources/links_highlights_annots.pdf
@@ -0,0 +1,159 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+  /AcroForm 6 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+% Page number 0.
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Resources <<
+    /Font <<
+      /F1 5 0 R
+    >>
+  >>
+  /MediaBox [0 0 612 792]
+  /Annots [
+    8 0 R
+    9 0 R
+    10 0 R
+    11 0 R
+    12 0 R
+    13 0 R
+  ]
+  /Tabs /R
+>>
+endobj
+4 0 obj <<
+  /Length 174
+>>
+stream
+BT
+70 700 Td
+/F1 18 Tf
+(Link Annotations) Tj
+0 -65 Td
+/F1 14 Tf
+(External Link ) Tj
+0 -104 Td
+/F1 10 Tf
+(PDF Reference, Version 1.7, Section 8.4.5 defines Annotations) Tj
+ET
+endstream
+endobj
+5 0 obj <<
+  /Type /Font
+  /Subtype /Type1
+  /BaseFont /Helvetica
+>>
+endobj
+% Forms
+6 0 obj <<
+  /Fields [7 0 R]
+>>
+endobj
+% Fields
+7 0 obj <<
+  /Kids [
+    8 0 R
+    9 0 R
+    10 0 R
+    11 0 R
+  ]
+>>
+endobj
+8 0 obj <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_LeftBottom)
+  /Rect [69 670 220 690]
+>>
+endobj
+9 0 obj <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_RightTop)
+  /Rect [69 440 220 460]
+>>
+endobj
+10 0 obj <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_LeftTop)
+  /Rect [69 600 221 620]
+>>
+endobj
+11 0 obj <<
+  /Type /Annot
+  /Subtype /Widget
+  /FT /Tx
+  /P 3 0 R
+  /T (Sub_RightBottom)
+  /Rect [69 400 220 420]
+>>
+endobj
+12 0 obj <<
+  /Type /Annot
+  /Subtype /Link
+  /BS <<
+    /W 0
+  >>
+  /Rect [69 633 542 653]
+  /A <<
+    /Type /Action
+    /S /URI
+    /URI (https://www.google.com/)
+  >>
+  /F 4
+>>
+endobj
+13 0 obj <<
+  /Type /Annot
+  /Subtype /Highlight
+  /NM (Highlight-1)
+  /F 4
+  /QuadPoints [293 542 349 542 293 530 349 530]
+  /P 3 0 R
+  /C [1 0.90196 0]
+  /Rect [293 530 349 542]
+>>
+endobj
+xref
+0 14
+0000000000 65535 f 
+0000000015 00000 n 
+0000000086 00000 n 
+0000000166 00000 n 
+0000000409 00000 n 
+0000000635 00000 n 
+0000000719 00000 n 
+0000000767 00000 n 
+0000000844 00000 n 
+0000000967 00000 n 
+0000001088 00000 n 
+0000001209 00000 n 
+0000001334 00000 n 
+0000001521 00000 n 
+trailer <<
+  /Root 1 0 R
+  /Size 14
+>>
+startxref
+1711
+%%EOF
\ No newline at end of file