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

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

Issue 2756133002: Add a test to load PDFs from FTP (Closed)
Patch Set: rebase Created 3 years, 9 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 | no next file » | 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 <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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "extensions/test/result_catcher.h" 54 #include "extensions/test/result_catcher.h"
55 #include "net/dns/mock_host_resolver.h" 55 #include "net/dns/mock_host_resolver.h"
56 #include "net/test/embedded_test_server/embedded_test_server.h" 56 #include "net/test/embedded_test_server/embedded_test_server.h"
57 #include "ui/base/resource/resource_bundle.h" 57 #include "ui/base/resource/resource_bundle.h"
58 #include "url/gurl.h" 58 #include "url/gurl.h"
59 59
60 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) 60 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
61 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 61 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
62 #endif 62 #endif
63 63
64 using content::WebContents;
65
64 const int kNumberLoadTestParts = 10; 66 const int kNumberLoadTestParts = 10;
65 67
66 #if defined(OS_MACOSX) 68 #if defined(OS_MACOSX)
67 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey; 69 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey;
68 #else 70 #else
69 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey; 71 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey;
70 #endif 72 #endif
71 73
72 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ 74 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ
73 // in order to print a more readable message if the strings differ. 75 // in order to print a more readable message if the strings differ.
74 #define ASSERT_MULTILINE_STREQ(expected, actual) \ 76 #define ASSERT_MULTILINE_STREQ(expected, actual) \
75 ASSERT_TRUE(expected == actual) \ 77 ASSERT_TRUE(expected == actual) \
76 << "Expected:\n" << expected \ 78 << "Expected:\n" << expected \
77 << "\n\nActual:\n" << actual 79 << "\n\nActual:\n" << actual
78 80
79 bool GetGuestCallback(content::WebContents** guest_out, 81 bool GetGuestCallback(WebContents** guest_out, WebContents* guest) {
80 content::WebContents* guest) {
81 EXPECT_FALSE(*guest_out); 82 EXPECT_FALSE(*guest_out);
82 *guest_out = guest; 83 *guest_out = guest;
83 // Return false so that we iterate through all the guests and verify there is 84 // Return false so that we iterate through all the guests and verify there is
84 // only one. 85 // only one.
85 return false; 86 return false;
86 } 87 }
87 88
88 class PDFExtensionTest : public ExtensionApiTest, 89 class PDFExtensionTest : public ExtensionApiTest,
89 public testing::WithParamInterface<int> { 90 public testing::WithParamInterface<int> {
90 public: 91 public:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const std::string& pdf_filename) { 130 const std::string& pdf_filename) {
130 extensions::ResultCatcher catcher; 131 extensions::ResultCatcher catcher;
131 132
132 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); 133 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename));
133 134
134 // It should be good enough to just navigate to the URL. But loading up the 135 // It should be good enough to just navigate to the URL. But loading up the
135 // BrowserPluginGuest seems to happen asynchronously as there was flakiness 136 // BrowserPluginGuest seems to happen asynchronously as there was flakiness
136 // being seen due to the BrowserPluginGuest not being available yet (see 137 // being seen due to the BrowserPluginGuest not being available yet (see
137 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is 138 // crbug.com/498077). So instead use |LoadPdf| which ensures that the PDF is
138 // loaded before continuing. 139 // loaded before continuing.
139 content::WebContents* guest_contents = LoadPdfGetGuestContents(url); 140 WebContents* guest_contents = LoadPdfGetGuestContents(url);
140 ASSERT_TRUE(guest_contents); 141 ASSERT_TRUE(guest_contents);
141 142
142 base::FilePath test_data_dir; 143 base::FilePath test_data_dir;
143 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 144 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
144 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); 145 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf"));
145 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js"); 146 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js");
146 std::string test_util_js; 147 std::string test_util_js;
147 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js)); 148 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js));
148 149
149 base::FilePath test_file_path = test_data_dir.AppendASCII(filename); 150 base::FilePath test_file_path = test_data_dir.AppendASCII(filename);
150 std::string test_js; 151 std::string test_js;
151 ASSERT_TRUE(base::ReadFileToString(test_file_path, &test_js)); 152 ASSERT_TRUE(base::ReadFileToString(test_file_path, &test_js));
152 153
153 test_util_js.append(test_js); 154 test_util_js.append(test_js);
154 ASSERT_TRUE(content::ExecuteScript(guest_contents, test_util_js)); 155 ASSERT_TRUE(content::ExecuteScript(guest_contents, test_util_js));
155 156
156 if (!catcher.GetNextResult()) 157 if (!catcher.GetNextResult())
157 FAIL() << catcher.message(); 158 FAIL() << catcher.message();
158 } 159 }
159 160
160 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has 161 // Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has
161 // finished loading. Return true if it loads successfully or false if it 162 // finished loading. Return true if it loads successfully or false if it
162 // fails. If it doesn't finish loading the test will hang. This is done from 163 // fails. If it doesn't finish loading the test will hang. This is done from
163 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works 164 // outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works
164 // correctly from there. 165 // correctly from there.
165 bool LoadPdf(const GURL& url) { 166 bool LoadPdf(const GURL& url) {
166 ui_test_utils::NavigateToURL(browser(), url); 167 ui_test_utils::NavigateToURL(browser(), url);
167 content::WebContents* web_contents = 168 WebContents* web_contents = GetActiveWebContents();
168 browser()->tab_strip_model()->GetActiveWebContents();
169 return pdf_extension_test_util::EnsurePDFHasLoaded(web_contents); 169 return pdf_extension_test_util::EnsurePDFHasLoaded(web_contents);
170 } 170 }
171 171
172 // Same as |LoadPdf|, but also returns a pointer to the guest WebContents for 172 // Same as |LoadPdf|, but also returns a pointer to the guest WebContents for
173 // the loaded PDF. Returns nullptr if the load fails. 173 // the loaded PDF. Returns nullptr if the load fails.
174 content::WebContents* LoadPdfGetGuestContents(const GURL& url) { 174 WebContents* LoadPdfGetGuestContents(const GURL& url) {
175 if (!LoadPdf(url)) 175 if (!LoadPdf(url))
176 return nullptr; 176 return nullptr;
177 177
178 content::WebContents* contents = 178 WebContents* contents = GetActiveWebContents();
179 browser()->tab_strip_model()->GetActiveWebContents();
180 content::BrowserPluginGuestManager* guest_manager = 179 content::BrowserPluginGuestManager* guest_manager =
181 contents->GetBrowserContext()->GetGuestManager(); 180 contents->GetBrowserContext()->GetGuestManager();
182 content::WebContents* guest_contents = 181 WebContents* guest_contents = guest_manager->GetFullPageGuest(contents);
183 guest_manager->GetFullPageGuest(contents);
184 return guest_contents; 182 return guest_contents;
185 } 183 }
186 184
187 // Load all the PDFs contained in chrome/test/data/<dir_name>. This only runs 185 // 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 186 // the test if base::Hash(filename) mod kNumberLoadTestParts == k in order
189 // to shard the files evenly across values of k in [0, kNumberLoadTestParts). 187 // to shard the files evenly across values of k in [0, kNumberLoadTestParts).
190 void LoadAllPdfsTest(const std::string& dir_name, int k) { 188 void LoadAllPdfsTest(const std::string& dir_name, int k) {
191 base::FilePath test_data_dir; 189 base::FilePath test_data_dir;
192 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 190 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
193 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name), 191 base::FileEnumerator file_enumerator(test_data_dir.AppendASCII(dir_name),
(...skipping 13 matching lines...) Expand all
207 EXPECT_EQ(!PdfIsExpectedToFailLoad(pdf_file), success); 205 EXPECT_EQ(!PdfIsExpectedToFailLoad(pdf_file), success);
208 } 206 }
209 ++count; 207 ++count;
210 } 208 }
211 // Assume that there is at least 1 pdf in the directory to guard against 209 // Assume that there is at least 1 pdf in the directory to guard against
212 // someone deleting the directory and silently making the test pass. 210 // someone deleting the directory and silently making the test pass.
213 ASSERT_GE(count, 1u); 211 ASSERT_GE(count, 1u);
214 } 212 }
215 213
216 void TestGetSelectedTextReply(GURL url, bool expect_success) { 214 void TestGetSelectedTextReply(GURL url, bool expect_success) {
217 ui_test_utils::NavigateToURL(browser(), url); 215 ASSERT_TRUE(LoadPdf(url));
218 content::WebContents* web_contents =
219 browser()->tab_strip_model()->GetActiveWebContents();
220 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
221 216
222 // Reach into the guest and hook into it such that it posts back a 'flush' 217 // Reach into the guest and hook into it such that it posts back a 'flush'
223 // message after every getSelectedTextReply message sent. 218 // message after every getSelectedTextReply message sent.
219 WebContents* web_contents = GetActiveWebContents();
224 content::BrowserPluginGuestManager* guest_manager = 220 content::BrowserPluginGuestManager* guest_manager =
225 web_contents->GetBrowserContext()->GetGuestManager(); 221 web_contents->GetBrowserContext()->GetGuestManager();
226 content::WebContents* guest_contents = nullptr; 222 WebContents* guest_contents = nullptr;
227 ASSERT_NO_FATAL_FAILURE(guest_manager->ForEachGuest( 223 ASSERT_NO_FATAL_FAILURE(guest_manager->ForEachGuest(
228 web_contents, base::Bind(&GetGuestCallback, &guest_contents))); 224 web_contents, base::Bind(&GetGuestCallback, &guest_contents)));
229 ASSERT_TRUE(guest_contents); 225 ASSERT_TRUE(guest_contents);
230 ASSERT_TRUE(content::ExecuteScript( 226 ASSERT_TRUE(content::ExecuteScript(
231 guest_contents, 227 guest_contents,
232 "var oldSendScriptingMessage = " 228 "var oldSendScriptingMessage = "
233 " PDFViewer.prototype.sendScriptingMessage_;" 229 " PDFViewer.prototype.sendScriptingMessage_;"
234 "PDFViewer.prototype.sendScriptingMessage_ = function(message) {" 230 "PDFViewer.prototype.sendScriptingMessage_ = function(message) {"
235 " oldSendScriptingMessage.bind(this)(message);" 231 " oldSendScriptingMessage.bind(this)(message);"
236 " if (message.type == 'getSelectedTextReply')" 232 " if (message.type == 'getSelectedTextReply')"
(...skipping 11 matching lines...) Expand all
248 " window.domAutomationController.send(false);" 244 " window.domAutomationController.send(false);"
249 " if (event.data.type == 'getSelectedTextReply')" 245 " if (event.data.type == 'getSelectedTextReply')"
250 " window.domAutomationController.send(true);" 246 " window.domAutomationController.send(true);"
251 "});" 247 "});"
252 "document.getElementsByTagName('embed')[0].postMessage(" 248 "document.getElementsByTagName('embed')[0].postMessage("
253 " {type: 'getSelectedText'});", 249 " {type: 'getSelectedText'});",
254 &success)); 250 &success));
255 ASSERT_EQ(expect_success, success); 251 ASSERT_EQ(expect_success, success);
256 } 252 }
257 253
258 void ConvertPageCoordToScreenCoord(content::WebContents* contents, 254 void ConvertPageCoordToScreenCoord(WebContents* contents, gfx::Point* point) {
259 gfx::Point* point) {
260 ASSERT_TRUE(contents); 255 ASSERT_TRUE(contents);
261 ASSERT_TRUE(content::ExecuteScript(contents, 256 ASSERT_TRUE(content::ExecuteScript(contents,
262 "var visiblePage = viewer.viewport.getMostVisiblePage();" 257 "var visiblePage = viewer.viewport.getMostVisiblePage();"
263 "var visiblePageDimensions =" 258 "var visiblePageDimensions ="
264 " viewer.viewport.getPageScreenRect(visiblePage);" 259 " viewer.viewport.getPageScreenRect(visiblePage);"
265 "var viewportPosition = viewer.viewport.position;" 260 "var viewportPosition = viewer.viewport.position;"
266 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;" 261 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;"
267 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;" 262 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;"
268 "var linkScreenPositionX =" 263 "var linkScreenPositionX ="
269 " Math.floor(" + base::IntToString(point->x()) + " + screenOffsetX);" 264 " Math.floor(" + base::IntToString(point->x()) + " + screenOffsetX);"
270 "var linkScreenPositionY =" 265 "var linkScreenPositionY ="
271 " Math.floor(" + base::IntToString(point->y()) + " +" 266 " Math.floor(" + base::IntToString(point->y()) + " +"
272 " screenOffsetY);")); 267 " screenOffsetY);"));
273 268
274 int x; 269 int x;
275 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 270 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
276 contents, 271 contents,
277 "window.domAutomationController.send(linkScreenPositionX);", 272 "window.domAutomationController.send(linkScreenPositionX);",
278 &x)); 273 &x));
279 274
280 int y; 275 int y;
281 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 276 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
282 contents, 277 contents,
283 "window.domAutomationController.send(linkScreenPositionY);", 278 "window.domAutomationController.send(linkScreenPositionY);",
284 &y)); 279 &y));
285 280
286 point->SetPoint(x, y); 281 point->SetPoint(x, y);
287 } 282 }
283
284 WebContents* GetActiveWebContents() {
285 return browser()->tab_strip_model()->GetActiveWebContents();
286 }
288 }; 287 };
289 288
290 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 289 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
291 #if defined(GOOGLE_CHROME_BUILD) 290 #if defined(GOOGLE_CHROME_BUILD)
292 // Load private PDFs. 291 // Load private PDFs.
293 LoadAllPdfsTest("pdf_private", GetParam()); 292 LoadAllPdfsTest("pdf_private", GetParam());
294 #endif 293 #endif
295 // Load public PDFs. 294 // Load public PDFs.
296 LoadAllPdfsTest("pdf", GetParam()); 295 LoadAllPdfsTest("pdf", GetParam());
297 } 296 }
(...skipping 22 matching lines...) Expand all
320 } 319 }
321 320
322 private: 321 private:
323 content::NotificationRegistrar registrar_; 322 content::NotificationRegistrar registrar_;
324 base::RunLoop download_run_loop_; 323 base::RunLoop download_run_loop_;
325 GURL last_url_; 324 GURL last_url_;
326 }; 325 };
327 326
328 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) { 327 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
329 // Disable the PDF plugin. 328 // Disable the PDF plugin.
330 content::WebContents* web_contents = 329 WebContents* web_contents = GetActiveWebContents();
331 browser()->tab_strip_model()->GetActiveWebContents();
332 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); 330 content::BrowserContext* browser_context = web_contents->GetBrowserContext();
333 Profile* profile = Profile::FromBrowserContext(browser_context); 331 Profile* profile = Profile::FromBrowserContext(browser_context);
334 DisablePluginHelper helper; 332 DisablePluginHelper helper;
335 helper.DisablePlugin(profile); 333 helper.DisablePlugin(profile);
336 334
337 // Register a download observer. 335 // Register a download observer.
338 content::DownloadManager* download_manager = 336 content::DownloadManager* download_manager =
339 content::BrowserContext::GetDownloadManager(browser_context); 337 content::BrowserContext::GetDownloadManager(browser_context);
340 download_manager->AddObserver(&helper); 338 download_manager->AddObserver(&helper);
341 339
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureInternalPluginDisabled) { 414 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureInternalPluginDisabled) {
417 std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec(); 415 std::string url = embedded_test_server()->GetURL("/pdf/test.pdf").spec();
418 std::string data_url = 416 std::string data_url =
419 "data:text/html," 417 "data:text/html,"
420 "<html><body>" 418 "<html><body>"
421 "<embed type=\"application/x-google-chrome-pdf\" src=\"" + 419 "<embed type=\"application/x-google-chrome-pdf\" src=\"" +
422 url + 420 url +
423 "\">" 421 "\">"
424 "</body></html>"; 422 "</body></html>";
425 ui_test_utils::NavigateToURL(browser(), GURL(data_url)); 423 ui_test_utils::NavigateToURL(browser(), GURL(data_url));
426 content::WebContents* web_contents = 424 WebContents* web_contents = GetActiveWebContents();
427 browser()->tab_strip_model()->GetActiveWebContents();
428 bool plugin_loaded = false; 425 bool plugin_loaded = false;
429 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 426 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
430 web_contents, 427 web_contents,
431 "var plugin_loaded = " 428 "var plugin_loaded = "
432 " document.getElementsByTagName('embed')[0].postMessage !== undefined;" 429 " document.getElementsByTagName('embed')[0].postMessage !== undefined;"
433 "window.domAutomationController.send(plugin_loaded);", 430 "window.domAutomationController.send(plugin_loaded);",
434 &plugin_loaded)); 431 &plugin_loaded));
435 ASSERT_FALSE(plugin_loaded); 432 ASSERT_FALSE(plugin_loaded);
436 } 433 }
437 434
(...skipping 11 matching lines...) Expand all
449 } 446 }
450 447
451 // Ensure same-origin replies do work for getSelectedText. 448 // Ensure same-origin replies do work for getSelectedText.
452 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) { 449 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureSameOriginRepliesAllowed) {
453 TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"), 450 TestGetSelectedTextReply(embedded_test_server()->GetURL("/pdf/test.pdf"),
454 true); 451 true);
455 } 452 }
456 453
457 // Ensure that the PDF component extension cannot be loaded directly. 454 // Ensure that the PDF component extension cannot be loaded directly.
458 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BlockDirectAccess) { 455 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BlockDirectAccess) {
459 content::WebContents* web_contents = 456 WebContents* web_contents = GetActiveWebContents();
460 browser()->tab_strip_model()->GetActiveWebContents();
461 457
462 std::unique_ptr<content::ConsoleObserverDelegate> console_delegate( 458 std::unique_ptr<content::ConsoleObserverDelegate> console_delegate(
463 new content::ConsoleObserverDelegate( 459 new content::ConsoleObserverDelegate(
464 web_contents, 460 web_contents,
465 "*Streams are only available from a mime handler view guest.*")); 461 "*Streams are only available from a mime handler view guest.*"));
466 web_contents->SetDelegate(console_delegate.get()); 462 web_contents->SetDelegate(console_delegate.get());
467 GURL forbiddenUrl( 463 GURL forbiddenUrl(
468 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" 464 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?"
469 "https://example.com/notrequested.pdf"); 465 "https://example.com/notrequested.pdf");
470 ui_test_utils::NavigateToURL(browser(), forbiddenUrl); 466 ui_test_utils::NavigateToURL(browser(), forbiddenUrl);
471 467
472 console_delegate->Wait(); 468 console_delegate->Wait();
473 } 469 }
474 470
475 // This test ensures that PDF can be loaded from local file 471 // This test ensures that PDF can be loaded from local file
476 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) { 472 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) {
477 base::FilePath test_data_dir; 473 base::FilePath test_data_dir;
478 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 474 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
479 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf")); 475 test_data_dir = test_data_dir.Append(FILE_PATH_LITERAL("pdf"));
480 base::FilePath test_data_file = test_data_dir.AppendASCII("test.pdf"); 476 base::FilePath test_data_file = test_data_dir.AppendASCII("test.pdf");
481 ASSERT_TRUE(PathExists(test_data_file)); 477 ASSERT_TRUE(PathExists(test_data_file));
482 GURL test_pdf_url("file://" + test_data_file.MaybeAsASCII()); 478 GURL test_pdf_url("file://" + test_data_file.MaybeAsASCII());
483 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 479 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
484 ASSERT_TRUE(guest_contents); 480 ASSERT_TRUE(guest_contents);
485 } 481 }
486 482
487 // This test ensures that link permissions are enforced properly in PDFs. 483 // This test ensures that link permissions are enforced properly in PDFs.
488 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkPermissions) { 484 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkPermissions) {
489 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); 485 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
490 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 486 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
491 ASSERT_TRUE(guest_contents); 487 ASSERT_TRUE(guest_contents);
492 488
493 // chrome://favicon links should be allowed for PDFs, while chrome://settings 489 // chrome://favicon links should be allowed for PDFs, while chrome://settings
494 // links should not. 490 // links should not.
495 GURL valid_link_url("chrome://favicon/https://www.google.ca/"); 491 GURL valid_link_url("chrome://favicon/https://www.google.ca/");
496 GURL invalid_link_url("chrome://settings"); 492 GURL invalid_link_url("chrome://settings");
497 493
498 GURL unfiltered_valid_link_url(valid_link_url); 494 GURL unfiltered_valid_link_url(valid_link_url);
499 content::RenderProcessHost* rph = guest_contents->GetRenderProcessHost(); 495 content::RenderProcessHost* rph = guest_contents->GetRenderProcessHost();
500 rph->FilterURL(true, &valid_link_url); 496 rph->FilterURL(true, &valid_link_url);
501 rph->FilterURL(true, &invalid_link_url); 497 rph->FilterURL(true, &invalid_link_url);
502 498
503 // Invalid link URLs should be changed to "about:blank" when filtered. 499 // Invalid link URLs should be changed to "about:blank" when filtered.
504 EXPECT_EQ(unfiltered_valid_link_url, valid_link_url); 500 EXPECT_EQ(unfiltered_valid_link_url, valid_link_url);
505 EXPECT_EQ(GURL("about:blank"), invalid_link_url); 501 EXPECT_EQ(GURL("about:blank"), invalid_link_url);
506 } 502 }
507 503
508 // This test ensures that titles are set properly for PDFs without /Title. 504 // This test ensures that titles are set properly for PDFs without /Title.
509 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithNoTitle) { 505 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithNoTitle) {
510 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); 506 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
511 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 507 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
512 ASSERT_TRUE(guest_contents); 508 ASSERT_TRUE(guest_contents);
513 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), guest_contents->GetTitle()); 509 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), guest_contents->GetTitle());
514 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), 510 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle());
515 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
516 } 511 }
517 512
518 // This test ensures that titles are set properly for PDFs with /Title. 513 // This test ensures that titles are set properly for PDFs with /Title.
519 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithTitle) { 514 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithTitle) {
520 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-title.pdf")); 515 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-title.pdf"));
521 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 516 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
522 ASSERT_TRUE(guest_contents); 517 ASSERT_TRUE(guest_contents);
523 EXPECT_EQ(base::ASCIIToUTF16("PDF title test"), guest_contents->GetTitle()); 518 EXPECT_EQ(base::ASCIIToUTF16("PDF title test"), guest_contents->GetTitle());
524 EXPECT_EQ(base::ASCIIToUTF16("PDF title test"), 519 EXPECT_EQ(base::ASCIIToUTF16("PDF title test"),
525 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 520 GetActiveWebContents()->GetTitle());
526 } 521 }
527 522
528 // This test ensures that titles are set properly for embedded PDFs with /Title. 523 // This test ensures that titles are set properly for embedded PDFs with /Title.
529 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithEmbeddedPdf) { 524 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabTitleWithEmbeddedPdf) {
530 std::string url = 525 std::string url =
531 embedded_test_server()->GetURL("/pdf/test-title.pdf").spec(); 526 embedded_test_server()->GetURL("/pdf/test-title.pdf").spec();
532 std::string data_url = 527 std::string data_url =
533 "data:text/html," 528 "data:text/html,"
534 "<html><head><title>TabTitleWithEmbeddedPdf</title></head><body>" 529 "<html><head><title>TabTitleWithEmbeddedPdf</title></head><body>"
535 "<embed type=\"application/pdf\" src=\"" + 530 "<embed type=\"application/pdf\" src=\"" +
536 url + 531 url +
537 "\"></body></html>"; 532 "\"></body></html>";
538 ui_test_utils::NavigateToURL(browser(), GURL(data_url)); 533 ASSERT_TRUE(LoadPdf(GURL(data_url)));
539 content::WebContents* web_contents =
540 browser()->tab_strip_model()->GetActiveWebContents();
541 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
542 EXPECT_EQ(base::ASCIIToUTF16("TabTitleWithEmbeddedPdf"), 534 EXPECT_EQ(base::ASCIIToUTF16("TabTitleWithEmbeddedPdf"),
543 web_contents->GetTitle()); 535 GetActiveWebContents()->GetTitle());
544 } 536 }
545 537
546 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfZoomWithoutBubble) { 538 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfZoomWithoutBubble) {
547 using namespace zoom; 539 using namespace zoom;
548 540
549 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); 541 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
550 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 542 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
551 ASSERT_TRUE(guest_contents); 543 ASSERT_TRUE(guest_contents);
552 content::WebContents* web_contents = 544 WebContents* web_contents = GetActiveWebContents();
553 browser()->tab_strip_model()->GetActiveWebContents();
554 545
555 // The PDF viewer always starts at default zoom, which for tests is 100% or 546 // The PDF viewer always starts at default zoom, which for tests is 100% or
556 // zoom level 0.0. Here we look at the presets to find the next zoom level 547 // zoom level 0.0. Here we look at the presets to find the next zoom level
557 // above 0. Ideally we should look at the zoom levels from the PDF viewer 548 // above 0. Ideally we should look at the zoom levels from the PDF viewer
558 // javascript, but we assume they'll always match the browser presets, which 549 // javascript, but we assume they'll always match the browser presets, which
559 // are easier to access. 550 // are easier to access.
560 std::vector<double> preset_zoom_levels = PageZoom::PresetZoomLevels(0.0); 551 std::vector<double> preset_zoom_levels = PageZoom::PresetZoomLevels(0.0);
561 std::vector<double>::iterator it = 552 std::vector<double>::iterator it =
562 std::find(preset_zoom_levels.begin(), preset_zoom_levels.end(), 0.0); 553 std::find(preset_zoom_levels.begin(), preset_zoom_levels.end(), 0.0);
563 ASSERT_TRUE(it != preset_zoom_levels.end()); 554 ASSERT_TRUE(it != preset_zoom_levels.end());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 " inlineTextBox 'Second Section\\r\\n'\n" 634 " inlineTextBox 'Second Section\\r\\n'\n"
644 " paragraph\n" 635 " paragraph\n"
645 " staticText '3'\n" 636 " staticText '3'\n"
646 " inlineTextBox '3'\n"; 637 " inlineTextBox '3'\n";
647 638
648 // https://crbug.com/701427 639 // https://crbug.com/701427
649 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibility) { 640 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibility) {
650 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 641 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
651 642
652 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); 643 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf"));
653 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 644 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
654 ASSERT_TRUE(guest_contents); 645 ASSERT_TRUE(guest_contents);
655 646
656 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, 647 WaitForAccessibilityTreeToContainNodeWithName(guest_contents,
657 "1 First Section\r\n"); 648 "1 First Section\r\n");
658 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); 649 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents);
659 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); 650 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree);
660 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); 651 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump);
661 } 652 }
662 653
663 #if defined(GOOGLE_CHROME_BUILD) 654 #if defined(GOOGLE_CHROME_BUILD)
664 // Test a particular PDF encountered in the wild that triggered a crash 655 // Test a particular PDF encountered in the wild that triggered a crash
665 // when accessibility is enabled. (http://crbug.com/648981) 656 // when accessibility is enabled. (http://crbug.com/648981)
666 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityCharCountCrash) { 657 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityCharCountCrash) {
667 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 658 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
668 GURL test_pdf_url(embedded_test_server()->GetURL( 659 GURL test_pdf_url(embedded_test_server()->GetURL(
669 "/pdf_private/accessibility_crash_1.pdf")); 660 "/pdf_private/accessibility_crash_1.pdf"));
670 661
671 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 662 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
672 ASSERT_TRUE(guest_contents); 663 ASSERT_TRUE(guest_contents);
673 664
674 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1"); 665 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1");
675 } 666 }
676 #endif 667 #endif
677 668
678 // https://crbug.com/701427 669 // https://crbug.com/701427
679 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityEnableLater) { 670 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityEnableLater) {
680 // In this test, load the PDF file first, with accessibility off. 671 // In this test, load the PDF file first, with accessibility off.
681 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf")); 672 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-bookmarks.pdf"));
682 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 673 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
683 ASSERT_TRUE(guest_contents); 674 ASSERT_TRUE(guest_contents);
684 675
685 // Now enable accessibility globally, and assert that the PDF accessibility 676 // Now enable accessibility globally, and assert that the PDF accessibility
686 // tree loads. 677 // tree loads.
687 EnableAccessibilityForWebContents(guest_contents); 678 EnableAccessibilityForWebContents(guest_contents);
688 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, 679 WaitForAccessibilityTreeToContainNodeWithName(guest_contents,
689 "1 First Section\r\n"); 680 "1 First Section\r\n");
690 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); 681 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents);
691 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); 682 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree);
692 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); 683 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump);
693 } 684 }
694 685
695 bool RetrieveGuestContents( 686 bool RetrieveGuestContents(WebContents** out_guest_contents,
696 content::WebContents** out_guest_contents, 687 WebContents* in_guest_contents) {
697 content::WebContents* in_guest_contents) {
698 *out_guest_contents = in_guest_contents; 688 *out_guest_contents = in_guest_contents;
699 return true; 689 return true;
700 } 690 }
701 691
702 // https://crbug.com/701427 692 // https://crbug.com/701427
703 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInIframe) { 693 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInIframe) {
704 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 694 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
705 GURL test_iframe_url(embedded_test_server()->GetURL("/pdf/test-iframe.html")); 695 GURL test_iframe_url(embedded_test_server()->GetURL("/pdf/test-iframe.html"));
706 ui_test_utils::NavigateToURL(browser(), test_iframe_url); 696 ui_test_utils::NavigateToURL(browser(), test_iframe_url);
707 content::WebContents* contents = 697 WebContents* contents = GetActiveWebContents();
708 browser()->tab_strip_model()->GetActiveWebContents();
709 WaitForAccessibilityTreeToContainNodeWithName(contents, 698 WaitForAccessibilityTreeToContainNodeWithName(contents,
710 "1 First Section\r\n"); 699 "1 First Section\r\n");
711 700
712 content::WebContents* guest_contents = nullptr; 701 WebContents* guest_contents = nullptr;
713 content::BrowserPluginGuestManager* guest_manager = 702 content::BrowserPluginGuestManager* guest_manager =
714 contents->GetBrowserContext()->GetGuestManager(); 703 contents->GetBrowserContext()->GetGuestManager();
715 guest_manager->ForEachGuest(contents, 704 guest_manager->ForEachGuest(contents,
716 base::Bind(&RetrieveGuestContents, 705 base::Bind(&RetrieveGuestContents,
717 &guest_contents)); 706 &guest_contents));
718 ASSERT_TRUE(guest_contents); 707 ASSERT_TRUE(guest_contents);
719 708
720 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); 709 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents);
721 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); 710 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree);
722 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); 711 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump);
723 } 712 }
724 713
725 // https://crbug.com/701427 714 // https://crbug.com/701427
726 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInOOPIF) { 715 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DISABLED_PdfAccessibilityInOOPIF) {
727 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 716 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
728 GURL test_iframe_url(embedded_test_server()->GetURL( 717 GURL test_iframe_url(embedded_test_server()->GetURL(
729 "/pdf/test-cross-site-iframe.html")); 718 "/pdf/test-cross-site-iframe.html"));
730 ui_test_utils::NavigateToURL(browser(), test_iframe_url); 719 ui_test_utils::NavigateToURL(browser(), test_iframe_url);
731 content::WebContents* contents = 720 WebContents* contents = GetActiveWebContents();
732 browser()->tab_strip_model()->GetActiveWebContents();
733 WaitForAccessibilityTreeToContainNodeWithName(contents, 721 WaitForAccessibilityTreeToContainNodeWithName(contents,
734 "1 First Section\r\n"); 722 "1 First Section\r\n");
735 723
736 content::WebContents* guest_contents = nullptr; 724 WebContents* guest_contents = nullptr;
737 content::BrowserPluginGuestManager* guest_manager = 725 content::BrowserPluginGuestManager* guest_manager =
738 contents->GetBrowserContext()->GetGuestManager(); 726 contents->GetBrowserContext()->GetGuestManager();
739 guest_manager->ForEachGuest(contents, 727 guest_manager->ForEachGuest(contents,
740 base::Bind(&RetrieveGuestContents, 728 base::Bind(&RetrieveGuestContents,
741 &guest_contents)); 729 &guest_contents));
742 ASSERT_TRUE(guest_contents); 730 ASSERT_TRUE(guest_contents);
743 731
744 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); 732 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents);
745 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); 733 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree);
746 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); 734 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump);
747 } 735 }
748 736
749 #if defined(GOOGLE_CHROME_BUILD) 737 #if defined(GOOGLE_CHROME_BUILD)
750 // Test a particular PDF encountered in the wild that triggered a crash 738 // Test a particular PDF encountered in the wild that triggered a crash
751 // when accessibility is enabled. (http://crbug.com/668724) 739 // when accessibility is enabled. (http://crbug.com/668724)
752 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityTextRunCrash) { 740 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilityTextRunCrash) {
753 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 741 content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
754 GURL test_pdf_url(embedded_test_server()->GetURL( 742 GURL test_pdf_url(embedded_test_server()->GetURL(
755 "/pdf_private/accessibility_crash_2.pdf")); 743 "/pdf_private/accessibility_crash_2.pdf"));
756 744
757 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 745 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
758 ASSERT_TRUE(guest_contents); 746 ASSERT_TRUE(guest_contents);
759 747
760 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1"); 748 WaitForAccessibilityTreeToContainNodeWithName(guest_contents, "Page 1");
761 } 749 }
762 #endif 750 #endif
763 751
764 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) { 752 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) {
765 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 753 host_resolver()->AddRule("www.example.com", "127.0.0.1");
766 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 754 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
767 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 755 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
768 ASSERT_TRUE(guest_contents); 756 ASSERT_TRUE(guest_contents);
769 757
770 // The link position of the test-link.pdf in page coordinates is (110, 110). 758 // The link position of the test-link.pdf in page coordinates is (110, 110).
771 // Convert the link position from page coordinates to screen coordinates. 759 // Convert the link position from page coordinates to screen coordinates.
772 gfx::Point link_position(110, 110); 760 gfx::Point link_position(110, 110);
773 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 761 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
774 762
775 content::WebContents* web_contents = 763 WebContents* web_contents = GetActiveWebContents();
776 browser()->tab_strip_model()->GetActiveWebContents();
777 764
778 content::WindowedNotificationObserver observer( 765 content::WindowedNotificationObserver observer(
779 chrome::NOTIFICATION_TAB_ADDED, 766 chrome::NOTIFICATION_TAB_ADDED,
780 content::NotificationService::AllSources()); 767 content::NotificationService::AllSources());
781 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier, 768 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
782 blink::WebMouseEvent::Button::Left, link_position); 769 blink::WebMouseEvent::Button::Left, link_position);
783 observer.Wait(); 770 observer.Wait();
784 771
785 int tab_count = browser()->tab_strip_model()->count(); 772 int tab_count = browser()->tab_strip_model()->count();
786 ASSERT_EQ(2, tab_count); 773 ASSERT_EQ(2, tab_count);
787 774
788 content::WebContents* active_web_contents = 775 WebContents* active_web_contents = GetActiveWebContents();
789 browser()->tab_strip_model()->GetActiveWebContents();
790 ASSERT_EQ(web_contents, active_web_contents); 776 ASSERT_EQ(web_contents, active_web_contents);
791 777
792 content::WebContents* new_web_contents = 778 WebContents* new_web_contents =
793 browser()->tab_strip_model()->GetWebContentsAt(1); 779 browser()->tab_strip_model()->GetWebContentsAt(1);
794 ASSERT_TRUE(new_web_contents); 780 ASSERT_TRUE(new_web_contents);
795 ASSERT_NE(web_contents, new_web_contents); 781 ASSERT_NE(web_contents, new_web_contents);
796 782
797 const GURL& url = new_web_contents->GetURL(); 783 const GURL& url = new_web_contents->GetURL();
798 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 784 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
799 } 785 }
800 786
801 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { 787 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) {
802 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 788 host_resolver()->AddRule("www.example.com", "127.0.0.1");
803 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 789 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
804 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 790 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
805 ASSERT_TRUE(guest_contents); 791 ASSERT_TRUE(guest_contents);
806 792
807 // The link position of the test-link.pdf in page coordinates is (110, 110). 793 // The link position of the test-link.pdf in page coordinates is (110, 110).
808 // Convert the link position from page coordinates to screen coordinates. 794 // Convert the link position from page coordinates to screen coordinates.
809 gfx::Point link_position(110, 110); 795 gfx::Point link_position(110, 110);
810 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 796 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
811 797
812 content::WebContents* web_contents = 798 WebContents* web_contents = GetActiveWebContents();
813 browser()->tab_strip_model()->GetActiveWebContents();
814 799
815 content::WindowedNotificationObserver observer( 800 content::WindowedNotificationObserver observer(
816 chrome::NOTIFICATION_TAB_ADDED, 801 chrome::NOTIFICATION_TAB_ADDED,
817 content::NotificationService::AllSources()); 802 content::NotificationService::AllSources());
818 content::SimulateMouseClickAt(web_contents, 0, 803 content::SimulateMouseClickAt(web_contents, 0,
819 blink::WebMouseEvent::Button::Middle, link_position); 804 blink::WebMouseEvent::Button::Middle, link_position);
820 observer.Wait(); 805 observer.Wait();
821 806
822 int tab_count = browser()->tab_strip_model()->count(); 807 int tab_count = browser()->tab_strip_model()->count();
823 ASSERT_EQ(2, tab_count); 808 ASSERT_EQ(2, tab_count);
824 809
825 content::WebContents* active_web_contents = 810 WebContents* active_web_contents = GetActiveWebContents();
826 browser()->tab_strip_model()->GetActiveWebContents();
827 ASSERT_EQ(web_contents, active_web_contents); 811 ASSERT_EQ(web_contents, active_web_contents);
828 812
829 content::WebContents* new_web_contents = 813 WebContents* new_web_contents =
830 browser()->tab_strip_model()->GetWebContentsAt(1); 814 browser()->tab_strip_model()->GetWebContentsAt(1);
831 ASSERT_TRUE(new_web_contents); 815 ASSERT_TRUE(new_web_contents);
832 ASSERT_NE(web_contents, new_web_contents); 816 ASSERT_NE(web_contents, new_web_contents);
833 817
834 const GURL& url = new_web_contents->GetURL(); 818 const GURL& url = new_web_contents->GetURL();
835 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 819 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
836 } 820 }
837 821
838 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) { 822 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) {
839 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 823 host_resolver()->AddRule("www.example.com", "127.0.0.1");
840 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 824 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
841 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 825 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
842 ASSERT_TRUE(guest_contents); 826 ASSERT_TRUE(guest_contents);
843 827
844 // The link position of the test-link.pdf in page coordinates is (110, 110). 828 // The link position of the test-link.pdf in page coordinates is (110, 110).
845 // Convert the link position from page coordinates to screen coordinates. 829 // Convert the link position from page coordinates to screen coordinates.
846 gfx::Point link_position(110, 110); 830 gfx::Point link_position(110, 110);
847 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 831 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
848 832
849 content::WebContents* web_contents = 833 WebContents* web_contents = GetActiveWebContents();
850 browser()->tab_strip_model()->GetActiveWebContents();
851 834
852 int modifiers = blink::WebInputEvent::ShiftKey | kDefaultKeyModifier; 835 int modifiers = blink::WebInputEvent::ShiftKey | kDefaultKeyModifier;
853 836
854 content::WindowedNotificationObserver observer( 837 content::WindowedNotificationObserver observer(
855 chrome::NOTIFICATION_TAB_ADDED, 838 chrome::NOTIFICATION_TAB_ADDED,
856 content::NotificationService::AllSources()); 839 content::NotificationService::AllSources());
857 content::SimulateMouseClickAt(web_contents, modifiers, 840 content::SimulateMouseClickAt(web_contents, modifiers,
858 blink::WebMouseEvent::Button::Left, link_position); 841 blink::WebMouseEvent::Button::Left, link_position);
859 observer.Wait(); 842 observer.Wait();
860 843
861 int tab_count = browser()->tab_strip_model()->count(); 844 int tab_count = browser()->tab_strip_model()->count();
862 ASSERT_EQ(2, tab_count); 845 ASSERT_EQ(2, tab_count);
863 846
864 content::WebContents* active_web_contents = 847 WebContents* active_web_contents = GetActiveWebContents();
865 browser()->tab_strip_model()->GetActiveWebContents();
866 ASSERT_NE(web_contents, active_web_contents); 848 ASSERT_NE(web_contents, active_web_contents);
867 849
868 const GURL& url = active_web_contents->GetURL(); 850 const GURL& url = active_web_contents->GetURL();
869 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 851 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
870 } 852 }
871 853
872 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) { 854 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) {
873 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 855 host_resolver()->AddRule("www.example.com", "127.0.0.1");
874 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 856 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
875 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 857 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
876 ASSERT_TRUE(guest_contents); 858 ASSERT_TRUE(guest_contents);
877 859
878 // The link position of the test-link.pdf in page coordinates is (110, 110). 860 // The link position of the test-link.pdf in page coordinates is (110, 110).
879 // Convert the link position from page coordinates to screen coordinates. 861 // Convert the link position from page coordinates to screen coordinates.
880 gfx::Point link_position(110, 110); 862 gfx::Point link_position(110, 110);
881 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 863 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
882 864
883 content::WebContents* web_contents = 865 WebContents* web_contents = GetActiveWebContents();
884 browser()->tab_strip_model()->GetActiveWebContents();
885 866
886 content::WindowedNotificationObserver observer( 867 content::WindowedNotificationObserver observer(
887 chrome::NOTIFICATION_TAB_ADDED, 868 chrome::NOTIFICATION_TAB_ADDED,
888 content::NotificationService::AllSources()); 869 content::NotificationService::AllSources());
889 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey, 870 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey,
890 blink::WebMouseEvent::Button::Middle, link_position); 871 blink::WebMouseEvent::Button::Middle, link_position);
891 observer.Wait(); 872 observer.Wait();
892 873
893 int tab_count = browser()->tab_strip_model()->count(); 874 int tab_count = browser()->tab_strip_model()->count();
894 ASSERT_EQ(2, tab_count); 875 ASSERT_EQ(2, tab_count);
895 876
896 content::WebContents* active_web_contents = 877 WebContents* active_web_contents = GetActiveWebContents();
897 browser()->tab_strip_model()->GetActiveWebContents();
898 ASSERT_NE(web_contents, active_web_contents); 878 ASSERT_NE(web_contents, active_web_contents);
899 879
900 const GURL& url = active_web_contents->GetURL(); 880 const GURL& url = active_web_contents->GetURL();
901 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 881 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
902 } 882 }
903 883
904 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftLeftClick) { 884 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftLeftClick) {
905 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 885 host_resolver()->AddRule("www.example.com", "127.0.0.1");
906 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 886 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
907 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 887 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
908 ASSERT_TRUE(guest_contents); 888 ASSERT_TRUE(guest_contents);
909 ASSERT_EQ(1U, chrome::GetTotalBrowserCount()); 889 ASSERT_EQ(1U, chrome::GetTotalBrowserCount());
910 890
911 // The link position of the test-link.pdf in page coordinates is (110, 110). 891 // The link position of the test-link.pdf in page coordinates is (110, 110).
912 // Convert the link position from page coordinates to screen coordinates. 892 // Convert the link position from page coordinates to screen coordinates.
913 gfx::Point link_position(110, 110); 893 gfx::Point link_position(110, 110);
914 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 894 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
915 895
916 content::WebContents* web_contents = 896 WebContents* web_contents = GetActiveWebContents();
917 browser()->tab_strip_model()->GetActiveWebContents();
918 897
919 content::WindowedNotificationObserver observer( 898 content::WindowedNotificationObserver observer(
920 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 899 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
921 content::NotificationService::AllSources()); 900 content::NotificationService::AllSources());
922 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey, 901 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey,
923 blink::WebMouseEvent::Button::Left, 902 blink::WebMouseEvent::Button::Left,
924 link_position); 903 link_position);
925 observer.Wait(); 904 observer.Wait();
926 905
927 ASSERT_EQ(2U, chrome::GetTotalBrowserCount()); 906 ASSERT_EQ(2U, chrome::GetTotalBrowserCount());
928 907
929 content::WebContents* active_web_contents = 908 WebContents* active_web_contents =
930 chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents(); 909 chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
931 ASSERT_NE(web_contents, active_web_contents); 910 ASSERT_NE(web_contents, active_web_contents);
932 911
933 const GURL& url = active_web_contents->GetURL(); 912 const GURL& url = active_web_contents->GetURL();
934 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 913 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
935 } 914 }
936 915
937 // Test that if the plugin tries to load a URL that redirects then it will fail 916 // Test that if the plugin tries to load a URL that redirects then it will fail
938 // to load. This is to avoid the source origin of the document changing during 917 // to load. This is to avoid the source origin of the document changing during
939 // the redirect, which can have security implications. https://crbug.com/653749. 918 // the redirect, which can have security implications. https://crbug.com/653749.
940 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, RedirectsFailInPlugin) { 919 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, RedirectsFailInPlugin) {
941 RunTestsInFile("redirects_fail_test.js", "test.pdf"); 920 RunTestsInFile("redirects_fail_test.js", "test.pdf");
942 } 921 }
943 922
944 // Test that even if a different tab is selected when a navigation occurs, 923 // Test that even if a different tab is selected when a navigation occurs,
945 // the correct tab still gets navigated (see crbug.com/672563). 924 // the correct tab still gets navigated (see crbug.com/672563).
946 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, NavigationOnCorrectTab) { 925 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, NavigationOnCorrectTab) {
947 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); 926 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
948 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 927 WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
949 ASSERT_TRUE(guest_contents); 928 ASSERT_TRUE(guest_contents);
950 content::WebContents* web_contents = 929 WebContents* web_contents = GetActiveWebContents();
951 browser()->tab_strip_model()->GetActiveWebContents();
952 930
953 ui_test_utils::NavigateToURLWithDisposition( 931 ui_test_utils::NavigateToURLWithDisposition(
954 browser(), GURL("about:blank"), 932 browser(), GURL("about:blank"),
955 WindowOpenDisposition::NEW_FOREGROUND_TAB, 933 WindowOpenDisposition::NEW_FOREGROUND_TAB,
956 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 934 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
957 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 935 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
958 content::WebContents* active_web_contents = 936 WebContents* active_web_contents = GetActiveWebContents();
959 browser()->tab_strip_model()->GetActiveWebContents();
960 ASSERT_NE(web_contents, active_web_contents); 937 ASSERT_NE(web_contents, active_web_contents);
961 938
962 ASSERT_TRUE(content::ExecuteScript( 939 ASSERT_TRUE(content::ExecuteScript(
963 guest_contents, 940 guest_contents,
964 "viewer.navigator_.navigate(" 941 "viewer.navigator_.navigate("
965 " 'www.example.com', Navigator.WindowOpenDisposition.CURRENT_TAB);")); 942 " 'www.example.com', Navigator.WindowOpenDisposition.CURRENT_TAB);"));
966 943
967 EXPECT_TRUE(web_contents->GetController().GetPendingEntry()); 944 EXPECT_TRUE(web_contents->GetController().GetPendingEntry());
968 EXPECT_FALSE(active_web_contents->GetController().GetPendingEntry()); 945 EXPECT_FALSE(active_web_contents->GetController().GetPendingEntry());
969 } 946 }
970 947
971 // This test opens a PDF by clicking a link via javascript and verifies that 948 // This test opens a PDF by clicking a link via javascript and verifies that
972 // the PDF is loaded and functional by clicking a link in the PDF. The link 949 // the PDF is loaded and functional by clicking a link in the PDF. The link
973 // click in the PDF opens a new tab. The main page handles the pageShow event 950 // click in the PDF opens a new tab. The main page handles the pageShow event
974 // and updates the history state. 951 // and updates the history state.
975 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenPDFOnLinkClickWithReplaceState) { 952 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenPDFOnLinkClickWithReplaceState) {
976 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 953 host_resolver()->AddRule("www.example.com", "127.0.0.1");
977 954
978 // Navigate to the main page. 955 // Navigate to the main page.
979 GURL test_url( 956 GURL test_url(
980 embedded_test_server()->GetURL("/pdf/pdf_href_replace_state.html")); 957 embedded_test_server()->GetURL("/pdf/pdf_href_replace_state.html"));
981 ui_test_utils::NavigateToURL(browser(), test_url); 958 ui_test_utils::NavigateToURL(browser(), test_url);
982 content::WebContents* web_contents = 959 WebContents* web_contents = GetActiveWebContents();
983 browser()->tab_strip_model()->GetActiveWebContents();
984 ASSERT_TRUE(web_contents); 960 ASSERT_TRUE(web_contents);
985 961
986 // Click on the link which opens the PDF via JS. 962 // Click on the link which opens the PDF via JS.
987 content::TestNavigationObserver navigation_observer(web_contents); 963 content::TestNavigationObserver navigation_observer(web_contents);
988 const char kPdfLinkClick[] = "document.getElementById('link').click();"; 964 const char kPdfLinkClick[] = "document.getElementById('link').click();";
989 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), 965 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
990 kPdfLinkClick)); 966 kPdfLinkClick));
991 navigation_observer.Wait(); 967 navigation_observer.Wait();
992 const GURL& current_url = web_contents->GetURL(); 968 const GURL& current_url = web_contents->GetURL();
993 ASSERT_TRUE(current_url.path() == "/pdf/test-link.pdf"); 969 ASSERT_EQ("/pdf/test-link.pdf", current_url.path());
994 970
995 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents)); 971 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
996 972
997 // Now click on the link to example.com in the PDF. This should open up a new 973 // Now click on the link to example.com in the PDF. This should open up a new
998 // tab. 974 // tab.
999 content::BrowserPluginGuestManager* guest_manager = 975 content::BrowserPluginGuestManager* guest_manager =
1000 web_contents->GetBrowserContext()->GetGuestManager(); 976 web_contents->GetBrowserContext()->GetGuestManager();
1001 content::WebContents* guest_contents = 977 WebContents* guest_contents = guest_manager->GetFullPageGuest(web_contents);
1002 guest_manager->GetFullPageGuest(web_contents);
1003 ASSERT_TRUE(guest_contents); 978 ASSERT_TRUE(guest_contents);
1004 // The link position of the test-link.pdf in page coordinates is (110, 110). 979 // The link position of the test-link.pdf in page coordinates is (110, 110).
1005 // Convert the link position from page coordinates to screen coordinates. 980 // Convert the link position from page coordinates to screen coordinates.
1006 gfx::Point link_position(110, 110); 981 gfx::Point link_position(110, 110);
1007 ConvertPageCoordToScreenCoord(guest_contents, &link_position); 982 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
1008 983
1009 content::WindowedNotificationObserver observer( 984 content::WindowedNotificationObserver observer(
1010 chrome::NOTIFICATION_TAB_ADDED, 985 chrome::NOTIFICATION_TAB_ADDED,
1011 content::NotificationService::AllSources()); 986 content::NotificationService::AllSources());
1012 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier, 987 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
1013 blink::WebMouseEvent::Button::Left, 988 blink::WebMouseEvent::Button::Left,
1014 link_position); 989 link_position);
1015 observer.Wait(); 990 observer.Wait();
1016 991
1017 // We should have two tabs now. One with the PDF and the second for 992 // We should have two tabs now. One with the PDF and the second for
1018 // example.com 993 // example.com
1019 int tab_count = browser()->tab_strip_model()->count(); 994 int tab_count = browser()->tab_strip_model()->count();
1020 ASSERT_EQ(2, tab_count); 995 ASSERT_EQ(2, tab_count);
1021 996
1022 content::WebContents* active_web_contents = 997 WebContents* active_web_contents = GetActiveWebContents();
1023 browser()->tab_strip_model()->GetActiveWebContents();
1024 ASSERT_EQ(web_contents, active_web_contents); 998 ASSERT_EQ(web_contents, active_web_contents);
1025 999
1026 content::WebContents* new_web_contents = 1000 WebContents* new_web_contents =
1027 browser()->tab_strip_model()->GetWebContentsAt(1); 1001 browser()->tab_strip_model()->GetWebContentsAt(1);
1028 ASSERT_TRUE(new_web_contents); 1002 ASSERT_TRUE(new_web_contents);
1029 ASSERT_NE(web_contents, new_web_contents); 1003 ASSERT_NE(web_contents, new_web_contents);
1030 1004
1031 const GURL& url = new_web_contents->GetURL(); 1005 const GURL& url = new_web_contents->GetURL();
1032 ASSERT_EQ(GURL("http://www.example.com"), url); 1006 ASSERT_EQ(GURL("http://www.example.com"), url);
1033 } 1007 }
1008
1009 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenFromFTP) {
1010 net::SpawnedTestServer ftp_server(
1011 net::SpawnedTestServer::TYPE_FTP, net::SpawnedTestServer::kLocalhost,
1012 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/pdf")));
1013 ASSERT_TRUE(ftp_server.Start());
1014
1015 GURL url(ftp_server.GetURL("/test.pdf"));
1016 ASSERT_TRUE(LoadPdf(url));
1017 EXPECT_EQ(base::ASCIIToUTF16("test.pdf"), GetActiveWebContents()->GetTitle());
1018 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698