| <!DOCTYPE html> |
| <!-- |
| Copyright 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/perf_insights/mappers/scheduling/map_rendering_cost.html"> |
| <link rel="import" href="/perf_insights/mre/mre_result.html"> |
| <link rel="import" href="/tracing/core/test_utils.html"> |
| <link rel="import" href="/tracing/extras/chrome/chrome_test_utils.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var TestUtils = tr.c.TestUtils; |
| var ThreadSlice = tr.model.ThreadSlice; |
| |
| test('mapperTest', function() { |
| var m = tr.e.chrome.ChromeTestUtils.newChromeModel(function(m) { |
| tr.e.chrome.ChromeTestUtils.addLoadingEvent(m, {start: 0, end: 10}); |
| |
| var mainThread = m.rendererMain; |
| |
| mainThread.sliceGroup.pushSlice(TestUtils.newSliceEx({ |
| type: ThreadSlice, |
| start: 4, |
| duration: 4, |
| title: 'TaskQueueManager::RunTask' |
| })); |
| |
| mainThread.sliceGroup.pushSlice(TestUtils.newSliceEx({ |
| type: ThreadSlice, |
| start: 5, |
| duration: 2, |
| title: 'ThreadProxy::BeginMainFrame' |
| })); |
| |
| // Two slices that only partially overlaps the loading phase. Both |
| // should be ignored. |
| mainThread.sliceGroup.pushSlice(TestUtils.newSliceEx({ |
| type: ThreadSlice, |
| start: -5, |
| duration: 10, |
| title: 'ThreadProxy::BeginMainFrame' |
| })); |
| |
| mainThread.sliceGroup.pushSlice(TestUtils.newSliceEx({ |
| type: ThreadSlice, |
| start: 8, |
| duration: 10, |
| title: 'ThreadProxy::BeginMainFrame' |
| })); |
| }); |
| |
| var result = new pi.mre.MreResult(); |
| pie.mapRenderingCostForTest(result, m); |
| |
| assert.equal(tr.b.dictionaryLength(result.pairs), 1); |
| |
| var renderingCost = result.pairs.renderingCost; |
| assert.deepEqual(renderingCost.loadingDuration, [10]); |
| assert.deepEqual(renderingCost.loadingTotalCost, [4]); |
| assert.deepEqual(renderingCost.loadingBeginMainFrameCost, [2]); |
| assert.deepEqual(renderingCost.loadingBeginMainFrameRelativeCost, [.5]); |
| }); |
| }); |
| |
| </script> |