| 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 21 matching lines...) Expand all Loading... |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 messagesReceived++; | 113 messagesReceived++; |
| 110 } else { | 114 } else { |
| 111 chrome.test.fail('unexpected message ' + event.data); | 115 chrome.test.fail('unexpected message ' + event.data); |
| 112 } | 116 } |
| 113 } | 117 } |
| 114 window.addEventListener('message', handleMessage, false); | 118 window.addEventListener('message', handleMessage, false); |
| 115 while (queuedMessages.length) { | 119 while (queuedMessages.length) { |
| 116 handleMessage(queuedMessages.shift()); | 120 handleMessage(queuedMessages.shift()); |
| 117 } | 121 } |
| 118 | 122 |
| 123 }, |
| 124 |
| 125 function testDataUrl() { |
| 126 // TODO(raymes): have separate checks for embedded/unembedded data URLs. |
| 127 checkStreamDetailsNoFile(); |
| 128 fetchUrl(streamDetails.streamUrl) |
| 129 .then(expectSuccessfulRead) |
| 130 .then(chrome.test.succeed); |
| 119 } | 131 } |
| 120 ]; | 132 ]; |
| 121 | 133 |
| 122 var testsByName = {}; | 134 var testsByName = {}; |
| 123 for (let i = 0; i < tests.length; i++) { | 135 for (let i = 0; i < tests.length; i++) { |
| 124 testsByName[tests[i].name] = tests[i]; | 136 testsByName[tests[i].name] = tests[i]; |
| 125 } | 137 } |
| 126 | 138 |
| 127 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) { | 139 chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) { |
| 128 if (!streamInfo) | 140 if (!streamInfo) |
| 129 return; | 141 return; |
| 130 | 142 |
| 131 // If the name of the file we're handling matches the name of a test, run that | 143 // If the name of the file we're handling matches the name of a test, run that |
| 132 // test. | 144 // test. |
| 133 var urlComponents = streamInfo.originalUrl.split('/'); | 145 var urlComponents = streamInfo.originalUrl.split('/'); |
| 134 var test = urlComponents[urlComponents.length - 1].split('.')[0]; | 146 var test = urlComponents[urlComponents.length - 1].split('.')[0]; |
| 135 streamDetails = streamInfo; | 147 streamDetails = streamInfo; |
| 136 if (testsByName[test]) { | 148 if (testsByName[test]) { |
| 137 window.removeEventListener('message', queueMessage); | 149 window.removeEventListener('message', queueMessage); |
| 138 chrome.test.runTests([testsByName[test]]); | 150 chrome.test.runTests([testsByName[test]]); |
| 139 } | 151 } |
| 152 |
| 153 // Run the test for data URLs. |
| 154 if (streamInfo.originalUrl.indexOf("data:") === 0) { |
| 155 window.removeEventListener('message', queueMessage); |
| 156 chrome.test.runTests([testsByName['testDataUrl']]); |
| 157 } |
| 140 }); | 158 }); |
| OLD | NEW |