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

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

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/hash.h" 12 #include "base/hash.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/pattern.h" 17 #include "base/strings/pattern.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/thread_restrictions.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/extensions/component_loader.h" 22 #include "chrome/browser/extensions/component_loader.h"
22 #include "chrome/browser/extensions/extension_apitest.h" 23 #include "chrome/browser/extensions/extension_apitest.h"
23 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/pdf/pdf_extension_test_util.h" 25 #include "chrome/browser/pdf/pdf_extension_test_util.h"
25 #include "chrome/browser/pdf/pdf_extension_util.h" 26 #include "chrome/browser/pdf/pdf_extension_util.h"
26 #include "chrome/browser/plugins/plugin_prefs.h" 27 #include "chrome/browser/plugins/plugin_prefs.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 135
135 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); 136 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename));
136 137
137 // It should be good enough to just navigate to the URL. But loading up the 138 // It should be good enough to just navigate to the URL. But loading up the
138 // BrowserPluginGuest seems to happen asynchronously as there was flakiness 139 // BrowserPluginGuest seems to happen asynchronously as there was flakiness
139 // being seen due to the BrowserPluginGuest not being available yet (see 140 // being seen due to the BrowserPluginGuest not being available yet (see
140 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is 141 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is
141 // loaded before continuing. 142 // loaded before continuing.
142 WebContents* guest_contents = LoadPdfGetGuestContents(url); 143 WebContents* guest_contents = LoadPdfGetGuestContents(url);
143 ASSERT_TRUE(guest_contents); 144 ASSERT_TRUE(guest_contents);
145 std::string test_util_js;
144 146
145 base::FilePath test_data_dir; 147 {
146 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 148 base::ThreadRestrictions::ScopedAllowIO allow_io;
147 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); 149 base::FilePath test_data_dir;
148 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js"); 150 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
149 std::string test_util_js; 151 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf"));
150 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js)); 152 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js");
153 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js));
151 154
152 base::FilePath test_file_path = test_data_dir.AppendASCII(filename); 155 base::FilePath test_file_path = test_data_dir.AppendASCII(filename);
153 std::string test_js; 156 std::string test_js;
154 ASSERT_TRUE(base::ReadFileToString(test_file_path, &test_js)); 157 ASSERT_TRUE(base::ReadFileToString(test_file_path, &test_js));
155 158
156 test_util_js.append(test_js); 159 test_util_js.append(test_js);
160 }
161
157 ASSERT_TRUE(content::ExecuteScript(guest_contents, test_util_js)); 162 ASSERT_TRUE(content::ExecuteScript(guest_contents, test_util_js));
158 163
159 if (!catcher.GetNextResult()) 164 if (!catcher.GetNextResult())
160 FAIL() << catcher.message(); 165 FAIL() << catcher.message();
161 } 166 }
162 167
163 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has 168 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has
164 // finished loading. Return true if it loads successfully or false if it 169 // finished loading. Return true if it loads successfully or false if it
165 // fails. If it doesn't finish loading the test will hang. This is done from 170 // fails. If it doesn't finish loading the test will hang. This is done from
166 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works 171 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works
(...skipping 14 matching lines...) Expand all
181 content::BrowserPluginGuestManager* guest_manager = 186 content::BrowserPluginGuestManager* guest_manager =
182 contents->GetBrowserContext()->GetGuestManager(); 187 contents->GetBrowserContext()->GetGuestManager();
183 WebContents* guest_contents = guest_manager->GetFullPageGuest(contents); 188 WebContents* guest_contents = guest_manager->GetFullPageGuest(contents);
184 return guest_contents; 189 return guest_contents;
185 } 190 }
186 191
187 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs 192 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs
188 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order 193 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order
189 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). 194 // to shard the files evenly across values of k in [0, kNumberLoadTestParts).
190 void LoadAllPdfsTest(const std::string& dir_name, int k) { 195 void LoadAllPdfsTest(const std::string& dir_name, int k) {
196 base::ThreadRestrictions::ScopedAllowIO allow_io;
191 base::FilePath test_data_dir; 197 base::FilePath test_data_dir;
192 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 198 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
193 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), 199 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name),
194 false, base::FileEnumerator::FILES, 200 false, base::FileEnumerator::FILES,
195 FILE_PATH_LITERAL("*.pdf")); 201 FILE_PATH_LITERAL("*.pdf"));
196 202
197 size_t count = 0; 203 size_t count = 0;
198 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); 204 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
199 file_path = file_enumerator.Next()) { 205 file_path = file_enumerator.Next()) {
200 std::string filename = file_path.BaseName().MaybeAsASCII(); 206 std::string filename = file_path.BaseName().MaybeAsASCII();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 GURL forbiddenUrl( 471 GURL forbiddenUrl(
466 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" 472 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?"
467 "https://example.com/notrequested.pdf"); 473 "https://example.com/notrequested.pdf");
468 ui_test_utils::NavigateToURL(browser(), forbiddenUrl); 474 ui_test_utils::NavigateToURL(browser(), forbiddenUrl);
469 475
470 console_delegate->Wait(); 476 console_delegate->Wait();
471 } 477 }
472 478
473 // This test ensures that PDF can be loaded from local file 479 // This test ensures that PDF can be loaded from local file
474 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) { 480 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) {
475 base::FilePath test_data_dir; 481 GURL test_pdf_url;
476 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 482 {
477 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); 483 base::ThreadRestrictions::ScopedAllowIO allow_io;
478 base::FilePath test_data_file = test_data_dir.AppendASCII("test.pdf"); 484 base::FilePath test_data_dir;
479 ASSERT_TRUE(PathExists(test_data_file)); 485 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
480 GURL test_pdf_url("file://" + test_data_file.MaybeAsASCII()); 486 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf"));
487 base::FilePath test_data_file = test_data_dir.AppendASCII("test.pdf");
488 ASSERT_TRUE(PathExists(test_data_file));
489 test_pdf_url = GURL("file://" + test_data_file.MaybeAsASCII());
490 }
481 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 491 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
482 ASSERT_TRUE(guest_contents); 492 ASSERT_TRUE(guest_contents);
483 } 493 }
484 494
485 // This test ensures that link permissions are enforced properly in PDFs. 495 // This test ensures that link permissions are enforced properly in PDFs.
486 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkPermissions) { 496 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkPermissions) {
487 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); 497 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
488 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 498 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
489 ASSERT_TRUE(guest_contents); 499 ASSERT_TRUE(guest_contents);
490 500
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenFromFTP) { 1024 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenFromFTP) {
1015 net::SpawnedTestServer ftp_server( 1025 net::SpawnedTestServer ftp_server(
1016 net::SpawnedTestServer::TYPE_FTP, net::SpawnedTestServer::kLocalhost, 1026 net::SpawnedTestServer::TYPE_FTP, net::SpawnedTestServer::kLocalhost,
1017 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/pdf"))); 1027 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/pdf")));
1018 ASSERT_TRUE(ftp_server.Start()); 1028 ASSERT_TRUE(ftp_server.Start());
1019 1029
1020 GURL url(ftp_server.GetURL("/test.pdf")); 1030 GURL url(ftp_server.GetURL("/test.pdf"));
1021 ASSERT_TRUE(LoadPdf(url)); 1031 ASSERT_TRUE(LoadPdf(url));
1022 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle()); 1032 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle());
1023 } 1033 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698