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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/document_loader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/pdf/redirects_fail_test.js
diff --git a/chrome/test/data/pdf/redirects_fail_test.js b/chrome/test/data/pdf/redirects_fail_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..3bd6d0b778723427678e98bc356e8380573d27d9
--- /dev/null
+++ b/chrome/test/data/pdf/redirects_fail_test.js
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Load a plugin with the given paramaters.
+function createPluginForUrl(streamUrl, url, headers, progressCallback) {
+ var plugin = document.createElement('embed');
+ plugin.type = 'application/x-google-chrome-pdf';
+ plugin.addEventListener('message', function(message) {
+ switch (message.data.type.toString()) {
+ case 'loadProgress':
+ progressCallback(message.data.progress);
+ break;
+ }
+ }, false);
+
+ plugin.setAttribute('src', url);
+ plugin.setAttribute('stream-url', streamUrl);
+ plugin.setAttribute('full-frame', '');
+ plugin.setAttribute('headers', headers);
+ document.body.appendChild(plugin);
+}
+
+function parseUrl(url) {
+ var a = document.createElement("a");
+ a.href = url;
+ return a;
+};
+
+var tests = [
+ // Test that if the plugin is loaded with a URL that redirects it fails.
+ function redirectsFail() {
+ var url = parseUrl(viewer.originalUrl_);
+ var redirectUrl = url.origin + '/server-redirect?' + viewer.originalUrl_;
+ createPluginForUrl(redirectUrl, redirectUrl, '', function(progress) {
+ if (progress == -1)
+ chrome.test.succeed();
+ else
+ chrome.test.fail();
+ });
+ },
+
+ // Test that if the plugin is loaded with a URL that doesn't redirect but
+ // subsequent requests do redirect, it fails.
+ function partialRedirectsFail() {
+ var url = parseUrl(viewer.originalUrl_);
+ var redirectUrl = url.origin + '/server-redirect?' + viewer.originalUrl_;
+ // Set the headers manually so that the first request is made using a URL
+ // that doesn't redirect and subsequent requests are made using a URL that
+ // does.
+ var headers = 'Accept-Ranges: bytes\n' +
+ 'Content-Length: 101688487\n' +
+ 'Content-Type: application/pdf\n';
+ createPluginForUrl(viewer.originalUrl_, redirectUrl, headers,
+ function(progress) {
+ if (progress == -1)
+ chrome.test.succeed();
+ else
+ chrome.test.fail();
+ });
+ },
+
+ // Test that if the plugin is loaded with a URL that doesn't redirect, it
+ // succeeds.
+ function noRedirectsSucceed() {
+ createPluginForUrl(viewer.originalUrl_, viewer.originalUrl_, '',
+ function(progress) {
+ if (progress == 100)
+ chrome.test.succeed()
+ });
+ },
+];
+
+var scriptingAPI = new PDFScriptingAPI(window, window);
+scriptingAPI.setLoadCallback(function() {
+ chrome.test.runTests(tests);
+});
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/document_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698