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>CategoryFilter tests</title> 10 <script src="base.js"></script> 11 </head> 12 <body> 13 <script> 14 base.require('unittest'); 15 base.require('test_utils'); 16 base.require('category_filter_dialog'); 17 base.require('settings'); 18 </script> 19 <script> 20 'use strict'; 21 22 function testCategoryFilterDialog_UpdateForm_NoSettings() { 23 var settings = new base.Settings(); 24 25 var dlg = new tracing.CategoryFilterDialog(); 26 dlg.categories = ['one', 'two', 'three']; 27 dlg.settings = settings; 28 dlg.settings_key = 'key'; 29 dlg.isCheckedCallback = function(category) { return true; } 30 dlg.updateForm_(); 31 32 var checkboxes = dlg.formEl_.getElementsByTagName('input'); 33 assertEquals(3, checkboxes.length); 34 assertEquals('one', checkboxes[0].id); 35 assertEquals('one', checkboxes[0].value); 36 assertEquals(true, checkboxes[0].checked); 37 assertEquals('three', checkboxes[1].id); 38 assertEquals('three', checkboxes[1].value); 39 assertEquals(true, checkboxes[1].checked); 40 assertEquals('two', checkboxes[2].id); 41 assertEquals('two', checkboxes[2].value); 42 assertEquals(true, checkboxes[2].checked); 43 var labels = dlg.formEl_.getElementsByTagName('label'); 44 assertEquals(3, labels.length); 45 assertEquals('one', labels[0].textContent); 46 assertEquals('three', labels[1].textContent); 47 assertEquals('two', labels[2].textContent); 48 } 49 50 function testCategoryFilterDialog_UpdateForm_Settings() { 51 var settings = new base.Settings(); 52 settings.set('two', true, 'categories'); 53 settings.set('three', false, 'categories'); 54 55 var dlg = new tracing.CategoryFilterDialog(); 56 dlg.categories = ['one']; 57 dlg.settings = settings; 58 dlg.settings_key = 'categories'; 59 dlg.updateForm_(); 60 61 var checkboxes = dlg.formEl_.getElementsByTagName('input'); 62 assertEquals(3, checkboxes.length); 63 assertEquals('one', checkboxes[0].id); 64 assertEquals('one', checkboxes[0].value); 65 assertEquals(true, checkboxes[0].checked); 66 assertEquals('three', checkboxes[1].id); 67 assertEquals('three', checkboxes[1].value); 68 assertEquals(false, checkboxes[1].checked); 69 assertEquals('two', checkboxes[2].id); 70 assertEquals('two', checkboxes[2].value); 71 assertEquals(true, checkboxes[2].checked); 72 var labels = dlg.formEl_.getElementsByTagName('label'); 73 assertEquals(3, labels.length); 74 assertEquals('one', labels[0].textContent); 75 assertEquals('three', labels[1].textContent); 76 assertEquals('two', labels[2].textContent); 77 } 78 </script> 79 </body> 80 </html> 81