| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Include test fixture. |
| 6 GEN_INCLUDE(['net_internals_test.js']); |
| 7 |
| 8 // Anonymous namespace |
| 9 (function() { |
| 10 |
| 11 // @return {Array.<object>} List of events for an abbreviated URL request. |
| 12 function urlRequestEvents(id) { |
| 13 return [ |
| 14 { |
| 15 'phase': EventPhase.PHASE_BEGIN, |
| 16 'source': { |
| 17 'id': id, |
| 18 'type': EventSourceType.URL_REQUEST |
| 19 }, |
| 20 'time': '953534778', |
| 21 'type': EventType.REQUEST_ALIVE |
| 22 }, |
| 23 { |
| 24 'params': { |
| 25 'load_flags': 68223104, |
| 26 'method': 'GET', |
| 27 'priority': 4, |
| 28 'url': 'http://www.google.com/' |
| 29 }, |
| 30 'phase': EventPhase.PHASE_BEGIN, |
| 31 'source': { |
| 32 'id': id, |
| 33 'type': EventSourceType.URL_REQUEST |
| 34 }, |
| 35 'time': '953534792', |
| 36 'type': EventType.URL_REQUEST_START_JOB |
| 37 }, |
| 38 { |
| 39 'phase': EventPhase.PHASE_END, |
| 40 'source': { |
| 41 'id': id, |
| 42 'type': EventSourceType.URL_REQUEST |
| 43 }, |
| 44 'time': '953534800', |
| 45 'type': EventType.URL_REQUEST_START_JOB |
| 46 }, |
| 47 { |
| 48 'phase': EventPhase.PHASE_BEGIN, |
| 49 'source': { |
| 50 'id': id, |
| 51 'type': EventSourceType.URL_REQUEST |
| 52 }, |
| 53 'time': '953534906', |
| 54 'type': EventType.HTTP_TRANSACTION_SEND_REQUEST |
| 55 }, |
| 56 { |
| 57 'params': { |
| 58 'headers': [ |
| 59 'Host: www.google.com', |
| 60 'Connection: keep-alive', |
| 61 'User-Agent: Mozilla/5.0', |
| 62 'Accept: text/html', |
| 63 'Accept-Encoding: gzip,deflate,sdch', |
| 64 'Accept-Language: en-US,en;q=0.8', |
| 65 'Accept-Charset: ISO-8859-1' |
| 66 ], |
| 67 'line': 'GET / HTTP/1.1\r\n' |
| 68 }, |
| 69 'phase': EventPhase.PHASE_NONE, |
| 70 'source': { |
| 71 'id': id, |
| 72 'type': EventSourceType.URL_REQUEST |
| 73 }, |
| 74 'time': '953534910', |
| 75 'type': EventType.HTTP_TRANSACTION_SEND_REQUEST_HEADERS |
| 76 }, |
| 77 { |
| 78 'phase': EventPhase.PHASE_END, |
| 79 'source': { |
| 80 'id': id, |
| 81 'type': EventSourceType.URL_REQUEST |
| 82 }, |
| 83 'time': '953534915', |
| 84 'type': EventType.HTTP_TRANSACTION_SEND_REQUEST |
| 85 }, |
| 86 { |
| 87 'phase': EventPhase.PHASE_END, |
| 88 'source': { |
| 89 'id': id, |
| 90 'type': EventSourceType.URL_REQUEST |
| 91 }, |
| 92 'time': '953535567', |
| 93 'type': EventType.REQUEST_ALIVE |
| 94 } |
| 95 ]; |
| 96 } |
| 97 |
| 98 /** |
| 99 * Tests the filters, both in terms of filtering correctly and UI. |
| 100 */ |
| 101 TEST_F('NetInternalsTest', 'netInternalsEventsViewFilter', function() { |
| 102 // Sets the filter and checks the results. |
| 103 // @param {string} filter Filter to use. |
| 104 // @param {Array.<boolean>} matches Ordered list of whether or not each source |
| 105 // matches |filter|. Order must match display order after applying the |
| 106 // filter. |
| 107 function checkFilter(filter, matches) { |
| 108 EventsView.getInstance().setFilterText_(filter); |
| 109 |
| 110 var postFilter = 0; |
| 111 for (var i = 0; i < matches.length; ++i) { |
| 112 if (matches[i]) |
| 113 ++postFilter; |
| 114 } |
| 115 |
| 116 // Updating the display is normally done asynchronously, so have to manually |
| 117 // call update function to check displayed event count. |
| 118 EventsView.getInstance().repaintFilterCounter_(); |
| 119 |
| 120 expectEquals(postFilter + ' of ' + matches.length, |
| 121 $(EventsView.FILTER_COUNT_ID).innerText, |
| 122 filter); |
| 123 |
| 124 var tbody = $(EventsView.TBODY_ID); |
| 125 assertEquals(matches.length, tbody.childElementCount, filter); |
| 126 |
| 127 var visibleCount = 0; |
| 128 for (var i = 0; i < tbody.childElementCount; ++i) { |
| 129 expectEquals(matches[i], |
| 130 NetInternalsTest.nodeIsVisible(tbody.children[i]), |
| 131 filter); |
| 132 } |
| 133 } |
| 134 |
| 135 EventsTracker.getInstance().deleteAllLogEntries(); |
| 136 checkFilter('', [], 0); |
| 137 |
| 138 // A completed request. |
| 139 g_browser.receivedLogEntries(urlRequestEvents(31)); |
| 140 checkFilter('', [true], 1); |
| 141 |
| 142 // An incomplete request. |
| 143 g_browser.receivedLogEntries(urlRequestEvents(56).slice(0, 3)); |
| 144 checkFilter('', [true, true], 2); |
| 145 |
| 146 // Filters used alone and in all combinations. |
| 147 // |text| is the string to add to the filter. |
| 148 // |matches| is a 2-element array of booleans indicating which of the two |
| 149 // requests passes the filter. |
| 150 // |textFilter| is true if the filter matches the displayed text of an |
| 151 // entry. Two string filter matches are concatenated when used, so |
| 152 // will never result in a filter match. |
| 153 var testFilters = [ |
| 154 {text: 'http://www.google.com', matches: [true, true], textFilter: true}, |
| 155 {text: 'MyMagicPony', matches: [false, false], textFilter: true}, |
| 156 {text: 'type:URL_REQUEST', matches: [true, true], textFilter: false}, |
| 157 {text: 'type:SOCKET,URL_REQUEST', matches: [true, true], textFilter: false}, |
| 158 {text: 'type:SOCKET', matches: [false, false], textFilter: false}, |
| 159 {text: 'id:31,32', matches: [true, false], textFilter: false}, |
| 160 {text: 'id:32,56,', matches: [false, true], textFilter: false}, |
| 161 {text: 'is:-active', matches: [true, false], textFilter: false}, |
| 162 {text: 'is:active', matches: [false, true], textFilter: false}, |
| 163 {text: 'is:-error', matches: [true, true], textFilter: false}, |
| 164 {text: 'is:error', matches: [false, false], textFilter: false}, |
| 165 // Partial match of source type. |
| 166 {text: 'URL_REQ', matches: [true, true], textFilter: true}, |
| 167 // Partial match of event type type. |
| 168 {text: 'SEND_REQUEST', matches: [true, false], textFilter: true}, |
| 169 // Check that ":" works in strings. |
| 170 {text: 'Host: www.google.com', matches: [true, false], textFilter: true}, |
| 171 {text: 'Host: GET', matches: [false, false], textFilter: true}, |
| 172 // Make sure sorting has no effect on filters. Sort by ID so order is |
| 173 // preserved. |
| 174 {text: 'sort:id', matches: [true, true], textFilter: false}, |
| 175 ]; |
| 176 |
| 177 for (var filter1 = 0; filter1 < testFilters.length; ++filter1) { |
| 178 checkFilter(testFilters[filter1].text, testFilters[filter1].matches); |
| 179 |
| 180 // Check |filter1| in combination with all the other filters. |
| 181 for (var filter2 = 0; filter2 < testFilters.length; ++filter2) { |
| 182 var matches = []; |
| 183 for (var i = 0; i < testFilters[filter1].matches.length; ++i) { |
| 184 // The merged filter matches an entry if both individual filters do, |
| 185 // unless both filters are text filters, since text filters are |
| 186 // concatenated. |
| 187 matches[i] = testFilters[filter1].matches[i] && |
| 188 testFilters[filter2].matches[i]; |
| 189 if (testFilters[filter1].textFilter && |
| 190 testFilters[filter2].textFilter) { |
| 191 matches[i] = false; |
| 192 } |
| 193 } |
| 194 |
| 195 checkFilter(testFilters[filter1].text + ' ' + testFilters[filter2].text, |
| 196 matches, |
| 197 1); |
| 198 } |
| 199 } |
| 200 |
| 201 testDone(); |
| 202 }); |
| 203 |
| 204 })(); // Anonymous namespace |
| OLD | NEW |