| 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> |
| 6 |
| 5 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 6 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/hash.h" | 10 #include "base/hash.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" |
| 9 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/component_loader.h" | 16 #include "chrome/browser/extensions/component_loader.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 17 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/plugins/plugin_prefs.h" |
| 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/chrome_content_client.h" |
| 14 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/browser_plugin_guest_manager.h" | 27 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 28 #include "content/public/browser/download_item.h" |
| 29 #include "content/public/browser/download_manager.h" |
| 30 #include "content/public/browser/notification_observer.h" |
| 31 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/plugin_service.h" | 32 #include "content/public/browser/plugin_service.h" |
| 33 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 34 #include "content/public/test/browser_test_utils.h" |
| 20 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 36 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 22 #include "extensions/test/result_catcher.h" | 37 #include "extensions/test/result_catcher.h" |
| 23 #include "grit/component_extension_resources.h" | 38 #include "grit/component_extension_resources.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "url/gurl.h" |
| 26 | 42 |
| 27 const int kNumberLoadTestParts = 10; | 43 const int kNumberLoadTestParts = 10; |
| 28 | 44 |
| 29 class PDFExtensionTest : public ExtensionApiTest, | 45 class PDFExtensionTest : public ExtensionApiTest, |
| 30 public testing::WithParamInterface<int> { | 46 public testing::WithParamInterface<int> { |
| 31 public: | 47 public: |
| 32 ~PDFExtensionTest() override {} | 48 ~PDFExtensionTest() override {} |
| 33 | 49 |
| 34 void SetUpCommandLine(base::CommandLine* command_line) override { | 50 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 35 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); | 51 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 176 |
| 161 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { | 177 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { |
| 162 #if defined(GOOGLE_CHROME_BUILD) | 178 #if defined(GOOGLE_CHROME_BUILD) |
| 163 // Load private PDFs. | 179 // Load private PDFs. |
| 164 LoadAllPdfsTest("pdf_private", GetParam()); | 180 LoadAllPdfsTest("pdf_private", GetParam()); |
| 165 #endif | 181 #endif |
| 166 // Load public PDFs. | 182 // Load public PDFs. |
| 167 LoadAllPdfsTest("pdf", GetParam()); | 183 LoadAllPdfsTest("pdf", GetParam()); |
| 168 } | 184 } |
| 169 | 185 |
| 186 class DisablePluginHelper : public content::DownloadManager::Observer, |
| 187 public content::NotificationObserver { |
| 188 public: |
| 189 DisablePluginHelper() {} |
| 190 |
| 191 virtual ~DisablePluginHelper() {} |
| 192 |
| 193 void DisablePlugin(Profile* profile) { |
| 194 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 195 content::Source<Profile>(profile)); |
| 196 scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile)); |
| 197 DCHECK(prefs.get()); |
| 198 prefs->EnablePluginGroup( |
| 199 false, base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName)); |
| 200 // Wait until the plugin has been disabled. |
| 201 run_loop_.Run(); |
| 202 } |
| 203 |
| 204 const GURL& GetLastUrl() { |
| 205 // Wait until the download has been created. |
| 206 run_loop_.Run(); |
| 207 return last_url_; |
| 208 } |
| 209 |
| 210 // content::DownloadManager::Observer implementation. |
| 211 void OnDownloadCreated(content::DownloadManager* manager, |
| 212 content::DownloadItem* item) override { |
| 213 last_url_ = item->GetURL(); |
| 214 run_loop_.Quit(); |
| 215 } |
| 216 |
| 217 // content::NotificationObserver implementation. |
| 218 void Observe(int type, |
| 219 const content::NotificationSource& source, |
| 220 const content::NotificationDetails& details) override { |
| 221 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 222 run_loop_.Quit(); |
| 223 } |
| 224 |
| 225 private: |
| 226 content::NotificationRegistrar registrar_; |
| 227 base::RunLoop run_loop_; |
| 228 GURL last_url_; |
| 229 }; |
| 230 |
| 231 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) { |
| 232 // Disable the PDF plugin. |
| 233 content::WebContents* web_contents = |
| 234 browser()->tab_strip_model()->GetActiveWebContents(); |
| 235 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 236 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 237 DisablePluginHelper helper; |
| 238 helper.DisablePlugin(profile); |
| 239 |
| 240 // Register a download observer. |
| 241 content::DownloadManager* download_manager = |
| 242 content::BrowserContext::GetDownloadManager(browser_context); |
| 243 download_manager->AddObserver(&helper); |
| 244 |
| 245 // Navigate to a PDF and test that it is downloaded. |
| 246 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf")); |
| 247 ui_test_utils::NavigateToURL(browser(), url); |
| 248 ASSERT_EQ(url, helper.GetLastUrl()); |
| 249 |
| 250 // Cancel the download to shutdown cleanly. |
| 251 download_manager->RemoveObserver(&helper); |
| 252 std::vector<content::DownloadItem*> downloads; |
| 253 download_manager->GetAllDownloads(&downloads); |
| 254 ASSERT_EQ(1u, downloads.size()); |
| 255 downloads[0]->Cancel(false); |
| 256 } |
| 257 |
| 170 // We break PDFTest.Load up into kNumberLoadTestParts. | 258 // We break PDFTest.Load up into kNumberLoadTestParts. |
| 171 INSTANTIATE_TEST_CASE_P(PDFTestFiles, | 259 INSTANTIATE_TEST_CASE_P(PDFTestFiles, |
| 172 PDFExtensionTest, | 260 PDFExtensionTest, |
| 173 testing::Range(0, kNumberLoadTestParts)); | 261 testing::Range(0, kNumberLoadTestParts)); |
| 174 | 262 |
| 175 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 263 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
| 176 RunTestsInFile("basic_test.js", "test.pdf"); | 264 RunTestsInFile("basic_test.js", "test.pdf"); |
| 177 } | 265 } |
| 178 | 266 |
| 179 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 267 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 RunTestsInFile("navigator_test.js", "test.pdf"); | 314 RunTestsInFile("navigator_test.js", "test.pdf"); |
| 227 } | 315 } |
| 228 | 316 |
| 229 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { | 317 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { |
| 230 RunTestsInFile("params_parser_test.js", "test.pdf"); | 318 RunTestsInFile("params_parser_test.js", "test.pdf"); |
| 231 } | 319 } |
| 232 | 320 |
| 233 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { | 321 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { |
| 234 RunTestsInFile("zoom_manager_test.js", "test.pdf"); | 322 RunTestsInFile("zoom_manager_test.js", "test.pdf"); |
| 235 } | 323 } |
| OLD | NEW |