Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/pdf/pdf_extension_test.cc

Issue 1164073006: Make the logic for stream interception by MimeHandlerViews consistent with starting the plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "chrome/browser/pdf/pdf_extension_test_util.h" 19 #include "chrome/browser/pdf/pdf_extension_test_util.h"
14 #include "chrome/browser/pdf/pdf_extension_util.h" 20 #include "chrome/browser/pdf/pdf_extension_util.h"
21 #include "chrome/browser/plugins/plugin_prefs.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/chrome_content_client.h"
16 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
19 #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"
31 #include "content/public/browser/download_manager.h"
32 #include "content/public/browser/notification_observer.h"
33 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/plugin_service.h" 34 #include "content/public/browser/plugin_service.h"
35 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h" 36 #include "content/public/test/browser_test_utils.h"
22 #include "extensions/browser/extension_registry.h" 37 #include "extensions/browser/extension_registry.h"
23 #include "extensions/common/manifest_handlers/mime_types_handler.h" 38 #include "extensions/common/manifest_handlers/mime_types_handler.h"
24 #include "extensions/test/result_catcher.h" 39 #include "extensions/test/result_catcher.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h" 40 #include "net/test/embedded_test_server/embedded_test_server.h"
41 #include "ui/base/resource/resource_bundle.h"
42 #include "url/gurl.h"
26 43
27 const int kNumberLoadTestParts = 10; 44 const int kNumberLoadTestParts = 10;
28 45
29 class PDFExtensionTest : public ExtensionApiTest, 46 class PDFExtensionTest : public ExtensionApiTest,
30 public testing::WithParamInterface<int> { 47 public testing::WithParamInterface<int> {
31 public: 48 public:
32 ~PDFExtensionTest() override {} 49 ~PDFExtensionTest() override {}
33 50
34 void SetUpCommandLine(base::CommandLine* command_line) override { 51 void SetUpCommandLine(base::CommandLine* command_line) override {
35 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); 52 command_line->AppendSwitch(switches::kDisablePdfMaterialUI);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 162
146 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 163 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
147 #if defined(GOOGLE_CHROME_BUILD) 164 #if defined(GOOGLE_CHROME_BUILD)
148 // Load private PDFs. 165 // Load private PDFs.
149 LoadAllPdfsTest("pdf_private", GetParam()); 166 LoadAllPdfsTest("pdf_private", GetParam());
150 #endif 167 #endif
151 // Load public PDFs. 168 // Load public PDFs.
152 LoadAllPdfsTest("pdf", GetParam()); 169 LoadAllPdfsTest("pdf", GetParam());
153 } 170 }
154 171
172 class DisablePluginHelper : public content::DownloadManager::Observer,
173 public content::NotificationObserver {
174 public:
175 DisablePluginHelper() {}
176
177 virtual ~DisablePluginHelper() {}
178
179 void DisablePlugin(Profile* profile) {
180 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
181 content::Source<Profile>(profile));
182 scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile));
183 DCHECK(prefs.get());
184 prefs->EnablePluginGroup(
185 false, base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName));
186 // Wait until the plugin has been disabled.
187 disable_run_loop_.Run();
188 }
189
190 const GURL& GetLastUrl() {
191 // Wait until the download has been created.
192 download_run_loop_.Run();
193 return last_url_;
194 }
195
196 // content::DownloadManager::Observer implementation.
197 void OnDownloadCreated(content::DownloadManager* manager,
198 content::DownloadItem* item) override {
199 last_url_ = item->GetURL();
200 download_run_loop_.Quit();
201 }
202
203 // content::NotificationObserver implementation.
204 void Observe(int type,
205 const content::NotificationSource& source,
206 const content::NotificationDetails& details) override {
207 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
208 disable_run_loop_.Quit();
209 }
210
211 private:
212 content::NotificationRegistrar registrar_;
213 base::RunLoop disable_run_loop_;
214 base::RunLoop download_run_loop_;
215 GURL last_url_;
216 };
217
218 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
219 // Disable the PDF plugin.
220 content::WebContents* web_contents =
221 browser()->tab_strip_model()->GetActiveWebContents();
222 content::BrowserContext* browser_context = web_contents->GetBrowserContext();
223 Profile* profile = Profile::FromBrowserContext(browser_context);
224 DisablePluginHelper helper;
225 helper.DisablePlugin(profile);
226
227 // Register a download observer.
228 content::DownloadManager* download_manager =
229 content::BrowserContext::GetDownloadManager(browser_context);
230 download_manager->AddObserver(&helper);
231
232 // Navigate to a PDF and test that it is downloaded.
233 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf"));
234 ui_test_utils::NavigateToURL(browser(), url);
235 ASSERT_EQ(url, helper.GetLastUrl());
236
237 // Cancel the download to shutdown cleanly.
238 download_manager->RemoveObserver(&helper);
239 std::vector<content::DownloadItem*> downloads;
240 download_manager->GetAllDownloads(&downloads);
241 ASSERT_EQ(1u, downloads.size());
242 downloads[0]->Cancel(false);
243 }
244
155 // We break PDFTest.Load up into kNumberLoadTestParts. 245 // We break PDFTest.Load up into kNumberLoadTestParts.
156 INSTANTIATE_TEST_CASE_P(PDFTestFiles, 246 INSTANTIATE_TEST_CASE_P(PDFTestFiles,
157 PDFExtensionTest, 247 PDFExtensionTest,
158 testing::Range(0, kNumberLoadTestParts)); 248 testing::Range(0, kNumberLoadTestParts));
159 249
160 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { 250 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) {
161 RunTestsInFile("basic_test.js", "test.pdf"); 251 RunTestsInFile("basic_test.js", "test.pdf");
162 } 252 }
163 253
164 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { 254 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 307
218 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { 308 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) {
219 RunTestsInFile("zoom_manager_test.js", "test.pdf"); 309 RunTestsInFile("zoom_manager_test.js", "test.pdf");
220 } 310 }
221 311
222 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ElementsTest) { 312 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ElementsTest) {
223 // Although this test file does not require a PDF to be loaded, loading the 313 // Although this test file does not require a PDF to be loaded, loading the
224 // elements without loading a PDF is difficult. 314 // elements without loading a PDF is difficult.
225 RunTestsInFile("material_elements_test.js", "test.pdf"); 315 RunTestsInFile("material_elements_test.js", "test.pdf");
226 } 316 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698