<!DOCTYPE HTML> <html> <!-- Copyright (c) 2012 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. --> <head> <title>Model tests</title> <style> .view { border: 1px solid black; margin: 10px; } .find-dialog { border: 1px solid black; margin: 10px; } </style> <script src="base.js"></script> <script> base.require('unittest'); base.require('test_utils'); base.require('model'); </script> </head> <body> <script> 'use strict'; var Slice = tracing.model.Slice; var ThreadSlice = tracing.model.ThreadSlice; var Thread = tracing.model.Thread; var Model = tracing.Model; var TitleFilter = tracing.TitleFilter; function createModelWithOneOfEverything() { var m = new Model(); var cpu = m.getOrCreateCpu(1); cpu.slices.push(test_utils.newSlice(1, 3)); var p = m.getOrCreateProcess(1); var t = p.getOrCreateThread(1); t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 4)); t.asyncSlices.push(test_utils.newAsyncSlice(0, 1, t, t)); var c = p.getOrCreateCounter('', 'ProcessCounter'); c.seriesNames.push('a', 'b'); c.seriesColors.push(0, 1); c.timestamps.push(0, 1, 2, 3); c.samples.push(5, 10, 6, 15, 5, 12, 7, 16); var c1 = cpu.getOrCreateCounter('', 'CpuCounter'); c1.seriesNames.push('a', 'b'); c1.seriesColors.push(0, 1); c1.timestamps.push(0, 1, 2, 3); c1.samples.push(5, 10, 6, 15, 5, 12, 7, 16); m.updateBounds(); return m; } function testModelBounds_EmptyModel() { var m = new Model(); m.updateBounds(); assertEquals(undefined, m.bounds.min); assertEquals(undefined, m.bounds.max); } function testModelBounds_OneEmptyThread() { var m = new Model(); var t = m.getOrCreateProcess(1).getOrCreateThread(1); m.updateBounds(); assertEquals(undefined, m.bounds.min); assertEquals(undefined, m.bounds.max); } function testModelBounds_OneThread() { var m = new Model(); var t = m.getOrCreateProcess(1).getOrCreateThread(1); t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3)); m.updateBounds(); assertEquals(1, m.bounds.min); assertEquals(4, m.bounds.max); } function testModelBounds_OneThreadAndOneEmptyThread() { var m = new Model(); var t1 = m.getOrCreateProcess(1).getOrCreateThread(1); t1.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3)); var t2 = m.getOrCreateProcess(1).getOrCreateThread(1); m.updateBounds(); assertEquals(1, m.bounds.min); assertEquals(4, m.bounds.max); } function testModelBounds_OneCpu() { var m = new Model(); var cpu = m.getOrCreateCpu(1); cpu.slices.push(test_utils.newSlice(1, 3)); m.updateBounds(); assertEquals(1, m.bounds.min); assertEquals(4, m.bounds.max); } function testModelBounds_OneCpuOneThread() { var m = new Model(); var cpu = m.getOrCreateCpu(1); cpu.slices.push(test_utils.newSlice(1, 3)); var t = m.getOrCreateProcess(1).getOrCreateThread(1); t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 4)); m.updateBounds(); assertEquals(1, m.bounds.min); assertEquals(5, m.bounds.max); } function testModelCanImportEmpty() { var m; m = new Model([]); m = new Model(''); } function testTitleFilter() { var s0 = test_utils.newSlice(1, 3); assertFalse(new TitleFilter('').matchSlice(s0)); assertTrue(new TitleFilter('a').matchSlice(s0)); assertFalse(new TitleFilter('x').matchSlice(s0)); var s1 = test_utils.newSliceNamed('ba', 1, 3); assertTrue(new TitleFilter('a').matchSlice(s1)); assertTrue(new TitleFilter('ba').matchSlice(s1)); assertFalse(new TitleFilter('x').matchSlice(s1)); } function testModel_toJSON() { var m = createModelWithOneOfEverything(); assertNotNull(JSON.stringify(m)); } function testModel_findAllThreadsNamed() { var m = new Model(); var t = m.getOrCreateProcess(1).getOrCreateThread(1); t.name = 'CrBrowserMain'; m.updateBounds(); var f = m.findAllThreadsNamed('CrBrowserMain'); assertArrayEquals([t], f); f = m.findAllThreadsNamed('NoSuchThread'); assertEquals(0, f.length); } function testModel_updateCategories() { var m = new Model(); var t = m.getOrCreateProcess(1).getOrCreateThread(1); t.pushSlice(new ThreadSlice('categoryA', 'a', 0, 1, {}, 3)); t.pushSlice(new ThreadSlice('categoryA', 'a', 0, 1, {}, 3)); t.pushSlice(new ThreadSlice('categoryB', 'a', 0, 1, {}, 3)); t.pushSlice(new ThreadSlice('categoryA', 'a', 0, 1, {}, 3)); t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3)); m.updateCategories_(); assertArrayEquals(['categoryA', 'categoryB'], m.categories); } </script> </body> </html>