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

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
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"
10 #include "chrome/browser/extensions/component_loader.h" 15 #include "chrome/browser/extensions/component_loader.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 16 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/plugins/plugin_prefs.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_content_client.h"
14 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/browser_plugin_guest_manager.h" 26 #include "content/public/browser/browser_plugin_guest_manager.h"
27 #include "content/public/browser/download_item.h"
28 #include "content/public/browser/download_manager.h"
18 #include "content/public/browser/plugin_service.h" 29 #include "content/public/browser/plugin_service.h"
30 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h" 31 #include "content/public/test/browser_test_utils.h"
20 #include "extensions/browser/extension_registry.h" 32 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/manifest_handlers/mime_types_handler.h" 33 #include "extensions/common/manifest_handlers/mime_types_handler.h"
22 #include "extensions/test/result_catcher.h" 34 #include "extensions/test/result_catcher.h"
23 #include "grit/component_extension_resources.h" 35 #include "grit/component_extension_resources.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
25 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
38 #include "url/gurl.h"
26 39
27 const int kNumberLoadTestParts = 10; 40 const int kNumberLoadTestParts = 10;
28 41
29 class PDFExtensionTest : public ExtensionApiTest, 42 class PDFExtensionTest : public ExtensionApiTest,
30 public testing::WithParamInterface<int> { 43 public testing::WithParamInterface<int> {
31 public: 44 public:
32 ~PDFExtensionTest() override {} 45 ~PDFExtensionTest() override {}
33 46
34 void SetUpCommandLine(base::CommandLine* command_line) override { 47 void SetUpCommandLine(base::CommandLine* command_line) override {
35 command_line->AppendSwitch(switches::kDisablePdfMaterialUI); 48 command_line->AppendSwitch(switches::kDisablePdfMaterialUI);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 173
161 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 174 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
162 #if defined(GOOGLE_CHROME_BUILD) 175 #if defined(GOOGLE_CHROME_BUILD)
163 // Load private PDFs. 176 // Load private PDFs.
164 LoadAllPdfsTest("pdf_private", GetParam()); 177 LoadAllPdfsTest("pdf_private", GetParam());
165 #endif 178 #endif
166 // Load public PDFs. 179 // Load public PDFs.
167 LoadAllPdfsTest("pdf", GetParam()); 180 LoadAllPdfsTest("pdf", GetParam());
168 } 181 }
169 182
183 class TestDownloadObserver : public content::DownloadManager::Observer {
184 public:
185 TestDownloadObserver() {}
186 virtual ~TestDownloadObserver() {}
187
188 GURL GetLastUrl() {
mmenke 2015/07/09 20:35:39 nit: const GURL& last_url() const
raymes 2015/07/17 03:21:00 Done.
189 return url_;
mmenke 2015/07/09 20:35:39 nit: url_ -> last_url_?
raymes 2015/07/17 03:21:00 Done.
190 }
191
192 // content::DownloadManager::Observer implementation
193 void OnDownloadCreated(content::DownloadManager* manager,
194 content::DownloadItem* item) override {
195 url_ = item->GetURL();
196 }
197
198 private:
199 GURL url_;
200 };
201
202 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
203 // Disable the PDF plugin.
204 content::WebContents* web_contents =
205 browser()->tab_strip_model()->GetActiveWebContents();
206 content::BrowserContext* browser_context = web_contents->GetBrowserContext();
207 Profile* profile = Profile::FromBrowserContext(browser_context);
208 scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile));
209 ASSERT_TRUE(prefs.get());
210 prefs->EnablePluginGroup(false,
211 base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName));
212
213 // Register a download observer.
214 content::DownloadManager* download_manager =
215 content::BrowserContext::GetDownloadManager(browser_context);
216 TestDownloadObserver download_observer;
217 download_manager->AddObserver(&download_observer);
218
219 // Navigate to a PDF and test that it is downloaded.
220 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf"));
221 ui_test_utils::NavigateToURL(browser(), url);
222 ASSERT_EQ(url, download_observer.GetLastUrl());
mmenke 2015/07/09 20:35:39 Right...But the download is not considered part of
raymes 2015/07/17 03:21:00 I agree with you, it's not completely clear whethe
223
224 // Cancel the download to shutdown cleanly.
225 download_manager->RemoveObserver(&download_observer);
226 std::vector<content::DownloadItem*> downloads;
227 download_manager->GetAllDownloads(&downloads);
228 ASSERT_EQ(1u, downloads.size());
229 downloads[0]->Cancel(false);
230 }
231
170 // We break PDFTest.Load up into kNumberLoadTestParts. 232 // We break PDFTest.Load up into kNumberLoadTestParts.
171 INSTANTIATE_TEST_CASE_P(PDFTestFiles, 233 INSTANTIATE_TEST_CASE_P(PDFTestFiles,
172 PDFExtensionTest, 234 PDFExtensionTest,
173 testing::Range(0, kNumberLoadTestParts)); 235 testing::Range(0, kNumberLoadTestParts));
174 236
175 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { 237 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) {
176 RunTestsInFile("basic_test.js", "test.pdf"); 238 RunTestsInFile("basic_test.js", "test.pdf");
177 } 239 }
178 240
179 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { 241 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 RunTestsInFile("navigator_test.js", "test.pdf"); 288 RunTestsInFile("navigator_test.js", "test.pdf");
227 } 289 }
228 290
229 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { 291 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) {
230 RunTestsInFile("params_parser_test.js", "test.pdf"); 292 RunTestsInFile("params_parser_test.js", "test.pdf");
231 } 293 }
232 294
233 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { 295 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) {
234 RunTestsInFile("zoom_manager_test.js", "test.pdf"); 296 RunTestsInFile("zoom_manager_test.js", "test.pdf");
235 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698