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

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

Issue 2300243004: Links in PDF should open in a new window when shift + left clicked. (Closed)
Patch Set: Links in PDF should open in a new window when shift + left clicked. Created 4 years, 3 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 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 NavigateInCurrentTabCallback() { 5 function NavigateCallback() {
raymes 2016/09/06 04:36:07 We would make this into a MockNavigatorDelegate cl
jaepark 2016/09/06 20:32:47 Done.
6 this.navigateCalled = false; 6 this.navigateCalled = false;
7 this.url = undefined; 7 this.url = undefined;
8 this.callback = function(url) { 8 this.callback = function(url) {
9 this.navigateCalled = true;
10 this.url = url;
11 }.bind(this);
12 this.reset = function() {
13 this.navigateCalled = false;
14 this.url = undefined;
15 };
16 }
17
18 function NavigateInNewTabCallback() {
19 this.navigateCalled = false;
20 this.url = undefined;
21 this.callback = function(url) {
22 this.navigateCalled = true; 9 this.navigateCalled = true;
23 this.url = url; 10 this.url = url;
24 }.bind(this); 11 }.bind(this);
25 this.reset = function() { 12 this.reset = function() {
26 this.navigateCalled = false; 13 this.navigateCalled = false;
27 this.url = undefined; 14 this.url = undefined;
28 }; 15 };
29 } 16 }
30 17
31 /** 18 /**
32 * Given a |navigator|, navigate to |url| in the current tab or new tab, 19 * Given a |navigator|, navigate to |url| in the current tab, a new tab, or
33 * depending on the value of |openInNewTab|. Use |viewportChangedCallback| 20 * a new window depending on the value of |disposition|.
34 * and |navigateCallback| to check the callbacks, and that the navigation 21 * Use |viewportChangedCallback| and |navigateCallback| to check the callbacks,
35 * to |expectedResultUrl| happened. 22 * and that the navigation to |expectedResultUrl| happened.
36 */ 23 */
37 function doNavigationUrlTest( 24 function doNavigationUrlTest(
38 navigator, 25 navigator,
39 url, 26 url,
40 disposition, 27 disposition,
41 expectedResultUrl, 28 expectedResultUrl,
42 viewportChangedCallback, 29 viewportChangedCallback,
43 navigateCallback) { 30 navigateCallback) {
44 viewportChangedCallback.reset(); 31 viewportChangedCallback.reset();
45 navigateCallback.reset(); 32 navigateCallback.reset();
46 navigator.navigate(url, disposition); 33 navigator.navigate(url, disposition);
47 chrome.test.assertFalse(viewportChangedCallback.wasCalled); 34 chrome.test.assertFalse(viewportChangedCallback.wasCalled);
48 chrome.test.assertTrue(navigateCallback.navigateCalled); 35 chrome.test.assertTrue(navigateCallback.navigateCalled);
49 chrome.test.assertEq(expectedResultUrl, navigateCallback.url); 36 chrome.test.assertEq(expectedResultUrl, navigateCallback.url);
50 } 37 }
51 38
52 /** 39 /**
53 * Helper function to run doNavigationUrlTest() for the current tab and a new 40 * Helper function to run doNavigationUrlTest() for the current tab, a new
54 * tab. 41 * tab, and a new window.
55 */ 42 */
56 function doNavigationUrlTestInCurrentTabAndNewTab( 43 function doNavigationUrlTests(originalUrl, url, expectedResultUrl) {
57 navigator, 44 var mockWindow = new MockWindow(100, 100);
58 url, 45 var mockSizer = new MockSizer();
59 expectedResultUrl, 46 var mockViewportChangedCallback = new MockViewportChangedCallback();
60 viewportChangedCallback, 47 var viewport = new Viewport(mockWindow, mockSizer,
61 navigateInCurrentTabCallback, 48 mockViewportChangedCallback.callback,
62 navigateInNewTabCallback) { 49 function() {}, function() {}, 0, 1, 0);
50
51 var paramsParser = new OpenPDFParamsParser(function(name) {
52 paramsParser.onNamedDestinationReceived(-1);
53 });
54
55 var navigateInCurrentTabCallback = new NavigateCallback();
56 var navigateInNewTabCallback = new NavigateCallback();
57 var navigateInNewWindowCallback = new NavigateCallback();
58
59 var navigateCallback = {
60 currentTabCallback: navigateInCurrentTabCallback.callback,
61 newTabCallback: navigateInNewTabCallback.callback,
62 newWindowCallback: navigateInNewWindowCallback.callback
63 };
64 var navigator = new Navigator(originalUrl, viewport, paramsParser,
65 navigateCallback);
raymes 2016/09/06 04:36:07 We could just pass in a new MockNavigatorDelegate
jaepark 2016/09/06 20:32:47 Done.
66
63 doNavigationUrlTest(navigator, url, 67 doNavigationUrlTest(navigator, url,
64 Navigator.WindowOpenDisposition.CURRENT_TAB, expectedResultUrl, 68 Navigator.WindowOpenDisposition.CURRENT_TAB, expectedResultUrl,
65 viewportChangedCallback, navigateInCurrentTabCallback); 69 mockViewportChangedCallback, navigateInCurrentTabCallback);
raymes 2016/09/06 04:36:07 We could pass in the appropriate state of the Mock
jaepark 2016/09/06 20:32:47 Done.
66 doNavigationUrlTest(navigator, url, 70 doNavigationUrlTest(navigator, url,
67 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB, expectedResultUrl, 71 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB, expectedResultUrl,
68 viewportChangedCallback, navigateInNewTabCallback); 72 mockViewportChangedCallback, navigateInNewTabCallback);
73 doNavigationUrlTest(navigator, url,
74 Navigator.WindowOpenDisposition.NEW_WINDOW, expectedResultUrl,
75 mockViewportChangedCallback, navigateInNewWindowCallback);
69 } 76 }
70 77
71 var tests = [ 78 var tests = [
72 /** 79 /**
73 * Test navigation within the page, opening a url in the same tab and 80 * Test navigation within the page, opening a url in the same tab and
74 * opening a url in a new tab. 81 * opening a url in a new tab.
75 */ 82 */
76 function testNavigate() { 83 function testNavigate() {
77 var mockWindow = new MockWindow(100, 100); 84 var mockWindow = new MockWindow(100, 100);
78 var mockSizer = new MockSizer(); 85 var mockSizer = new MockSizer();
79 var mockCallback = new MockViewportChangedCallback(); 86 var mockCallback = new MockViewportChangedCallback();
80 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback, 87 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
81 function() {}, function() {}, 0, 1, 0); 88 function() {}, function() {}, 0, 1, 0);
82 89
83 var paramsParser = new OpenPDFParamsParser(function(name) { 90 var paramsParser = new OpenPDFParamsParser(function(name) {
84 if (name == 'US') 91 if (name == 'US')
85 paramsParser.onNamedDestinationReceived(0); 92 paramsParser.onNamedDestinationReceived(0);
86 else if (name == 'UY') 93 else if (name == 'UY')
87 paramsParser.onNamedDestinationReceived(2); 94 paramsParser.onNamedDestinationReceived(2);
88 else 95 else
89 paramsParser.onNamedDestinationReceived(-1); 96 paramsParser.onNamedDestinationReceived(-1);
90 }); 97 });
91 var url = "http://xyz.pdf"; 98 var url = "http://xyz.pdf";
92 99
93 var navigateInCurrentTabCallback = new NavigateInCurrentTabCallback(); 100 var navigateInCurrentTabCallback = new NavigateCallback();
94 var navigateInNewTabCallback = new NavigateInNewTabCallback(); 101 var navigateInNewTabCallback = new NavigateCallback();
102 var navigateInNewWindowCallback = new NavigateCallback();
103
104 var navigateCallback = {
105 currentTabCallback: navigateInCurrentTabCallback.callback,
106 newTabCallback: navigateInNewTabCallback.callback,
107 newWindowCallback: navigateInNewWindowCallback.callback
108 };
95 var navigator = new Navigator(url, viewport, paramsParser, 109 var navigator = new Navigator(url, viewport, paramsParser,
96 navigateInCurrentTabCallback.callback, 110 navigateCallback);
97 navigateInNewTabCallback.callback);
98 111
99 var documentDimensions = new MockDocumentDimensions(); 112 var documentDimensions = new MockDocumentDimensions();
100 documentDimensions.addPage(100, 100); 113 documentDimensions.addPage(100, 100);
101 documentDimensions.addPage(200, 200); 114 documentDimensions.addPage(200, 200);
102 documentDimensions.addPage(100, 400); 115 documentDimensions.addPage(100, 400);
103 viewport.setDocumentDimensions(documentDimensions); 116 viewport.setDocumentDimensions(documentDimensions);
104 viewport.setZoom(1); 117 viewport.setZoom(1);
105 118
106 mockCallback.reset(); 119 mockCallback.reset();
107 // This should move viewport to page 0. 120 // This should move viewport to page 0.
(...skipping 30 matching lines...) Expand all
138 navigator.navigate(url + "#ABC", 151 navigator.navigate(url + "#ABC",
139 Navigator.WindowOpenDisposition.CURRENT_TAB); 152 Navigator.WindowOpenDisposition.CURRENT_TAB);
140 chrome.test.assertFalse(mockCallback.wasCalled); 153 chrome.test.assertFalse(mockCallback.wasCalled);
141 chrome.test.assertTrue(navigateInCurrentTabCallback.navigateCalled); 154 chrome.test.assertTrue(navigateInCurrentTabCallback.navigateCalled);
142 chrome.test.assertEq(0, viewport.position.x); 155 chrome.test.assertEq(0, viewport.position.x);
143 chrome.test.assertEq(300, viewport.position.y); 156 chrome.test.assertEq(300, viewport.position.y);
144 157
145 chrome.test.succeed(); 158 chrome.test.succeed();
146 }, 159 },
147 /** 160 /**
148 * Test opening a url in the same tab and opening a url in a new tab for 161 * Test opening a url in the same tab, in a new tab, and in a new window for
149 * a http:// url as the current location. The destination url may not have 162 * a http:// url as the current location. The destination url may not have
150 * a valid scheme, so the navigator must determine the url by following 163 * a valid scheme, so the navigator must determine the url by following
151 * similar heuristics as Adobe Acrobat Reader. 164 * similar heuristics as Adobe Acrobat Reader.
152 */ 165 */
153 function testNavigateForLinksWithoutScheme() { 166 function testNavigateForLinksWithoutScheme() {
154 var mockWindow = new MockWindow(100, 100);
155 var mockSizer = new MockSizer();
156 var mockCallback = new MockViewportChangedCallback();
157 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
158 function() {}, function() {}, 0, 1, 0);
159
160 var paramsParser = new OpenPDFParamsParser(function(name) {
161 paramsParser.onNamedDestinationReceived(-1);
162 });
163 var url = "http://www.example.com/subdir/xyz.pdf"; 167 var url = "http://www.example.com/subdir/xyz.pdf";
164 168
165 var navigateInCurrentTabCallback = new NavigateInCurrentTabCallback();
166 var navigateInNewTabCallback = new NavigateInNewTabCallback();
167 var navigator = new Navigator(url, viewport, paramsParser,
168 navigateInCurrentTabCallback.callback,
169 navigateInNewTabCallback.callback);
170
171 // Sanity check. 169 // Sanity check.
172 doNavigationUrlTestInCurrentTabAndNewTab( 170 doNavigationUrlTests(
173 navigator, 171 url,
174 'https://www.foo.com/bar.pdf', 172 'https://www.foo.com/bar.pdf',
175 'https://www.foo.com/bar.pdf', 173 'https://www.foo.com/bar.pdf');
176 mockCallback,
177 navigateInCurrentTabCallback,
178 navigateInNewTabCallback);
179 174
180 // Open relative links. 175 // Open relative links.
181 doNavigationUrlTestInCurrentTabAndNewTab( 176 doNavigationUrlTests(
182 navigator, 177 url,
183 'foo/bar.pdf', 178 'foo/bar.pdf',
184 'http://www.example.com/subdir/foo/bar.pdf', 179 'http://www.example.com/subdir/foo/bar.pdf');
185 mockCallback, 180 doNavigationUrlTests(
186 navigateInCurrentTabCallback, 181 url,
187 navigateInNewTabCallback);
188 doNavigationUrlTestInCurrentTabAndNewTab(
189 navigator,
190 'foo.com/bar.pdf', 182 'foo.com/bar.pdf',
191 'http://www.example.com/subdir/foo.com/bar.pdf', 183 'http://www.example.com/subdir/foo.com/bar.pdf');
192 mockCallback,
193 navigateInCurrentTabCallback,
194 navigateInNewTabCallback);
195 // The expected result is not normalized here. 184 // The expected result is not normalized here.
196 doNavigationUrlTestInCurrentTabAndNewTab( 185 doNavigationUrlTests(
197 navigator, 186 url,
198 '../www.foo.com/bar.pdf', 187 '../www.foo.com/bar.pdf',
199 'http://www.example.com/subdir/../www.foo.com/bar.pdf', 188 'http://www.example.com/subdir/../www.foo.com/bar.pdf');
200 mockCallback,
201 navigateInCurrentTabCallback,
202 navigateInNewTabCallback);
203 189
204 // Open an absolute link. 190 // Open an absolute link.
205 doNavigationUrlTestInCurrentTabAndNewTab( 191 doNavigationUrlTests(
206 navigator, 192 url,
207 '/foodotcom/bar.pdf', 193 '/foodotcom/bar.pdf',
208 'http://www.example.com/foodotcom/bar.pdf', 194 'http://www.example.com/foodotcom/bar.pdf');
209 mockCallback,
210 navigateInCurrentTabCallback,
211 navigateInNewTabCallback);
212 195
213 // Open a http url without a scheme. 196 // Open a http url without a scheme.
214 doNavigationUrlTestInCurrentTabAndNewTab( 197 doNavigationUrlTests(
215 navigator, 198 url,
216 'www.foo.com/bar.pdf', 199 'www.foo.com/bar.pdf',
217 'http://www.foo.com/bar.pdf', 200 'http://www.foo.com/bar.pdf');
218 mockCallback,
219 navigateInCurrentTabCallback,
220 navigateInNewTabCallback);
221 201
222 // Test three dots. 202 // Test three dots.
223 doNavigationUrlTestInCurrentTabAndNewTab( 203 doNavigationUrlTests(
224 navigator, 204 url,
225 '.../bar.pdf', 205 '.../bar.pdf',
226 'http://www.example.com/subdir/.../bar.pdf', 206 'http://www.example.com/subdir/.../bar.pdf');
227 mockCallback,
228 navigateInCurrentTabCallback,
229 navigateInNewTabCallback);
230 207
231 // Test forward slashes. 208 // Test forward slashes.
232 doNavigationUrlTestInCurrentTabAndNewTab( 209 doNavigationUrlTests(
233 navigator, 210 url,
234 '..\\bar.pdf', 211 '..\\bar.pdf',
235 'http://www.example.com/subdir/..\\bar.pdf', 212 'http://www.example.com/subdir/..\\bar.pdf');
236 mockCallback, 213 doNavigationUrlTests(
237 navigateInCurrentTabCallback, 214 url,
238 navigateInNewTabCallback);
239 doNavigationUrlTestInCurrentTabAndNewTab(
240 navigator,
241 '.\\bar.pdf', 215 '.\\bar.pdf',
242 'http://www.example.com/subdir/.\\bar.pdf', 216 'http://www.example.com/subdir/.\\bar.pdf');
243 mockCallback, 217 doNavigationUrlTests(
244 navigateInCurrentTabCallback, 218 url,
245 navigateInNewTabCallback);
246 doNavigationUrlTestInCurrentTabAndNewTab(
247 navigator,
248 '\\bar.pdf', 219 '\\bar.pdf',
249 'http://www.example.com/subdir/\\bar.pdf', 220 'http://www.example.com/subdir/\\bar.pdf');
250 mockCallback,
251 navigateInCurrentTabCallback,
252 navigateInNewTabCallback);
253 221
254 // Regression test for https://crbug.com/569040 222 // Regression test for https://crbug.com/569040
255 doNavigationUrlTestInCurrentTabAndNewTab( 223 doNavigationUrlTests(
256 navigator, 224 url,
257 'http://something.else/foo#page=5', 225 'http://something.else/foo#page=5',
258 'http://something.else/foo#page=5', 226 'http://something.else/foo#page=5');
259 mockCallback,
260 navigateInCurrentTabCallback,
261 navigateInNewTabCallback);
262 227
263 chrome.test.succeed(); 228 chrome.test.succeed();
264 }, 229 },
265 /** 230 /**
266 * Test opening a url in the same tab and opening a url in a new tab with a 231 * Test opening a url in the same tab, in a new tab, and in a new window with
267 * file:/// url as the current location. 232 * a file:/// url as the current location.
268 */ 233 */
269 function testNavigateFromLocalFile() { 234 function testNavigateFromLocalFile() {
270 var mockWindow = new MockWindow(100, 100);
271 var mockSizer = new MockSizer();
272 var mockCallback = new MockViewportChangedCallback();
273 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
274 function() {}, function() {}, 0, 1, 0);
275
276 var paramsParser = new OpenPDFParamsParser(function(name) {
277 paramsParser.onNamedDestinationReceived(-1);
278 });
279 var url = "file:///some/path/to/myfile.pdf"; 235 var url = "file:///some/path/to/myfile.pdf";
280 236
281 var navigateInCurrentTabCallback = new NavigateInCurrentTabCallback();
282 var navigateInNewTabCallback = new NavigateInNewTabCallback();
283 var navigator = new Navigator(url, viewport, paramsParser,
284 navigateInCurrentTabCallback.callback,
285 navigateInNewTabCallback.callback);
286
287 // Open an absolute link. 237 // Open an absolute link.
288 doNavigationUrlTestInCurrentTabAndNewTab( 238 doNavigationUrlTests(
289 navigator, 239 url,
290 '/foodotcom/bar.pdf', 240 '/foodotcom/bar.pdf',
291 'file:///foodotcom/bar.pdf', 241 'file:///foodotcom/bar.pdf');
292 mockCallback,
293 navigateInCurrentTabCallback,
294 navigateInNewTabCallback);
295 242
296 chrome.test.succeed(); 243 chrome.test.succeed();
297 } 244 }
298 ]; 245 ];
299 246
300 var scriptingAPI = new PDFScriptingAPI(window, window); 247 var scriptingAPI = new PDFScriptingAPI(window, window);
301 scriptingAPI.setLoadCallback(function() { 248 scriptingAPI.setLoadCallback(function() {
302 chrome.test.runTests(tests); 249 chrome.test.runTests(tests);
303 }); 250 });
OLDNEW
« chrome/browser/resources/pdf/pdf.js ('K') | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698