| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/hash.h" | 10 #include "base/hash.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/chrome_content_client.h" | 25 #include "chrome/common/chrome_content_client.h" |
| 26 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "content/public/browser/browser_plugin_guest_manager.h" | 29 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 30 #include "content/public/browser/download_item.h" | 30 #include "content/public/browser/download_item.h" |
| 31 #include "content/public/browser/download_manager.h" | 31 #include "content/public/browser/download_manager.h" |
| 32 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
| 33 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 34 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
| 35 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
| 37 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
| 38 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 39 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 39 #include "extensions/test/result_catcher.h" | 40 #include "extensions/test/result_catcher.h" |
| 40 #include "net/test/embedded_test_server/embedded_test_server.h" | 41 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 41 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
| 42 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 43 | 44 |
| 44 const int kNumberLoadTestParts = 10; | 45 const int kNumberLoadTestParts = 10; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 const std::string& pdf_filename) { | 94 const std::string& pdf_filename) { |
| 94 extensions::ResultCatcher catcher; | 95 extensions::ResultCatcher catcher; |
| 95 | 96 |
| 96 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); | 97 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); |
| 97 | 98 |
| 98 // It should be good enough to just navigate to the URL. But loading up the | 99 // It should be good enough to just navigate to the URL. But loading up the |
| 99 // BrowserPluginGuest seems to happen asynchronously as there was flakiness | 100 // BrowserPluginGuest seems to happen asynchronously as there was flakiness |
| 100 // being seen due to the BrowserPluginGuest not being available yet (see | 101 // being seen due to the BrowserPluginGuest not being available yet (see |
| 101 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is | 102 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is |
| 102 // loaded before continuing. | 103 // loaded before continuing. |
| 103 ASSERT_TRUE(LoadPdf(url)); | 104 content::WebContents* guest_contents = LoadPdfGetGuestContents(url); |
| 104 | |
| 105 content::WebContents* contents = | |
| 106 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 107 content::BrowserPluginGuestManager* guest_manager = | |
| 108 contents->GetBrowserContext()->GetGuestManager(); | |
| 109 content::WebContents* guest_contents = | |
| 110 guest_manager->GetFullPageGuest(contents); | |
| 111 ASSERT_TRUE(guest_contents); | 105 ASSERT_TRUE(guest_contents); |
| 112 | 106 |
| 113 base::FilePath test_data_dir; | 107 base::FilePath test_data_dir; |
| 114 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 108 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 115 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); | 109 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); |
| 116 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js"); | 110 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js"); |
| 117 std::string test_util_js; | 111 std::string test_util_js; |
| 118 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js)); | 112 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js)); |
| 119 | 113 |
| 120 base::FilePath test_file_path = test_data_dir.AppendASCII(filename); | 114 base::FilePath test_file_path = test_data_dir.AppendASCII(filename); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 // fails. If it doesn't finish loading the test will hang. This is done from | 127 // fails. If it doesn't finish loading the test will hang. This is done from |
| 134 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works | 128 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works |
| 135 // correctly from there. | 129 // correctly from there. |
| 136 bool LoadPdf(const GURL& url) { | 130 bool LoadPdf(const GURL& url) { |
| 137 ui_test_utils::NavigateToURL(browser(), url); | 131 ui_test_utils::NavigateToURL(browser(), url); |
| 138 content::WebContents* web_contents = | 132 content::WebContents* web_contents = |
| 139 browser()->tab_strip_model()->GetActiveWebContents(); | 133 browser()->tab_strip_model()->GetActiveWebContents(); |
| 140 return pdf_extension_test_util::EnsurePDFHasLoaded(web_contents); | 134 return pdf_extension_test_util::EnsurePDFHasLoaded(web_contents); |
| 141 } | 135 } |
| 142 | 136 |
| 137 // Same as |LoadPdf|, but also returns a pointer to the guest WebContents for |
| 138 // the loaded PDF. Returns nullptr if the load fails. |
| 139 content::WebContents* LoadPdfGetGuestContents(const GURL& url) { |
| 140 if (!LoadPdf(url)) |
| 141 return nullptr; |
| 142 |
| 143 content::WebContents* contents = |
| 144 browser()->tab_strip_model()->GetActiveWebContents(); |
| 145 content::BrowserPluginGuestManager* guest_manager = |
| 146 contents->GetBrowserContext()->GetGuestManager(); |
| 147 content::WebContents* guest_contents = |
| 148 guest_manager->GetFullPageGuest(contents); |
| 149 return guest_contents; |
| 150 } |
| 151 |
| 143 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs | 152 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs |
| 144 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order | 153 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order |
| 145 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). | 154 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). |
| 146 void LoadAllPdfsTest(const std::string& dir_name, int k) { | 155 void LoadAllPdfsTest(const std::string& dir_name, int k) { |
| 147 base::FilePath test_data_dir; | 156 base::FilePath test_data_dir; |
| 148 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 157 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
| 149 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), | 158 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), |
| 150 false, base::FileEnumerator::FILES, | 159 false, base::FileEnumerator::FILES, |
| 151 FILE_PATH_LITERAL("*.pdf")); | 160 FILE_PATH_LITERAL("*.pdf")); |
| 152 | 161 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 "</body></html>"; | 384 "</body></html>"; |
| 376 TestGetSelectedTextReply(GURL(data_url), false); | 385 TestGetSelectedTextReply(GURL(data_url), false); |
| 377 } | 386 } |
| 378 | 387 |
| 379 // Ensure same-origin replies do work for getSelectedText. | 388 // Ensure same-origin replies do work for getSelectedText. |
| 380 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) { | 389 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) { |
| 381 TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"), | 390 TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"), |
| 382 true); | 391 true); |
| 383 } | 392 } |
| 384 | 393 |
| 394 // This test ensures that link permissions are enforced properly in PDFs. |
| 395 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkPermissions) { |
| 396 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); |
| 397 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 398 ASSERT_TRUE(guest_contents); |
| 399 |
| 400 // chrome://favicon links should be allowed for PDFs, while chrome://settings |
| 401 // links should not. |
| 402 GURL valid_link_url("chrome://favicon/https://www.google.ca/"); |
| 403 GURL invalid_link_url("chrome://settings"); |
| 404 |
| 405 GURL unfiltered_valid_link_url(valid_link_url); |
| 406 content::RenderProcessHost* rph = guest_contents->GetRenderProcessHost(); |
| 407 rph->FilterURL(true, &valid_link_url); |
| 408 rph->FilterURL(true, &invalid_link_url); |
| 409 |
| 410 // Invalid link URLs should be changed to "about:blank" when filtered. |
| 411 EXPECT_EQ(unfiltered_valid_link_url, valid_link_url); |
| 412 EXPECT_EQ(GURL("about:blank"), invalid_link_url); |
| 413 } |
| 414 |
| 385 class MaterialPDFExtensionTest : public PDFExtensionTest { | 415 class MaterialPDFExtensionTest : public PDFExtensionTest { |
| 386 void SetUpCommandLine(base::CommandLine* command_line) override { | 416 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 387 command_line->AppendSwitch(switches::kEnablePdfMaterialUI); | 417 command_line->AppendSwitch(switches::kEnablePdfMaterialUI); |
| 388 } | 418 } |
| 389 }; | 419 }; |
| 390 | 420 |
| 391 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) { | 421 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Basic) { |
| 392 RunTestsInFile("basic_test_material.js", "test.pdf"); | 422 RunTestsInFile("basic_test_material.js", "test.pdf"); |
| 393 } | 423 } |
| 394 | 424 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 RunTestsInFile("title_test.js", "test-title.pdf"); | 460 RunTestsInFile("title_test.js", "test-title.pdf"); |
| 431 } | 461 } |
| 432 | 462 |
| 433 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, WhitespaceTitle) { | 463 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, WhitespaceTitle) { |
| 434 RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf"); | 464 RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf"); |
| 435 } | 465 } |
| 436 | 466 |
| 437 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, PageChange) { | 467 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, PageChange) { |
| 438 RunTestsInFile("page_change_test.js", "test-bookmarks.pdf"); | 468 RunTestsInFile("page_change_test.js", "test-bookmarks.pdf"); |
| 439 } | 469 } |
| OLD | NEW |