1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>Model tests</title> 10 <style> 11 .view { 12 border: 1px solid black; 13 margin: 10px; 14 } 15 .find-dialog { 16 border: 1px solid black; 17 margin: 10px; 18 } 19 </style> 20 <script src="base.js"></script> 21 <script> 22 base.require('unittest'); 23 base.require('test_utils'); 24 base.require('model.slice'); 25 base.require('filter'); 26 </script> 27 </head> 28 <body> 29 <script> 30 'use strict'; 31 32 var Slice = tracing.model.Slice; 33 var TitleFilter = tracing.TitleFilter; 34 var CategoryFilter = tracing.CategoryFilter; 35 36 function testTitleFilter() { 37 var s0 = test_utils.newSlice(1, 3); 38 assertFalse(new TitleFilter('').matchSlice(s0)); 39 40 assertTrue(new TitleFilter('a').matchSlice(s0)); 41 assertFalse(new TitleFilter('x').matchSlice(s0)); 42 43 var s1 = test_utils.newSliceNamed('ba', 1, 3); 44 assertTrue(new TitleFilter('a').matchSlice(s1)); 45 assertTrue(new TitleFilter('ba').matchSlice(s1)); 46 assertFalse(new TitleFilter('x').matchSlice(s1)); 47 48 var c0 = test_utils.newCounter(null); 49 assertFalse(new TitleFilter('').matchCounter(c0)); 50 51 assertTrue(new TitleFilter('a').matchCounter(c0)); 52 assertFalse(new TitleFilter('x').matchCounter(c0)); 53 54 var c1 = test_utils.newCounterNamed(null, 'ba'); 55 assertTrue(new TitleFilter('a').matchCounter(c1)); 56 assertTrue(new TitleFilter('ba').matchCounter(c1)); 57 assertFalse(new TitleFilter('x').matchCounter(c1)); 58 } 59 60 function testCategoryFilter() { 61 var sNoCategory = test_utils.newSlice(1, 3); 62 sNoCategory.category = undefined; 63 assertTrue(new CategoryFilter(['x']).matchSlice(sNoCategory)); 64 65 var s0 = test_utils.newSlice(1, 3); 66 s0.category = 'x'; 67 assertFalse(new CategoryFilter(['x']).matchSlice(s0)); 68 69 var s1 = test_utils.newSliceNamed('ba', 1, 3); 70 s1.category = 'y'; 71 assertTrue(new CategoryFilter(['x']).matchSlice(s1)); 72 assertFalse(new CategoryFilter(['y']).matchSlice(s1)); 73 assertFalse(new CategoryFilter(['x', 'y']).matchSlice(s1)); 74 75 var cNoCategory = test_utils.newCounterCategory(null, undefined, 'a'); 76 assertTrue(new CategoryFilter(['x']).matchCounter(cNoCategory)); 77 78 var c0 = test_utils.newCounterCategory(null, 'x', 'a'); 79 assertFalse(new CategoryFilter(['x']).matchCounter(c0)); 80 81 var c1 = test_utils.newCounterCategory(null, 'y', 'ba'); 82 assertTrue(new CategoryFilter(['x']).matchCounter(c1)); 83 assertFalse(new CategoryFilter(['y']).matchCounter(c1)); 84 assertFalse(new CategoryFilter(['x', 'y']).matchCounter(c1)); 85 } 86 87 function testFilterSliceArray() { 88 var slices = [ 89 test_utils.newSliceNamed('ba', 1, 3), 90 test_utils.newSliceNamed('ab', 1, 3), 91 test_utils.newSliceNamed('x', 1, 3), 92 test_utils.newSliceNamed('axa', 1, 3) 93 ]; 94 var filter = new TitleFilter('a'); 95 var matched = tracing.filterSliceArray(filter, slices); 96 assertEquals(3, matched.length); 97 assertEquals('ba', matched[0].title); 98 assertEquals('ab', matched[1].title); 99 assertEquals('axa', matched[2].title); 100 } 101 102 function testFilterCounterArray() { 103 var counters = [ 104 test_utils.newCounterNamed(null, 'ba'), 105 test_utils.newCounterNamed(null, 'ab'), 106 test_utils.newCounterNamed(null, 'x'), 107 test_utils.newCounterNamed(null, 'axa') 108 ]; 109 var filter = new TitleFilter('a'); 110 var matched = tracing.filterCounterArray(filter, counters); 111 assertEquals(3, matched.length); 112 assertEquals('ba', matched[0].name); 113 assertEquals('ab', matched[1].name); 114 assertEquals('axa', matched[2].name); 115 } 116 </script> 117 </body> 118 </html> 119