[email protected] | 036ce30 | 2015-04-09 13:33:06 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
| 3 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 | <script src="../http/tests/inspector/inspector-test.js"></script> |
| 5 | <script> |
| 6 | |
| 7 | function initialize_ChunkedFileReaderTest() |
| 8 | { |
| 9 | |
| 10 | InspectorTest.TestOutputStreamDelegate = function(doneCallback) |
| 11 | { |
| 12 | this._doneCallback = doneCallback; |
| 13 | this._chunkCount = 0; |
| 14 | } |
| 15 | |
| 16 | InspectorTest.TestOutputStreamDelegate.prototype = { |
| 17 | onTransferStarted: function() |
| 18 | { |
| 19 | InspectorTest.addResult("WebInspector.OutputStreamDelegate.onTransferStarted() called"); |
| 20 | }, |
| 21 | |
| 22 | onTransferFinished: function() |
| 23 | { |
| 24 | InspectorTest.addResult("Chunks transferred: " + this._chunkCount); |
| 25 | InspectorTest.addResult("WebInspector.OutputStreamDelegate.onTransferFinished() called"); |
| 26 | this._doneCallback(); |
| 27 | }, |
| 28 | |
| 29 | /** |
| 30 | * @param {!WebInspector.ChunkedReader} reader |
| 31 | */ |
| 32 | onChunkTransferred: function(reader) |
| 33 | { |
| 34 | this._chunkCount++; |
| 35 | }, |
| 36 | |
| 37 | /** |
| 38 | * @param {!WebInspector.ChunkedReader} reader |
| 39 | * @param {!Event} event |
| 40 | */ |
| 41 | onError: function(reader, event) |
| 42 | { |
| 43 | InspectorTest.addResult("WebInspector.OutputStreamDelegate.onError() called"); |
| 44 | this._doneCallback(); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | } |
| 49 | |
| 50 | function test() |
| 51 | { |
| 52 | var text = ["Латынь из моды вышла ныне:\n", |
| 53 | "Так, если правду вам сказать,\n", |
| 54 | "Он знал довольно по-латыне,\n", |
| 55 | "Чтоб эпиграфы разбирать\n"]; |
| 56 | |
| 57 | var blob = new Blob(text); |
| 58 | // Most of the characters above will be encoded as 2 bytes, so make sure we use odd |
| 59 | // chunk size to cause chunk boundaries sometimes to happen between chaacter bytes. |
| 60 | var chunkSize = 5; |
| 61 | var reader = new WebInspector.ChunkedFileReader(blob, chunkSize, new InspectorTest.TestOutputStreamDelegate(onTransferFinished)); |
| 62 | var output = new WebInspector.StringOutputStream(); |
| 63 | reader.start(output); |
| 64 | function onTransferFinished() |
| 65 | { |
| 66 | InspectorTest.assertEquals(text.join(""), output.data(), "Read text is different from written text"); |
| 67 | InspectorTest.addResult("DONE"); |
| 68 | InspectorTest.completeTest(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | </script> |
| 73 | </head> |
| 74 | |
| 75 | <body onload="runTest()"> |
| 76 | <p> |
| 77 | This tests that ChunkedFileReader properly re-assembles chunks, especially in case these contain multibyte characters. |
| 78 | </p> |
| 79 | |
| 80 | </body> |
| 81 | </html> |