1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/base/unittest.html"> 9<link rel="import" href="/tracing/core/filter.html"> 10<link rel="import" href="/tracing/core/test_utils.html"> 11 12<script> 13'use strict'; 14 15tr.b.unittest.testSuite(function() { 16 var TitleOrCategoryFilter = tr.c.TitleOrCategoryFilter; 17 var ExactTitleFilter = tr.c.ExactTitleFilter; 18 var FullTextFilter = tr.c.FullTextFilter; 19 20 test('titleOrCategoryFilter', function() { 21 assert.throw(function() { 22 new TitleOrCategoryFilter(); 23 }); 24 assert.throw(function() { 25 new TitleOrCategoryFilter(''); 26 }); 27 28 var s0 = tr.c.TestUtils.newSliceEx( 29 {cat: 'cat', title: 'a', start: 1, duration: 3}); 30 assert.isTrue(new TitleOrCategoryFilter('a').matchSlice(s0)); 31 assert.isTrue(new TitleOrCategoryFilter('cat').matchSlice(s0)); 32 assert.isTrue(new TitleOrCategoryFilter('at').matchSlice(s0)); 33 assert.isFalse(new TitleOrCategoryFilter('b').matchSlice(s0)); 34 assert.isFalse(new TitleOrCategoryFilter('X').matchSlice(s0)); 35 36 var s1 = tr.c.TestUtils.newSliceEx( 37 {cat: 'cat', title: 'abc', start: 1, duration: 3}); 38 assert.isTrue(new TitleOrCategoryFilter('abc').matchSlice(s1)); 39 assert.isTrue(new TitleOrCategoryFilter('Abc').matchSlice(s1)); 40 assert.isTrue(new TitleOrCategoryFilter('cat').matchSlice(s1)); 41 assert.isTrue(new TitleOrCategoryFilter('Cat').matchSlice(s1)); 42 assert.isFalse(new TitleOrCategoryFilter('cat1').matchSlice(s1)); 43 assert.isFalse(new TitleOrCategoryFilter('X').matchSlice(s1)); 44 }); 45 46 test('exactTitleFilter', function() { 47 assert.throw(function() { 48 new ExactTitleFilter(); 49 }); 50 assert.throw(function() { 51 new ExactTitleFilter(''); 52 }); 53 54 var s0 = tr.c.TestUtils.newSliceEx({title: 'a', start: 1, duration: 3}); 55 assert.isTrue(new ExactTitleFilter('a').matchSlice(s0)); 56 assert.isFalse(new ExactTitleFilter('b').matchSlice(s0)); 57 assert.isFalse(new ExactTitleFilter('A').matchSlice(s0)); 58 59 var s1 = tr.c.TestUtils.newSliceEx({title: 'abc', start: 1, duration: 3}); 60 assert.isTrue(new ExactTitleFilter('abc').matchSlice(s1)); 61 assert.isFalse(new ExactTitleFilter('Abc').matchSlice(s1)); 62 assert.isFalse(new ExactTitleFilter('bc').matchSlice(s1)); 63 assert.isFalse(new ExactTitleFilter('a').matchSlice(s1)); 64 }); 65 66 test('fullTextFilter', function() { 67 assert.throw(function() { 68 new FullTextFilter(); 69 }); 70 assert.throw(function() { 71 new FullTextFilter(''); 72 }); 73 74 var s0 = tr.c.TestUtils.newSliceEx( 75 {cat: 'cat', title: 'a', start: 1, duration: 3}); 76 s0.args['key'] = 'value'; 77 s0.args['anotherKey'] = 'anotherValue'; 78 assert.isTrue(new FullTextFilter('cat').matchSlice(s0)); 79 assert.isTrue(new FullTextFilter('a').matchSlice(s0)); 80 assert.isTrue(new FullTextFilter('key').matchSlice(s0)); 81 assert.isTrue(new FullTextFilter('value').matchSlice(s0)); 82 assert.isTrue(new FullTextFilter('anotherValue').matchSlice(s0)); 83 assert.isFalse(new FullTextFilter('not there').matchSlice(s0)); 84 85 var s1 = tr.c.TestUtils.newSliceEx( 86 {cat: 'cat', title: 'a', start: 1, duration: 3}); 87 s1.args['key'] = 123; 88 assert.isTrue(new FullTextFilter('123').matchSlice(s1)); 89 90 var s2 = tr.c.TestUtils.newSliceEx( 91 {cat: 'cat', title: 'a', start: 1, duration: 3}); 92 s2.args['key'] = ['innerValue1', 'innerValue2']; 93 assert.isTrue(new FullTextFilter('innerValue1').matchSlice(s2)); 94 assert.isTrue(new FullTextFilter('innerValue2').matchSlice(s2)); 95 96 var s3 = tr.c.TestUtils.newSliceEx( 97 {cat: 'cat', title: 'a', start: 1, duration: 3}); 98 s3.args['key'] = ['one', 'two', 'three']; 99 assert.isTrue(new FullTextFilter('two').matchSlice(s3)); 100 101 var s4 = tr.c.TestUtils.newSliceEx( 102 {cat: 'cat', title: 'a', start: 1, duration: 3}); 103 s4.args['key'] = undefined; 104 assert.isFalse(new FullTextFilter('not there').matchSlice(s4)); 105 }); 106}); 107</script> 108