OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2013 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/base64.html"> | 8 <link rel="import" href="/tracing/base/base64.html"> |
| 9 <link rel="import" href="/tracing/core/test_utils.html"> |
9 <link rel="import" href="/tracing/extras/importer/gzip_importer.html"> | 10 <link rel="import" href="/tracing/extras/importer/gzip_importer.html"> |
10 <link rel="import" href="/tracing/core/test_utils.html"> | |
11 <link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> | 11 <link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> |
12 | 12 |
13 <script> | 13 <script> |
14 'use strict'; | 14 'use strict'; |
15 | 15 |
16 tr.b.unittest.testSuite(function() { | 16 tr.b.unittest.testSuite(function() { |
17 var Base64 = tr.b.Base64; | 17 var Base64 = tr.b.Base64; |
18 var findSliceNamed = tr.c.TestUtils.findSliceNamed; | 18 var findSliceNamed = tr.c.TestUtils.findSliceNamed; |
19 var original_data = | 19 var original_data = |
20 '[{"name":"a","args":{},"pid":52,"ts":520,"cat":"foo","tid":53,' + | 20 '[{"name":"a","args":{},"pid":52,"ts":520,"cat":"foo","tid":53,' + |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 var gzip_data = Base64.atob(gzip_data_base64); | 54 var gzip_data = Base64.atob(gzip_data_base64); |
55 assert.isTrue(tr.e.importer.GzipImporter.canImport(gzip_data)); | 55 assert.isTrue(tr.e.importer.GzipImporter.canImport(gzip_data)); |
56 | 56 |
57 var model = tr.c.TestUtils.newModelWithEvents(gzip_data); | 57 var model = tr.c.TestUtils.newModelWithEvents(gzip_data); |
58 var threads = model.getAllThreads(); | 58 var threads = model.getAllThreads(); |
59 assert.equal(threads.length, 1); | 59 assert.equal(threads.length, 1); |
60 | 60 |
61 var slice = findSliceNamed(threads[0].sliceGroup, 'a'); | 61 var slice = findSliceNamed(threads[0].sliceGroup, 'a'); |
62 assert.equal(slice.category, 'foo'); | 62 assert.equal(slice.category, 'foo'); |
63 }); | 63 }); |
| 64 |
| 65 test('transformToString', function() { |
| 66 function checkTransform(data, expectedString) { |
| 67 assert.strictEqual(tr.e.importer.GzipImporter.transformToString(data), |
| 68 expectedString); |
| 69 } |
| 70 |
| 71 function createArrayBuffer(values) { |
| 72 var buffer = new ArrayBuffer(values.length); |
| 73 var view = new Uint8Array(buffer); |
| 74 view.set(values); |
| 75 return buffer; |
| 76 } |
| 77 |
| 78 // If the browser supports TextDecoder, this will test our custom |
| 79 // implementation. Otherwise, the jszip fallback will be tested. |
| 80 checkTransform('abc012', 'abc012'); |
| 81 checkTransform([100, 101, 102, 51, 52, 53], 'def345'); |
| 82 checkTransform(createArrayBuffer([103, 104, 105, 54, 55, 56]), 'ghi678'); |
| 83 checkTransform(new Uint8Array([106, 107, 108, 57, 58, 59]), 'jkl9:;'); |
| 84 |
| 85 if (typeof TextDecoder === 'undefined') { |
| 86 // The browser doesn't support TextDecoder, so we have already checked |
| 87 // the jszip fallback. |
| 88 return; |
| 89 } |
| 90 |
| 91 // The browser supports TextDecoder, so we now check the jszip fallback. |
| 92 var oldTextDecoder = TextDecoder; |
| 93 TextDecoder = undefined; |
| 94 try { |
| 95 checkTransform('abc012', 'abc012'); |
| 96 checkTransform([100, 101, 102, 51, 52, 53], 'def345'); |
| 97 checkTransform(createArrayBuffer([103, 104, 105, 54, 55, 56]), 'ghi678'); |
| 98 checkTransform(new Uint8Array([106, 107, 108, 57, 58, 59]), 'jkl9:;'); |
| 99 } finally { |
| 100 TextDecoder = oldTextDecoder; |
| 101 } |
| 102 }); |
64 }); | 103 }); |
65 </script> | 104 </script> |
66 | 105 |
OLD | NEW |