OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 request.open('GET', streamDetails.streamUrl, true); | 31 request.open('GET', streamDetails.streamUrl, true); |
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 expectSuccessfulReadLong(response) { |
| 42 chrome.test.assertEq(200, response.status); |
| 43 chrome.test.assertTrue(response.data.indexOf('content to read\n') === 0); |
| 44 } |
| 45 |
41 function checkStreamDetails(name, embedded) { | 46 function checkStreamDetails(name, embedded) { |
42 checkStreamDetailsNoFile(); | 47 checkStreamDetailsNoFile(); |
43 chrome.test.assertEq(embedded, streamDetails.embedded); | 48 chrome.test.assertEq(embedded, streamDetails.embedded); |
44 chrome.test.assertTrue(streamDetails.originalUrl.indexOf(name) != -1); | 49 chrome.test.assertTrue(streamDetails.originalUrl.indexOf(name) != -1); |
45 chrome.test.assertEq('text/csv', | 50 chrome.test.assertEq('text/csv', |
46 streamDetails.responseHeaders['Content-Type']); | 51 streamDetails.responseHeaders['Content-Type']); |
47 } | 52 } |
48 | 53 |
49 function checkStreamDetailsNoFile() { | 54 function checkStreamDetailsNoFile() { |
50 chrome.test.assertEq('text/csv', streamDetails.mimeType); | 55 chrome.test.assertEq('text/csv', streamDetails.mimeType); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 126 } |
122 | 127 |
123 }, | 128 }, |
124 | 129 |
125 function testDataUrl() { | 130 function testDataUrl() { |
126 // TODO(raymes): have separate checks for embedded/unembedded data URLs. | 131 // TODO(raymes): have separate checks for embedded/unembedded data URLs. |
127 checkStreamDetailsNoFile(); | 132 checkStreamDetailsNoFile(); |
128 fetchUrl(streamDetails.streamUrl) | 133 fetchUrl(streamDetails.streamUrl) |
129 .then(expectSuccessfulRead) | 134 .then(expectSuccessfulRead) |
130 .then(chrome.test.succeed); | 135 .then(chrome.test.succeed); |
| 136 }, |
| 137 |
| 138 function testDataUrlLong() { |
| 139 checkStreamDetailsNoFile(); |
| 140 fetchUrl(streamDetails.streamUrl) |
| 141 .then(expectSuccessfulReadLong) |
| 142 .then(chrome.test.succeed); |
131 } | 143 } |
132 ]; | 144 ]; |
133 | 145 |
134 var testsByName = {}; | 146 var testsByName = {}; |
135 for (let i = 0; i < tests.length; i++) { | 147 for (let i = 0; i < tests.length; i++) { |
136 testsByName[tests[i].name] = tests[i]; | 148 testsByName[tests[i].name] = tests[i]; |
137 } | 149 } |
138 | 150 |
139 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) { | 151 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) { |
140 if (!streamInfo) | 152 if (!streamInfo) |
141 return; | 153 return; |
142 | 154 |
143 // If the name of the file we're handling matches the name of a test, run that | 155 // If the name of the file we're handling matches the name of a test, run that |
144 // test. | 156 // test. |
145 var urlComponents = streamInfo.originalUrl.split('/'); | 157 var urlComponents = streamInfo.originalUrl.split('/'); |
146 var test = urlComponents[urlComponents.length - 1].split('.')[0]; | 158 var test = urlComponents[urlComponents.length - 1].split('.')[0]; |
147 streamDetails = streamInfo; | 159 streamDetails = streamInfo; |
148 if (testsByName[test]) { | 160 if (testsByName[test]) { |
149 window.removeEventListener('message', queueMessage); | 161 window.removeEventListener('message', queueMessage); |
150 chrome.test.runTests([testsByName[test]]); | 162 chrome.test.runTests([testsByName[test]]); |
151 } | 163 } |
152 | 164 |
153 // Run the test for data URLs. | 165 // Run the test for data URLs. |
154 if (streamInfo.originalUrl.indexOf("data:") === 0) { | 166 if (streamInfo.originalUrl.indexOf("data:") === 0) { |
155 window.removeEventListener('message', queueMessage); | 167 window.removeEventListener('message', queueMessage); |
156 chrome.test.runTests([testsByName['testDataUrl']]); | 168 // Long data URLs get truncated. |
| 169 if (streamInfo.originalUrl == "data:") |
| 170 chrome.test.runTests([testsByName['testDataUrlLong']]); |
| 171 else |
| 172 chrome.test.runTests([testsByName['testDataUrl']]); |
157 } | 173 } |
158 }); | 174 }); |
OLD | NEW |