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

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

Issue 2455663004: Add test to ensure that URLs that redirect inside the PDF plugin fail to load (Closed)
Patch Set: Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Load a plugin with the given paramaters.
6 function createPluginForUrl(streamUrl, url, headers, progressCallback) {
7 var plugin = document.createElement('embed');
8 plugin.type = 'application/x-google-chrome-pdf';
9 plugin.addEventListener('message', function(message) {
10 console.error(url);
Lei Zhang 2016/11/03 07:10:45 Debug code?
raymes 2016/11/07 03:25:44 Done.
11 switch (message.data.type.toString()) {
12 case 'loadProgress':
13 progressCallback(message.data.progress);
14 break;
15 }
16 }, false);
17
18 plugin.setAttribute('src', url);
19 plugin.setAttribute('stream-url', streamUrl);
20 plugin.setAttribute('full-frame', '');
21 plugin.setAttribute('headers', headers);
22 document.body.appendChild(plugin);
23 }
24
25 function parseUrl(url) {
26 var a = document.createElement("a");
27 a.href = url;
28 return a;
29 };
30
31 var tests = [
32 // Test that if the plugin is loaded with a URL that redirects it fails.
33 function redirectsFail() {
34 var url = parseUrl(viewer.originalUrl_);
35 var redirectUrl = url.origin + '/server-redirect?' + viewer.originalUrl_;
36 createPluginForUrl(redirectUrl, redirectUrl, '', function(progress) {
37 if (progress == -1)
38 chrome.test.succeed();
39 else
40 chrome.test.fail();
41 });
42 },
43
44 // Test that if the plugin is loaded with a URL that doesn't redirect but
45 // subsequent requests do redirect, it fails.
46 function partialRedirectsFail() {
47 var url = parseUrl(viewer.originalUrl_);
48 var redirectUrl = url.origin + '/server-redirect?' + viewer.originalUrl_;
49 // Set the headers manually so that the first request is made using a URL
50 // that doesn't redirect and subsequent requests are made using a URL that
51 // does.
52 var headers = 'Accept-Ranges: bytes\n' +
53 'Content-Length: 101688487\n' +
54 'Content-Type: application/pdf\n';
55 createPluginForUrl(viewer.originalUrl_, redirectUrl, headers,
56 function(progress) {
57 if (progress == -1)
58 chrome.test.succeed();
59 else
60 chrome.test.fail();
61 });
62 },
63
64 // Test that if the plugin is loaded with a URL that doesn't redirect, it
65 // succeeds.
66 function noRedirectsSucceed() {
67 createPluginForUrl(viewer.originalUrl_, viewer.originalUrl_, '',
68 function(progress) {
69 if (progress == 100)
70 chrome.test.succeed()
71 });
72 },
73 ];
74
75 var scriptingAPI = new PDFScriptingAPI(window, window);
76 scriptingAPI.setLoadCallback(function() {
77 chrome.test.runTests(tests);
78 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698