| 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 "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/component_loader.h" | 11 #include "chrome/browser/extensions/component_loader.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/plugins/plugin_prefs.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/chrome_content_client.h" |
| 14 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/browser_plugin_guest_manager.h" | 20 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 21 #include "content/public/browser/download_manager.h" |
| 18 #include "content/public/browser/plugin_service.h" | 22 #include "content/public/browser/plugin_service.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 20 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 25 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 22 #include "extensions/test/result_catcher.h" | 26 #include "extensions/test/result_catcher.h" |
| 23 #include "grit/component_extension_resources.h" | 27 #include "grit/component_extension_resources.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 26 | 30 |
| 27 const int kNumberLoadTestParts = 10; | 31 const int kNumberLoadTestParts = 10; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 159 |
| 156 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { | 160 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { |
| 157 #if defined(GOOGLE_CHROME_BUILD) | 161 #if defined(GOOGLE_CHROME_BUILD) |
| 158 // Load private PDFs. | 162 // Load private PDFs. |
| 159 LoadAllPdfsTest("pdf_private", GetParam()); | 163 LoadAllPdfsTest("pdf_private", GetParam()); |
| 160 #endif | 164 #endif |
| 161 // Load public PDFs. | 165 // Load public PDFs. |
| 162 LoadAllPdfsTest("pdf", GetParam()); | 166 LoadAllPdfsTest("pdf", GetParam()); |
| 163 } | 167 } |
| 164 | 168 |
| 169 class TestDownloadObserver : public content::DownloadManager::Observer { |
| 170 public: |
| 171 TestDownloadObserver() {} |
| 172 virtual ~TestDownloadObserver() {} |
| 173 |
| 174 GURL GetAndClearLastUrl() { |
| 175 GURL result = url_; |
| 176 url_ = GURL(); |
| 177 return result; |
| 178 } |
| 179 |
| 180 void OnDownloadCreated(content::DownloadManager* manager, |
| 181 content::DownloadItem* item) override { |
| 182 CHECK(url_.is_empty()); |
| 183 url_ = item->GetURL(); |
| 184 CHECK(!url_.is_empty()); |
| 185 } |
| 186 |
| 187 private: |
| 188 GURL url_; |
| 189 }; |
| 190 |
| 191 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) { |
| 192 // Disable the PDF plugin. |
| 193 content::WebContents* web_contents = |
| 194 browser()->tab_strip_model()->GetActiveWebContents(); |
| 195 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 196 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 197 scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile)); |
| 198 ASSERT_TRUE(prefs.get()); |
| 199 prefs->EnablePluginGroup(false, |
| 200 base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName)); |
| 201 |
| 202 // Register a download observer. |
| 203 content::DownloadManager* download_manager = |
| 204 content::BrowserContext::GetDownloadManager(browser_context); |
| 205 TestDownloadObserver download_observer; |
| 206 download_manager->AddObserver(&download_observer); |
| 207 |
| 208 // Navigate to a PDF and test that it is downloaded. |
| 209 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf")); |
| 210 ui_test_utils::NavigateToURL(browser(), url); |
| 211 ASSERT_EQ(url, download_observer.GetAndClearLastUrl()); |
| 212 |
| 213 // Cancel the download to shutdown cleanly. |
| 214 download_manager->RemoveObserver(&download_observer); |
| 215 std::vector<content::DownloadItem*> downloads; |
| 216 download_manager->GetAllDownloads(&downloads); |
| 217 ASSERT_EQ(1u, downloads.size()); |
| 218 downloads[0]->Cancel(false); |
| 219 } |
| 220 |
| 165 // We break PDFTest.Load up into kNumberLoadTestParts. | 221 // We break PDFTest.Load up into kNumberLoadTestParts. |
| 166 INSTANTIATE_TEST_CASE_P(PDFTestFiles, | 222 INSTANTIATE_TEST_CASE_P(PDFTestFiles, |
| 167 PDFExtensionTest, | 223 PDFExtensionTest, |
| 168 testing::Range(0, kNumberLoadTestParts)); | 224 testing::Range(0, kNumberLoadTestParts)); |
| 169 | 225 |
| 170 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 226 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
| 171 RunTestsInFile("basic_test.js", "test.pdf"); | 227 RunTestsInFile("basic_test.js", "test.pdf"); |
| 172 } | 228 } |
| 173 | 229 |
| 174 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 230 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 RunTestsInFile("navigator_test.js", "test.pdf"); | 277 RunTestsInFile("navigator_test.js", "test.pdf"); |
| 222 } | 278 } |
| 223 | 279 |
| 224 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { | 280 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { |
| 225 RunTestsInFile("params_parser_test.js", "test.pdf"); | 281 RunTestsInFile("params_parser_test.js", "test.pdf"); |
| 226 } | 282 } |
| 227 | 283 |
| 228 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { | 284 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { |
| 229 RunTestsInFile("zoom_manager_test.js", "test.pdf"); | 285 RunTestsInFile("zoom_manager_test.js", "test.pdf"); |
| 230 } | 286 } |
| OLD | NEW |