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

Side by Side Diff: chrome/test/data/pdf/navigator_test.js

Issue 2402873002: Add check for file:-navigations from PDFs (Closed)
Patch Set: Put logic at single location, add test Created 4 years, 2 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 | « chrome/browser/resources/pdf/pdf.js ('k') | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 function MockNavigatorDelegate() { 5 function MockNavigatorDelegate() {
6 this.navigateInCurrentTabCalled = false; 6 this.navigateInCurrentTabCalled = false;
7 this.navigateInNewTabCalled = false; 7 this.navigateInNewTabCalled = false;
8 this.navigateInNewWindowCalled = false; 8 this.navigateInNewWindowCalled = false;
9 this.url = undefined; 9 this.url = undefined;
10 } 10 }
11 11
12 MockNavigatorDelegate.prototype = { 12 MockNavigatorDelegate.prototype = {
13 navigateInCurrentTab: function(url) { 13 navigateInCurrentTab: function(url) {
14 this.navigateInCurrentTabCalled = true; 14 this.navigateInCurrentTabCalled = true;
15 this.url = url; 15 this.url = url || '<called, but no url set>';
16 }, 16 },
17 navigateInNewTab: function(url) { 17 navigateInNewTab: function(url) {
18 this.navigateInNewTabCalled = true; 18 this.navigateInNewTabCalled = true;
19 this.url = url; 19 this.url = url || '<called, but no url set>';
20 20
21 }, 21 },
22 navigateInNewWindow: function(url) { 22 navigateInNewWindow: function(url) {
23 this.navigateInNewWindowCalled = true; 23 this.navigateInNewWindowCalled = true;
24 this.url = url; 24 this.url = url || '<called, but no url set>';
25 }, 25 },
26 reset: function() { 26 reset: function() {
27 this.navigateInCurrentTabCalled = false; 27 this.navigateInCurrentTabCalled = false;
28 this.navigateInNewTabCalled = false; 28 this.navigateInNewTabCalled = false;
29 this.navigateInNewWindowCalled = false; 29 this.navigateInNewWindowCalled = false;
30 this.url = undefined; 30 this.url = undefined;
31 } 31 }
32 } 32 }
33 33
34 /** 34 /**
35 * Given a |navigator|, navigate to |url| in the current tab, a new tab, or 35 * Given a |navigator|, navigate to |url| in the current tab, a new tab, or
36 * a new window depending on the value of |disposition|. Use 36 * a new window depending on the value of |disposition|. Use
37 * |viewportChangedCallback| and |navigatorDelegate| to check the callbacks, 37 * |viewportChangedCallback| and |navigatorDelegate| to check the callbacks,
38 * and that the navigation to |expectedResultUrl| happened. 38 * and that the navigation to |expectedResultUrl| happened.
39 */ 39 */
40 function doNavigationUrlTest( 40 function doNavigationUrlTest(
41 navigator, 41 navigator,
42 url, 42 url,
43 disposition, 43 disposition,
44 expectedResultUrl, 44 expectedResultUrl,
45 viewportChangedCallback, 45 viewportChangedCallback,
46 navigatorDelegate) { 46 navigatorDelegate) {
47 viewportChangedCallback.reset(); 47 viewportChangedCallback.reset();
48 navigatorDelegate.reset(); 48 navigatorDelegate.reset();
49 navigator.navigate(url, disposition); 49 navigator.navigate(url, disposition);
50 chrome.test.assertFalse(viewportChangedCallback.wasCalled); 50 chrome.test.assertFalse(viewportChangedCallback.wasCalled);
51 chrome.test.assertEq(expectedResultUrl, navigatorDelegate.url);
52 if (expectedResultUrl === undefined) {
53 return;
raymes 2016/10/13 00:11:34 Can we assert navigatorDelegate.navigateInCurrent
robwu 2016/10/13 07:22:35 That is not needed, because url is undefined iff t
54 }
51 switch (disposition) { 55 switch (disposition) {
52 case Navigator.WindowOpenDisposition.CURRENT_TAB: 56 case Navigator.WindowOpenDisposition.CURRENT_TAB:
53 chrome.test.assertTrue(navigatorDelegate.navigateInCurrentTabCalled); 57 chrome.test.assertTrue(navigatorDelegate.navigateInCurrentTabCalled);
54 break; 58 break;
55 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB: 59 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB:
56 chrome.test.assertTrue(navigatorDelegate.navigateInNewTabCalled); 60 chrome.test.assertTrue(navigatorDelegate.navigateInNewTabCalled);
57 break; 61 break;
58 case Navigator.WindowOpenDisposition.NEW_WINDOW: 62 case Navigator.WindowOpenDisposition.NEW_WINDOW:
59 chrome.test.assertTrue(navigatorDelegate.navigateInNewWindowCalled); 63 chrome.test.assertTrue(navigatorDelegate.navigateInNewWindowCalled);
60 break; 64 break;
61 default: 65 default:
62 break; 66 break;
63 } 67 }
64 chrome.test.assertEq(expectedResultUrl, navigatorDelegate.url);
65 } 68 }
66 69
67 /** 70 /**
68 * Helper function to run doNavigationUrlTest() for the current tab, a new 71 * Helper function to run doNavigationUrlTest() for the current tab, a new
69 * tab, and a new window. 72 * tab, and a new window.
70 */ 73 */
71 function doNavigationUrlTests(originalUrl, url, expectedResultUrl) { 74 function doNavigationUrlTests(originalUrl, url, expectedResultUrl) {
72 var mockWindow = new MockWindow(100, 100); 75 var mockWindow = new MockWindow(100, 100);
73 var mockSizer = new MockSizer(); 76 var mockSizer = new MockSizer();
74 var mockViewportChangedCallback = new MockViewportChangedCallback(); 77 var mockViewportChangedCallback = new MockViewportChangedCallback();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 function testNavigateFromLocalFile() { 249 function testNavigateFromLocalFile() {
247 var url = "file:///some/path/to/myfile.pdf"; 250 var url = "file:///some/path/to/myfile.pdf";
248 251
249 // Open an absolute link. 252 // Open an absolute link.
250 doNavigationUrlTests( 253 doNavigationUrlTests(
251 url, 254 url,
252 '/foodotcom/bar.pdf', 255 '/foodotcom/bar.pdf',
253 'file:///foodotcom/bar.pdf'); 256 'file:///foodotcom/bar.pdf');
254 257
255 chrome.test.succeed(); 258 chrome.test.succeed();
259 },
260
261 function testNavigateInvalidUrls() {
262 var url = 'https://example.com/some-web-document.pdf';
263
264 // From non-file: to file:
265 doNavigationUrlTests(
266 url,
267 'file:///bar.pdf',
268 undefined);
269
270 doNavigationUrlTests(
271 url,
272 'chrome://version',
273 undefined);
274
275 doNavigationUrlTests(
276 url,
277 'javascript:// this is not a document.pdf',
278 undefined);
279
280 doNavigationUrlTests(
281 url,
282 'this-is-not-a-valid-scheme://path.pdf',
283 undefined);
284
285 doNavigationUrlTests(
286 url,
287 '',
288 undefined);
289
290 chrome.test.succeed();
256 } 291 }
257 ]; 292 ];
258 293
259 var scriptingAPI = new PDFScriptingAPI(window, window); 294 var scriptingAPI = new PDFScriptingAPI(window, window);
260 scriptingAPI.setLoadCallback(function() { 295 scriptingAPI.setLoadCallback(function() {
261 chrome.test.runTests(tests); 296 chrome.test.runTests(tests);
262 }); 297 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698