| 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 74d1061f5b7285bfabda0c91c72e34cc1a16e2b0..d5a7d077bdd639e878c7d573ac222f0b533b1f10 100644
|
| --- a/chrome/browser/pdf/pdf_extension_test.cc
|
| +++ b/chrome/browser/pdf/pdf_extension_test.cc
|
| @@ -15,13 +15,13 @@
|
| #include "base/memory/ref_counted.h"
|
| #include "base/path_service.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/threading/platform_thread.h"
|
| #include "build/build_config.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/extensions/component_loader.h"
|
| #include "chrome/browser/extensions/extension_apitest.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/pdf/pdf_extension_test_util.h"
|
| -#include "chrome/browser/pdf/pdf_extension_util.h"
|
| #include "chrome/browser/plugins/plugin_prefs.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -30,6 +30,8 @@
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| +#include "components/pdf/browser/pdf_web_contents_helper.h"
|
| +#include "components/pdf/browser/pdf_web_contents_helper_client.h"
|
| #include "components/zoom/page_zoom.h"
|
| #include "components/zoom/test/zoom_test_utils.h"
|
| #include "components/zoom/zoom_controller.h"
|
| @@ -58,6 +60,8 @@
|
| #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
|
| #endif
|
|
|
| +namespace {
|
| +
|
| const int kNumberLoadTestParts = 10;
|
|
|
| #if defined(OS_MACOSX)
|
| @@ -82,6 +86,33 @@ bool GetGuestCallback(content::WebContents** guest_out,
|
| return false;
|
| }
|
|
|
| +class TestPDFWebContentsHelperClient : public pdf::PDFWebContentsHelperClient {
|
| + public:
|
| + explicit TestPDFWebContentsHelperClient(content::WebContents* contents)
|
| + : contents_(contents) {}
|
| + ~TestPDFWebContentsHelperClient() override {}
|
| +
|
| + int save_url_count() const { return save_url_count_; }
|
| +
|
| + private:
|
| + // PDFWebContentsHelperClient:
|
| + void UpdateLocationBar(content::WebContents* contents) override {}
|
| + void UpdateContentRestrictions(content::WebContents* contents,
|
| + int content_restrictions) override {}
|
| + void OnPDFHasUnsupportedFeature(content::WebContents* contents) override {}
|
| + void OnSaveURL(content::WebContents* contents) override {
|
| + EXPECT_EQ(contents_, contents);
|
| + ++save_url_count_;
|
| + }
|
| +
|
| + int save_url_count_ = 0;
|
| + content::WebContents* const contents_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestPDFWebContentsHelperClient);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| class PDFExtensionTest : public ExtensionApiTest,
|
| public testing::WithParamInterface<int> {
|
| public:
|
| @@ -251,6 +282,12 @@ class PDFExtensionTest : public ExtensionApiTest,
|
| ASSERT_EQ(expect_success, success);
|
| }
|
|
|
| + content::WebContents* SetUpForLinkClickTest() {
|
| + host_resolver()->AddRule("www.example.com", "127.0.0.1");
|
| + GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
|
| + return LoadPdfGetGuestContents(test_pdf_url);
|
| + }
|
| +
|
| void ConvertPageCoordToScreenCoord(content::WebContents* contents,
|
| gfx::Point* point) {
|
| ASSERT_TRUE(contents);
|
| @@ -281,7 +318,6 @@ class PDFExtensionTest : public ExtensionApiTest,
|
|
|
| point->SetPoint(x, y);
|
| }
|
| -
|
| };
|
|
|
| IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
|
| @@ -720,9 +756,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityInOOPIF) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) {
|
| - host_resolver()->AddRule("www.example.com", "127.0.0.1");
|
| - GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
|
| - content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
|
| + content::WebContents* guest_contents = SetUpForLinkClickTest();
|
| ASSERT_TRUE(guest_contents);
|
|
|
| // The link position of the test-link.pdf in page coordinates is (110, 110).
|
| @@ -757,9 +791,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) {
|
| - host_resolver()->AddRule("www.example.com", "127.0.0.1");
|
| - GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
|
| - content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
|
| + content::WebContents* guest_contents = SetUpForLinkClickTest();
|
| ASSERT_TRUE(guest_contents);
|
|
|
| // The link position of the test-link.pdf in page coordinates is (110, 110).
|
| @@ -794,9 +826,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) {
|
| - host_resolver()->AddRule("www.example.com", "127.0.0.1");
|
| - GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
|
| - content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
|
| + content::WebContents* guest_contents = SetUpForLinkClickTest();
|
| ASSERT_TRUE(guest_contents);
|
|
|
| // The link position of the test-link.pdf in page coordinates is (110, 110).
|
| @@ -828,9 +858,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) {
|
| - host_resolver()->AddRule("www.example.com", "127.0.0.1");
|
| - GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
|
| - content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
|
| + content::WebContents* guest_contents = SetUpForLinkClickTest();
|
| ASSERT_TRUE(guest_contents);
|
|
|
| // The link position of the test-link.pdf in page coordinates is (110, 110).
|
| @@ -858,3 +886,27 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) {
|
| const GURL& url = active_web_contents->GetURL();
|
| ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
|
| }
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DownloadPDFButton) {
|
| + GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
|
| + content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
|
| + ASSERT_TRUE(guest_contents);
|
| +
|
| + auto* helper = pdf::PDFWebContentsHelper::FromWebContents(guest_contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Pass ownership to |helper| but retain a raw pointer to check test results.
|
| + // |client| is alive for the duration of this test.
|
| + auto* client = new TestPDFWebContentsHelperClient(guest_contents);
|
| + helper->SetClientForTest(base::WrapUnique(client));
|
| +
|
| + const char kScript[] = "$('toolbar').fire('save');";
|
| + ASSERT_TRUE(content::ExecuteScript(guest_contents, kScript));
|
| +
|
| + // Wait to get the save count. If it never arrives and the test hangs, then
|
| + // the test has failed. Unfortunately with multiple processes in the PDF
|
| + // Viewer, it is too hard for the test to be event driven.
|
| + while (!client->save_url_count())
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
|
| + EXPECT_EQ(1, client->save_url_count());
|
| +}
|
|
|