Chromium Code Reviews| Index: chrome/browser/pdf/pdf_extension_test.cc |
| diff --git a/chrome/browser/pdf/pdf_extension_test.cc b/chrome/browser/pdf/pdf_extension_test.cc |
| index 3e11df7829e3d3e63da939418497da44bdc69f4c..39f070c9688b6c8e362cefa9899ff8144aea558c 100644 |
| --- a/chrome/browser/pdf/pdf_extension_test.cc |
| +++ b/chrome/browser/pdf/pdf_extension_test.cc |
| @@ -48,6 +48,7 @@ |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| #include "extensions/test/result_catcher.h" |
| +#include "net/dns/mock_host_resolver.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "url/gurl.h" |
| @@ -58,6 +59,13 @@ |
| const int kNumberLoadTestParts = 10; |
| +// Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ |
| +// in order to print a more readable message if the strings differ. |
| +#define ASSERT_MULTILINE_STREQ(expected, actual) \ |
| + ASSERT_TRUE(expected == actual) \ |
| + << "Expected:\n" << expected \ |
| + << "\n\nActual:\n" << actual |
| + |
| bool GetGuestCallback(content::WebContents** guest_out, |
| content::WebContents* guest) { |
| EXPECT_FALSE(*guest_out); |
| @@ -72,9 +80,15 @@ class PDFExtensionTest : public ExtensionApiTest, |
| public: |
| ~PDFExtensionTest() override {} |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + content::IsolateAllSitesForTesting(command_line); |
| + } |
| + |
| void SetUpOnMainThread() override { |
| ExtensionApiTest::SetUpOnMainThread(); |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| ASSERT_TRUE(embedded_test_server()->Start()); |
| + content::SetupCrossSiteRedirector(embedded_test_server()); |
| } |
| void TearDownOnMainThread() override { |
| @@ -513,17 +527,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfZoomWithoutBubble) { |
| #endif |
| } |
| -IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibility) { |
| - content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| - |
| - GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); |
| - content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| - ASSERT_TRUE(guest_contents); |
| - |
| - WaitForAccessibilityTreeToContainNodeWithName(guest_contents, |
| - "1 First Section\r\n"); |
| - ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| - |
| +static std::string DumpPdfAccessibilityTree(const ui::AXTreeUpdate& ax_tree) { |
| // Create a string representation of the tree starting with the embedded |
| // object. |
| std::string ax_tree_dump; |
| @@ -549,39 +553,117 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibility) { |
| id_to_indentation[node.child_ids[j]] = indent + 1; |
| } |
| - const char* expected_ax_tree = |
| - "embeddedObject\n" |
| - " group\n" |
| - " region 'Page 1'\n" |
| - " paragraph\n" |
| - " staticText '1 First Section\\r\\n'\n" |
| - " inlineTextBox '1 '\n" |
| - " inlineTextBox 'First Section\\r\\n'\n" |
| - " paragraph\n" |
| - " staticText 'This is the first section.\\r\\n1'\n" |
| - " inlineTextBox 'This is the first section.\\r\\n'\n" |
| - " inlineTextBox '1'\n" |
| - " region 'Page 2'\n" |
| - " paragraph\n" |
| - " staticText '1.1 First Subsection\\r\\n'\n" |
| - " inlineTextBox '1.1 '\n" |
| - " inlineTextBox 'First Subsection\\r\\n'\n" |
| - " paragraph\n" |
| - " staticText 'This is the first subsection.\\r\\n2'\n" |
| - " inlineTextBox 'This is the first subsection.\\r\\n'\n" |
| - " inlineTextBox '2'\n" |
| - " region 'Page 3'\n" |
| - " paragraph\n" |
| - " staticText '2 Second Section\\r\\n'\n" |
| - " inlineTextBox '2 '\n" |
| - " inlineTextBox 'Second Section\\r\\n'\n" |
| - " paragraph\n" |
| - " staticText '3'\n" |
| - " inlineTextBox '3'\n"; |
| - |
| - // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ |
| - // in order to print a more readable message if the strings differ. |
| - ASSERT_TRUE(expected_ax_tree == ax_tree_dump) |
| - << "Expected:\n" << expected_ax_tree |
| - << "\n\nActual:\n" << ax_tree_dump; |
| + return ax_tree_dump; |
| +} |
| + |
| +static const char* kExpectedPDFAXTree = |
|
Lei Zhang
2016/07/15 19:26:21
const char kFoo[], otherwise you can potentially w
dmazzoni
2016/07/18 04:28:32
Done
|
| + "embeddedObject\n" |
| + " group\n" |
| + " region 'Page 1'\n" |
| + " paragraph\n" |
| + " staticText '1 First Section\\r\\n'\n" |
| + " inlineTextBox '1 '\n" |
| + " inlineTextBox 'First Section\\r\\n'\n" |
| + " paragraph\n" |
| + " staticText 'This is the first section.\\r\\n1'\n" |
| + " inlineTextBox 'This is the first section.\\r\\n'\n" |
| + " inlineTextBox '1'\n" |
| + " region 'Page 2'\n" |
| + " paragraph\n" |
| + " staticText '1.1 First Subsection\\r\\n'\n" |
| + " inlineTextBox '1.1 '\n" |
| + " inlineTextBox 'First Subsection\\r\\n'\n" |
| + " paragraph\n" |
| + " staticText 'This is the first subsection.\\r\\n2'\n" |
| + " inlineTextBox 'This is the first subsection.\\r\\n'\n" |
| + " inlineTextBox '2'\n" |
| + " region 'Page 3'\n" |
| + " paragraph\n" |
| + " staticText '2 Second Section\\r\\n'\n" |
| + " inlineTextBox '2 '\n" |
| + " inlineTextBox 'Second Section\\r\\n'\n" |
| + " paragraph\n" |
| + " staticText '3'\n" |
| + " inlineTextBox '3'\n"; |
| + |
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibility) { |
| + content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| + |
| + GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); |
| + content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| + ASSERT_TRUE(guest_contents); |
| + |
| + WaitForAccessibilityTreeToContainNodeWithName(guest_contents, |
| + "1 First Section\r\n"); |
| + ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| + std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| + ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityEnableLater) { |
| + // In this test, load the PDF file first, with accessibility off. |
| + GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); |
| + content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| + ASSERT_TRUE(guest_contents); |
| + |
| + // Now enable accessibility globally, and assert that the PDF accessibility |
| + // tree loads. |
| + EnableAccessibilityForWebContents(guest_contents); |
| + WaitForAccessibilityTreeToContainNodeWithName(guest_contents, |
| + "1 First Section\r\n"); |
| + ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| + std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| + ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); |
| +} |
| + |
| +bool RetrieveGuestContents( |
| + content::WebContents** out_guest_contents, |
| + content::WebContents* in_guest_contents) { |
| + *out_guest_contents = in_guest_contents; |
| + return true; |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityInIframe) { |
| + content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| + GURL test_iframe_url(embedded_test_server()->GetURL("/pdf/test-iframe.html")); |
| + ui_test_utils::NavigateToURL(browser(), test_iframe_url); |
| + content::WebContents* contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + WaitForAccessibilityTreeToContainNodeWithName(contents, |
| + "1 First Section\r\n"); |
| + |
| + content::WebContents* guest_contents = nullptr; |
| + content::BrowserPluginGuestManager* guest_manager = |
| + contents->GetBrowserContext()->GetGuestManager(); |
| + guest_manager->ForEachGuest(contents, |
| + base::Bind(&RetrieveGuestContents, |
| + &guest_contents)); |
| + ASSERT_TRUE(guest_contents); |
| + |
| + ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| + std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| + ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityInOOPIF) { |
| + content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| + GURL test_iframe_url(embedded_test_server()->GetURL( |
| + "/pdf/test-cross-site-iframe.html")); |
| + ui_test_utils::NavigateToURL(browser(), test_iframe_url); |
| + content::WebContents* contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + WaitForAccessibilityTreeToContainNodeWithName(contents, |
| + "1 First Section\r\n"); |
| + |
| + content::WebContents* guest_contents = nullptr; |
| + content::BrowserPluginGuestManager* guest_manager = |
| + contents->GetBrowserContext()->GetGuestManager(); |
| + guest_manager->ForEachGuest(contents, |
| + base::Bind(&RetrieveGuestContents, |
| + &guest_contents)); |
| + ASSERT_TRUE(guest_contents); |
| + |
| + ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| + std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| + ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); |
| } |