| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/pattern.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
| 21 #include "chrome/browser/extensions/extension_apitest.h" | 22 #include "chrome/browser/extensions/extension_apitest.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/pdf/pdf_extension_test_util.h" | 24 #include "chrome/browser/pdf/pdf_extension_test_util.h" |
| 24 #include "chrome/browser/pdf/pdf_extension_util.h" | 25 #include "chrome/browser/pdf/pdf_extension_util.h" |
| 25 #include "chrome/browser/plugins/plugin_prefs.h" | 26 #include "chrome/browser/plugins/plugin_prefs.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 using content::WebContents; | 65 using content::WebContents; |
| 65 | 66 |
| 66 const int kNumberLoadTestParts = 10; | 67 const int kNumberLoadTestParts = 10; |
| 67 | 68 |
| 68 #if defined(OS_MACOSX) | 69 #if defined(OS_MACOSX) |
| 69 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey; | 70 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey; |
| 70 #else | 71 #else |
| 71 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey; | 72 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey; |
| 72 #endif | 73 #endif |
| 73 | 74 |
| 74 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ | 75 // Check if the |actual| string matches the string or the string pattern in |
| 75 // in order to print a more readable message if the strings differ. | 76 // |pattern| and print a readable message if it does not match. |
| 76 #define ASSERT_MULTILINE_STREQ(expected, actual) \ | 77 #define ASSERT_MULTILINE_STR_MATCHES(pattern, actual) \ |
| 77 ASSERT_TRUE(expected == actual) \ | 78 ASSERT_TRUE(base::MatchPattern(actual, pattern)) \ |
| 78 << "Expected:\n" << expected \ | 79 << "Expected match pattern:\n" \ |
| 79 << "\n\nActual:\n" << actual | 80 << pattern << "\n\nActual:\n" \ |
| 81 << actual |
| 80 | 82 |
| 81 bool GetGuestCallback(WebContents** guest_out, WebContents* guest) { | 83 bool GetGuestCallback(WebContents** guest_out, WebContents* guest) { |
| 82 EXPECT_FALSE(*guest_out); | 84 EXPECT_FALSE(*guest_out); |
| 83 *guest_out = guest; | 85 *guest_out = guest; |
| 84 // Return false so that we iterate through all the guests and verify there is | 86 // Return false so that we iterate through all the guests and verify there is |
| 85 // only one. | 87 // only one. |
| 86 return false; | 88 return false; |
| 87 } | 89 } |
| 88 | 90 |
| 89 class PDFExtensionTest : public ExtensionApiTest, | 91 class PDFExtensionTest : public ExtensionApiTest, |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 if (node.role == ui::AX_ROLE_EMBEDDED_OBJECT) | 589 if (node.role == ui::AX_ROLE_EMBEDDED_OBJECT) |
| 588 found_embedded_object = true; | 590 found_embedded_object = true; |
| 589 if (!found_embedded_object) | 591 if (!found_embedded_object) |
| 590 continue; | 592 continue; |
| 591 | 593 |
| 592 int indent = id_to_indentation[node.id]; | 594 int indent = id_to_indentation[node.id]; |
| 593 ax_tree_dump += std::string(2 * indent, ' '); | 595 ax_tree_dump += std::string(2 * indent, ' '); |
| 594 ax_tree_dump += ui::ToString(node.role); | 596 ax_tree_dump += ui::ToString(node.role); |
| 595 | 597 |
| 596 std::string name = node.GetStringAttribute(ui::AX_ATTR_NAME); | 598 std::string name = node.GetStringAttribute(ui::AX_ATTR_NAME); |
| 597 base::ReplaceChars(name, "\r", "\\r", &name); | 599 base::ReplaceChars(name, "\r\n", "", &name); |
| 598 base::ReplaceChars(name, "\n", "\\n", &name); | |
| 599 if (!name.empty()) | 600 if (!name.empty()) |
| 600 ax_tree_dump += " '" + name + "'"; | 601 ax_tree_dump += " '" + name + "'"; |
| 601 ax_tree_dump += "\n"; | 602 ax_tree_dump += "\n"; |
| 602 for (size_t j = 0; j < node.child_ids.size(); ++j) | 603 for (size_t j = 0; j < node.child_ids.size(); ++j) |
| 603 id_to_indentation[node.child_ids[j]] = indent + 1; | 604 id_to_indentation[node.child_ids[j]] = indent + 1; |
| 604 } | 605 } |
| 605 | 606 |
| 606 return ax_tree_dump; | 607 return ax_tree_dump; |
| 607 } | 608 } |
| 608 | 609 |
| 609 static const char kExpectedPDFAXTree[] = | 610 // This is a pattern with a few wildcards due to a PDF bug where the |
| 611 // fi ligature is not parsed correctly on some systems. |
| 612 // http://crbug.com/701427 |
| 613 |
| 614 static const char kExpectedPDFAXTreePattern[] = |
| 610 "embeddedObject\n" | 615 "embeddedObject\n" |
| 611 " group\n" | 616 " group\n" |
| 612 " region 'Page 1'\n" | 617 " region 'Page 1'\n" |
| 613 " paragraph\n" | 618 " paragraph\n" |
| 614 " staticText '1 First Section\\r\\n'\n" | 619 " staticText '1 First Section'\n" |
| 615 " inlineTextBox '1 '\n" | 620 " inlineTextBox '1 '\n" |
| 616 " inlineTextBox 'First Section\\r\\n'\n" | 621 " inlineTextBox 'First Section'\n" |
| 617 " paragraph\n" | 622 " paragraph\n" |
| 618 " staticText 'This is the first section.\\r\\n1'\n" | 623 " staticText 'This is the *rst section.1'\n" |
| 619 " inlineTextBox 'This is the first section.\\r\\n'\n" | 624 " inlineTextBox 'This is the *rst section.'\n" |
| 620 " inlineTextBox '1'\n" | 625 " inlineTextBox '1'\n" |
| 621 " region 'Page 2'\n" | 626 " region 'Page 2'\n" |
| 622 " paragraph\n" | 627 " paragraph\n" |
| 623 " staticText '1.1 First Subsection\\r\\n'\n" | 628 " staticText '1.1 First Subsection'\n" |
| 624 " inlineTextBox '1.1 '\n" | 629 " inlineTextBox '1.1 '\n" |
| 625 " inlineTextBox 'First Subsection\\r\\n'\n" | 630 " inlineTextBox 'First Subsection'\n" |
| 626 " paragraph\n" | 631 " paragraph\n" |
| 627 " staticText 'This is the first subsection.\\r\\n2'\n" | 632 " staticText 'This is the *rst subsection.2'\n" |
| 628 " inlineTextBox 'This is the first subsection.\\r\\n'\n" | 633 " inlineTextBox 'This is the *rst subsection.'\n" |
| 629 " inlineTextBox '2'\n" | 634 " inlineTextBox '2'\n" |
| 630 " region 'Page 3'\n" | 635 " region 'Page 3'\n" |
| 631 " paragraph\n" | 636 " paragraph\n" |
| 632 " staticText '2 Second Section\\r\\n'\n" | 637 " staticText '2 Second Section'\n" |
| 633 " inlineTextBox '2 '\n" | 638 " inlineTextBox '2 '\n" |
| 634 " inlineTextBox 'Second Section\\r\\n'\n" | 639 " inlineTextBox 'Second Section'\n" |
| 635 " paragraph\n" | 640 " paragraph\n" |
| 636 " staticText '3'\n" | 641 " staticText '3'\n" |
| 637 " inlineTextBox '3'\n"; | 642 " inlineTextBox '3'\n"; |
| 638 | 643 |
| 639 // https://crbug.com/701427 | 644 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibility) { |
| 640 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibility) { | |
| 641 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 645 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 642 | 646 |
| 643 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); | 647 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); |
| 644 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | 648 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 645 ASSERT_TRUE(guest_contents); | 649 ASSERT_TRUE(guest_contents); |
| 646 | 650 |
| 647 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, | 651 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, |
| 648 "1 First Section\r\n"); | 652 "1 First Section\r\n"); |
| 649 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); | 653 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| 650 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); | 654 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| 651 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); | 655 |
| 656 ASSERT_MULTILINE_STR_MATCHES(kExpectedPDFAXTreePattern, ax_tree_dump); |
| 652 } | 657 } |
| 653 | 658 |
| 654 #if defined(GOOGLE_CHROME_BUILD) | 659 #if defined(GOOGLE_CHROME_BUILD) |
| 655 // Test a particular PDF encountered in the wild that triggered a crash | 660 // Test a particular PDF encountered in the wild that triggered a crash |
| 656 // when accessibility is enabled. (http://crbug.com/648981) | 661 // when accessibility is enabled. (http://crbug.com/648981) |
| 657 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityCharCountCrash) { | 662 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityCharCountCrash) { |
| 658 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 663 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 659 GURL test_pdf_url(embedded_test_server()->GetURL( | 664 GURL test_pdf_url(embedded_test_server()->GetURL( |
| 660 "/pdf_private/accessibility_crash_1.pdf")); | 665 "/pdf_private/accessibility_crash_1.pdf")); |
| 661 | 666 |
| 662 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | 667 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 663 ASSERT_TRUE(guest_contents); | 668 ASSERT_TRUE(guest_contents); |
| 664 | 669 |
| 665 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1"); | 670 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1"); |
| 666 } | 671 } |
| 667 #endif | 672 #endif |
| 668 | 673 |
| 669 // https://crbug.com/701427 | 674 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityEnableLater) { |
| 670 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityEnableLater) { | |
| 671 // In this test, load the PDF file first, with accessibility off. | 675 // In this test, load the PDF file first, with accessibility off. |
| 672 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); | 676 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); |
| 673 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | 677 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 674 ASSERT_TRUE(guest_contents); | 678 ASSERT_TRUE(guest_contents); |
| 675 | 679 |
| 676 // Now enable accessibility globally, and assert that the PDF accessibility | 680 // Now enable accessibility globally, and assert that the PDF accessibility |
| 677 // tree loads. | 681 // tree loads. |
| 678 EnableAccessibilityForWebContents(guest_contents); | 682 EnableAccessibilityForWebContents(guest_contents); |
| 679 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, | 683 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, |
| 680 "1 First Section\r\n"); | 684 "1 First Section\r\n"); |
| 681 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); | 685 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| 682 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); | 686 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| 683 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); | 687 ASSERT_MULTILINE_STR_MATCHES(kExpectedPDFAXTreePattern, ax_tree_dump); |
| 684 } | 688 } |
| 685 | 689 |
| 686 bool RetrieveGuestContents(WebContents** out_guest_contents, | 690 bool RetrieveGuestContents(WebContents** out_guest_contents, |
| 687 WebContents* in_guest_contents) { | 691 WebContents* in_guest_contents) { |
| 688 *out_guest_contents = in_guest_contents; | 692 *out_guest_contents = in_guest_contents; |
| 689 return true; | 693 return true; |
| 690 } | 694 } |
| 691 | 695 |
| 692 // https://crbug.com/701427 | 696 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityInIframe) { |
| 693 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInIframe) { | |
| 694 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 697 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 695 GURL test_iframe_url(embedded_test_server()->GetURL("/pdf/test-iframe.html")); | 698 GURL test_iframe_url(embedded_test_server()->GetURL("/pdf/test-iframe.html")); |
| 696 ui_test_utils::NavigateToURL(browser(), test_iframe_url); | 699 ui_test_utils::NavigateToURL(browser(), test_iframe_url); |
| 697 WebContents* contents = GetActiveWebContents(); | 700 WebContents* contents = GetActiveWebContents(); |
| 698 WaitForAccessibilityTreeToContainNodeWithName(contents, | 701 WaitForAccessibilityTreeToContainNodeWithName(contents, |
| 699 "1 First Section\r\n"); | 702 "1 First Section\r\n"); |
| 700 | 703 |
| 701 WebContents* guest_contents = nullptr; | 704 WebContents* guest_contents = nullptr; |
| 702 content::BrowserPluginGuestManager* guest_manager = | 705 content::BrowserPluginGuestManager* guest_manager = |
| 703 contents->GetBrowserContext()->GetGuestManager(); | 706 contents->GetBrowserContext()->GetGuestManager(); |
| 704 guest_manager->ForEachGuest(contents, | 707 guest_manager->ForEachGuest(contents, |
| 705 base::Bind(&RetrieveGuestContents, | 708 base::Bind(&RetrieveGuestContents, |
| 706 &guest_contents)); | 709 &guest_contents)); |
| 707 ASSERT_TRUE(guest_contents); | 710 ASSERT_TRUE(guest_contents); |
| 708 | 711 |
| 709 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); | 712 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| 710 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); | 713 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| 711 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); | 714 ASSERT_MULTILINE_STR_MATCHES(kExpectedPDFAXTreePattern, ax_tree_dump); |
| 712 } | 715 } |
| 713 | 716 |
| 714 // https://crbug.com/701427 | 717 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityInOOPIF) { |
| 715 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInOOPIF) { | |
| 716 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 718 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 717 GURL test_iframe_url(embedded_test_server()->GetURL( | 719 GURL test_iframe_url(embedded_test_server()->GetURL( |
| 718 "/pdf/test-cross-site-iframe.html")); | 720 "/pdf/test-cross-site-iframe.html")); |
| 719 ui_test_utils::NavigateToURL(browser(), test_iframe_url); | 721 ui_test_utils::NavigateToURL(browser(), test_iframe_url); |
| 720 WebContents* contents = GetActiveWebContents(); | 722 WebContents* contents = GetActiveWebContents(); |
| 721 WaitForAccessibilityTreeToContainNodeWithName(contents, | 723 WaitForAccessibilityTreeToContainNodeWithName(contents, |
| 722 "1 First Section\r\n"); | 724 "1 First Section\r\n"); |
| 723 | 725 |
| 724 WebContents* guest_contents = nullptr; | 726 WebContents* guest_contents = nullptr; |
| 725 content::BrowserPluginGuestManager* guest_manager = | 727 content::BrowserPluginGuestManager* guest_manager = |
| 726 contents->GetBrowserContext()->GetGuestManager(); | 728 contents->GetBrowserContext()->GetGuestManager(); |
| 727 guest_manager->ForEachGuest(contents, | 729 guest_manager->ForEachGuest(contents, |
| 728 base::Bind(&RetrieveGuestContents, | 730 base::Bind(&RetrieveGuestContents, |
| 729 &guest_contents)); | 731 &guest_contents)); |
| 730 ASSERT_TRUE(guest_contents); | 732 ASSERT_TRUE(guest_contents); |
| 731 | 733 |
| 732 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); | 734 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| 733 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); | 735 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| 734 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); | 736 ASSERT_MULTILINE_STR_MATCHES(kExpectedPDFAXTreePattern, ax_tree_dump); |
| 735 } | 737 } |
| 736 | 738 |
| 737 #if defined(GOOGLE_CHROME_BUILD) | 739 #if defined(GOOGLE_CHROME_BUILD) |
| 738 // Test a particular PDF encountered in the wild that triggered a crash | 740 // Test a particular PDF encountered in the wild that triggered a crash |
| 739 // when accessibility is enabled. (http://crbug.com/668724) | 741 // when accessibility is enabled. (http://crbug.com/668724) |
| 740 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityTextRunCrash) { | 742 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityTextRunCrash) { |
| 741 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); | 743 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); |
| 742 GURL test_pdf_url(embedded_test_server()->GetURL( | 744 GURL test_pdf_url(embedded_test_server()->GetURL( |
| 743 "/pdf_private/accessibility_crash_2.pdf")); | 745 "/pdf_private/accessibility_crash_2.pdf")); |
| 744 | 746 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenFromFTP) { | 1011 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenFromFTP) { |
| 1010 net::SpawnedTestServer ftp_server( | 1012 net::SpawnedTestServer ftp_server( |
| 1011 net::SpawnedTestServer::TYPE_FTP, net::SpawnedTestServer::kLocalhost, | 1013 net::SpawnedTestServer::TYPE_FTP, net::SpawnedTestServer::kLocalhost, |
| 1012 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/pdf"))); | 1014 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/pdf"))); |
| 1013 ASSERT_TRUE(ftp_server.Start()); | 1015 ASSERT_TRUE(ftp_server.Start()); |
| 1014 | 1016 |
| 1015 GURL url(ftp_server.GetURL("/test.pdf")); | 1017 GURL url(ftp_server.GetURL("/test.pdf")); |
| 1016 ASSERT_TRUE(LoadPdf(url)); | 1018 ASSERT_TRUE(LoadPdf(url)); |
| 1017 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle()); | 1019 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle()); |
| 1018 } | 1020 } |
| OLD | NEW |