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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/files/file_enumerator.h" | 6 #include "base/files/file_enumerator.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "chrome/browser/extensions/component_loader.h" | 10 #include "chrome/browser/extensions/component_loader.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/pdf/pdf_extension_test_util.h" |
| 14 #include "chrome/browser/pdf/pdf_extension_util.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/browser_plugin_guest_manager.h" | 19 #include "content/public/browser/browser_plugin_guest_manager.h" |
18 #include "content/public/browser/plugin_service.h" | 20 #include "content/public/browser/plugin_service.h" |
19 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
20 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
21 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 23 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
22 #include "extensions/test/result_catcher.h" | 24 #include "extensions/test/result_catcher.h" |
23 #include "grit/component_extension_resources.h" | |
24 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
25 #include "ui/base/resource/resource_bundle.h" | |
26 | 26 |
27 const int kNumberLoadTestParts = 10; | 27 const int kNumberLoadTestParts = 10; |
28 | 28 |
29 class PDFExtensionTest : public ExtensionApiTest, | 29 class PDFExtensionTest : public ExtensionApiTest, |
30 public testing::WithParamInterface<int> { | 30 public testing::WithParamInterface<int> { |
31 public: | 31 public: |
32 ~PDFExtensionTest() override {} | 32 ~PDFExtensionTest() override {} |
33 | 33 |
34 void SetUpCommandLine(base::CommandLine* command_line) override { | 34 void SetUpCommandLine(base::CommandLine* command_line) override { |
35 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); | 35 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has | 104 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has |
105 // finished loading. Return true if it loads successfully or false if it | 105 // finished loading. Return true if it loads successfully or false if it |
106 // fails. If it doesn't finish loading the test will hang. This is done from | 106 // fails. If it doesn't finish loading the test will hang. This is done from |
107 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works | 107 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works |
108 // correctly from there. | 108 // correctly from there. |
109 bool LoadPdf(const GURL& url) { | 109 bool LoadPdf(const GURL& url) { |
110 ui_test_utils::NavigateToURL(browser(), url); | 110 ui_test_utils::NavigateToURL(browser(), url); |
111 content::WebContents* web_contents = | 111 content::WebContents* web_contents = |
112 browser()->tab_strip_model()->GetActiveWebContents(); | 112 browser()->tab_strip_model()->GetActiveWebContents(); |
113 std::string scripting_api_js = | 113 return pdf_extension_test_util::EnsurePDFHasLoaded(web_contents); |
114 ResourceBundle::GetSharedInstance() | |
115 .GetRawDataResource(IDR_PDF_PDF_SCRIPTING_API_JS) | |
116 .as_string(); | |
117 CHECK(content::ExecuteScript(web_contents, scripting_api_js)); | |
118 | |
119 bool load_success = false; | |
120 CHECK(content::ExecuteScriptAndExtractBool( | |
121 web_contents, | |
122 "var scriptingAPI = new PDFScriptingAPI(window, " | |
123 " document.getElementsByTagName('embed')[0]);" | |
124 "scriptingAPI.setLoadCallback(function(success) {" | |
125 " window.domAutomationController.send(success);" | |
126 "});", | |
127 &load_success)); | |
128 return load_success; | |
129 } | 114 } |
130 | 115 |
131 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs | 116 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs |
132 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order | 117 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order |
133 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). | 118 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). |
134 void LoadAllPdfsTest(const std::string& dir_name, int k) { | 119 void LoadAllPdfsTest(const std::string& dir_name, int k) { |
135 base::FilePath test_data_dir; | 120 base::FilePath test_data_dir; |
136 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 121 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
137 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), | 122 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), |
138 false, base::FileEnumerator::FILES, | 123 false, base::FileEnumerator::FILES, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 217 |
233 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { | 218 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { |
234 RunTestsInFile("zoom_manager_test.js", "test.pdf"); | 219 RunTestsInFile("zoom_manager_test.js", "test.pdf"); |
235 } | 220 } |
236 | 221 |
237 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ElementsTest) { | 222 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ElementsTest) { |
238 // Although this test file does not require a PDF to be loaded, loading the | 223 // Although this test file does not require a PDF to be loaded, loading the |
239 // elements without loading a PDF is difficult. | 224 // elements without loading a PDF is difficult. |
240 RunTestsInFile("material_elements_test.js", "test.pdf"); | 225 RunTestsInFile("material_elements_test.js", "test.pdf"); |
241 } | 226 } |
OLD | NEW |