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

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, 6 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 "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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 161
158 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 162 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
159 #if defined(GOOGLE_CHROME_BUILD) 163 #if defined(GOOGLE_CHROME_BUILD)
160 // Load private PDFs. 164 // Load private PDFs.
161 LoadAllPdfsTest("pdf_private", GetParam()); 165 LoadAllPdfsTest("pdf_private", GetParam());
162 #endif 166 #endif
163 // Load public PDFs. 167 // Load public PDFs.
164 LoadAllPdfsTest("pdf", GetParam()); 168 LoadAllPdfsTest("pdf", GetParam());
165 } 169 }
166 170
171 class TestDownloadObserver : public content::DownloadManager::Observer {
172 public:
173 TestDownloadObserver() {}
174 virtual ~TestDownloadObserver() {}
175
176 GURL GetAndClearLastUrl() {
177 GURL result = url_;
178 url_ = GURL();
mmenke 2015/06/11 19:38:04 Is there a reason we need to clear the URL? Shoul
raymes 2015/07/01 05:13:18 Done.
179 return result;
180 }
181
182 void OnDownloadCreated(content::DownloadManager* manager,
mmenke 2015/06/11 19:38:04 Maybe add something like: // content::DownloadMan
raymes 2015/07/01 05:13:17 Done.
183 content::DownloadItem* item) override {
mmenke 2015/06/11 19:38:04 Should include download_item.h
raymes 2015/07/01 05:13:18 Done.
184 CHECK(url_.is_empty());
185 url_ = item->GetURL();
186 CHECK(!url_.is_empty());
mmenke 2015/06/11 19:38:03 Need to include base/logging.h for CHECK, and url/
raymes 2015/07/01 05:13:18 Done.
187 }
188
189 private:
190 GURL url_;
191 };
192
193 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
194 // Disable the PDF plugin.
195 content::WebContents* web_contents =
196 browser()->tab_strip_model()->GetActiveWebContents();
mmenke 2015/06/11 19:38:03 Need to include the browser and tab string model h
raymes 2015/07/01 05:13:18 Done.
197 content::BrowserContext* browser_context = web_contents->GetBrowserContext();
mmenke 2015/06/11 19:38:03 Need the web_contents header.
raymes 2015/07/01 05:13:18 Done.
198 Profile* profile = Profile::FromBrowserContext(browser_context);
mmenke 2015/06/11 19:38:04 Need to include the profile header.
raymes 2015/07/01 05:13:18 Done.
199 scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile));
mmenke 2015/06/11 19:38:03 Include ref_counted.h?
raymes 2015/07/01 05:13:18 Done.
200 ASSERT_TRUE(prefs.get());
201 prefs->EnablePluginGroup(false,
202 base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName));
203
204 // Register a download observer.
205 content::DownloadManager* download_manager =
206 content::BrowserContext::GetDownloadManager(browser_context);
207 TestDownloadObserver download_observer;
208 download_manager->AddObserver(&download_observer);
209
210 // Navigate to a PDF and test that it is downloaded.
211 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf"));
212 ui_test_utils::NavigateToURL(browser(), url);
213 ASSERT_EQ(url, download_observer.GetAndClearLastUrl());
mmenke 2015/06/11 19:38:03 I'm not sufficiently familiar with navigation/down
raymes 2015/07/01 05:13:18 The comment in NavigateToURL says: // Navigates th
214
215 // Cancel the download to shutdown cleanly.
216 download_manager->RemoveObserver(&download_observer);
217 std::vector<content::DownloadItem*> downloads;
mmenke 2015/06/11 19:38:03 include <vector>
raymes 2015/07/01 05:13:18 Done.
218 download_manager->GetAllDownloads(&downloads);
219 ASSERT_EQ(1u, downloads.size());
220 downloads[0]->Cancel(false);
221 }
222
167 // We break PDFTest.Load up into kNumberLoadTestParts. 223 // We break PDFTest.Load up into kNumberLoadTestParts.
168 INSTANTIATE_TEST_CASE_P(PDFTestFiles, 224 INSTANTIATE_TEST_CASE_P(PDFTestFiles,
169 PDFExtensionTest, 225 PDFExtensionTest,
170 testing::Range(0, kNumberLoadTestParts)); 226 testing::Range(0, kNumberLoadTestParts));
171 227
172 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { 228 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) {
173 RunTestsInFile("basic_test.js", "test.pdf"); 229 RunTestsInFile("basic_test.js", "test.pdf");
174 } 230 }
175 231
176 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { 232 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 RunTestsInFile("navigator_test.js", "test.pdf"); 279 RunTestsInFile("navigator_test.js", "test.pdf");
224 } 280 }
225 281
226 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) { 282 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ParamsParser) {
227 RunTestsInFile("params_parser_test.js", "test.pdf"); 283 RunTestsInFile("params_parser_test.js", "test.pdf");
228 } 284 }
229 285
230 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) { 286 IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, ZoomManager) {
231 RunTestsInFile("zoom_manager_test.js", "test.pdf"); 287 RunTestsInFile("zoom_manager_test.js", "test.pdf");
232 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698