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

Side by Side Diff: chrome/test/data/extensions/api_test/mime_handler_view/index.js

Issue 1091253004: Fix MimeHandlerView plugin loading for data: URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 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 'use strict'; 5 'use strict';
6 6
7 // Tests don't start running until an async call to 7 // Tests don't start running until an async call to
8 // chrome.mimeHandlerPrivate.getStreamInfo() completes, so queue any messages 8 // chrome.mimeHandlerPrivate.getStreamInfo() completes, so queue any messages
9 // received until that point. 9 // received until that point.
10 var queuedMessages = []; 10 var queuedMessages = [];
(...skipping 21 matching lines...) Expand all
32 request.send(); 32 request.send();
33 }); 33 });
34 } 34 }
35 35
36 function expectSuccessfulRead(response) { 36 function expectSuccessfulRead(response) {
37 chrome.test.assertEq(200, response.status); 37 chrome.test.assertEq(200, response.status);
38 chrome.test.assertEq('content to read\n', response.data); 38 chrome.test.assertEq('content to read\n', response.data);
39 } 39 }
40 40
41 function checkStreamDetails(name, embedded) { 41 function checkStreamDetails(name, embedded) {
42 checkStreamDetailsNoFile();
43 chrome.test.assertEq(embedded, streamDetails.embedded);
42 chrome.test.assertTrue(streamDetails.originalUrl.indexOf(name) != -1); 44 chrome.test.assertTrue(streamDetails.originalUrl.indexOf(name) != -1);
45 chrome.test.assertEq('text/csv',
46 streamDetails.responseHeaders['Content-Type']);
47 }
48
49 function checkStreamDetailsNoFile() {
43 chrome.test.assertEq('text/csv', streamDetails.mimeType); 50 chrome.test.assertEq('text/csv', streamDetails.mimeType);
44 chrome.test.assertTrue(streamDetails.tabId != -1); 51 chrome.test.assertTrue(streamDetails.tabId != -1);
45 chrome.test.assertEq(embedded, streamDetails.embedded);
46 chrome.test.assertEq('text/csv',
47 streamDetails.responseHeaders['Content-Type']);
48 } 52 }
49 53
50 var tests = [ 54 var tests = [
51 function testBasic() { 55 function testBasic() {
52 checkStreamDetails('testBasic.csv', false); 56 checkStreamDetails('testBasic.csv', false);
53 fetchUrl(streamDetails.streamUrl) 57 fetchUrl(streamDetails.streamUrl)
54 .then(expectSuccessfulRead) 58 .then(expectSuccessfulRead)
55 .then(chrome.test.succeed); 59 .then(chrome.test.succeed);
56 }, 60 },
57 61
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 messagesReceived++; 104 messagesReceived++;
101 } else { 105 } else {
102 chrome.test.fail('unexpected message ' + event.data); 106 chrome.test.fail('unexpected message ' + event.data);
103 } 107 }
104 } 108 }
105 window.addEventListener('message', handleMessage, false); 109 window.addEventListener('message', handleMessage, false);
106 while (queuedMessages.length) { 110 while (queuedMessages.length) {
107 handleMessage(queuedMessages.shift()); 111 handleMessage(queuedMessages.shift());
108 } 112 }
109 113
114 },
115
116 function testDataUrl() {
117 // TODO(raymes): have separate checks for embedded/unembedded data URLs.
118 checkStreamDetailsNoFile();
119 fetchUrl(streamDetails.streamUrl)
120 .then(expectSuccessfulRead)
121 .then(chrome.test.succeed);
110 } 122 }
111 ]; 123 ];
112 124
113 var testsByName = {}; 125 var testsByName = {};
114 for (let i = 0; i < tests.length; i++) { 126 for (let i = 0; i < tests.length; i++) {
115 testsByName[tests[i].name] = tests[i]; 127 testsByName[tests[i].name] = tests[i];
116 } 128 }
117 129
118 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) { 130 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) {
119 if (!streamInfo) 131 if (!streamInfo)
120 return; 132 return;
121 133
122 // If the name of the file we're handling matches the name of a test, run that 134 // If the name of the file we're handling matches the name of a test, run that
123 // test. 135 // test.
124 var urlComponents = streamInfo.originalUrl.split('/'); 136 var urlComponents = streamInfo.originalUrl.split('/');
125 var test = urlComponents[urlComponents.length - 1].split('.')[0]; 137 var test = urlComponents[urlComponents.length - 1].split('.')[0];
126 streamDetails = streamInfo; 138 streamDetails = streamInfo;
127 if (testsByName[test]) { 139 if (testsByName[test]) {
128 window.removeEventListener('message', queueMessage); 140 window.removeEventListener('message', queueMessage);
129 chrome.test.runTests([testsByName[test]]); 141 chrome.test.runTests([testsByName[test]]);
130 } 142 }
143
144 // Run the test for data URLs.
145 if (streamInfo.originalUrl.indexOf("data:") === 0) {
146 window.removeEventListener('message', queueMessage);
147 chrome.test.runTests([testsByName['testDataUrl']]);
148 }
131 }); 149 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698