Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/test/data/webui/net_internals/dns_view.js

Issue 2773023003: Add more data to net-internals view of DNS cache (Closed)
Patch Set: undefined -> empty string Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Include test fixture. 5 // Include test fixture.
6 GEN_INCLUDE(['net_internals_test.js']); 6 GEN_INCLUDE(['net_internals_test.js']);
7 7
8 // Anonymous namespace 8 // Anonymous namespace
9 (function() { 9 (function() {
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 this.expired_ ? -2 : 2 94 this.expired_ ? -2 : 2
95 ]; 95 ];
96 chrome.send('addCacheEntry', addCacheEntryParams); 96 chrome.send('addCacheEntry', addCacheEntryParams);
97 g_browser.addHostResolverInfoObserver(this, false); 97 g_browser.addHostResolverInfoObserver(this, false);
98 }, 98 },
99 99
100 /** 100 /**
101 * Callback from the BrowserBridge. Checks if |hostResolverInfo| has the 101 * Callback from the BrowserBridge. Checks if |hostResolverInfo| has the
102 * DNS entry specified on creation. If so, validates it and completes the 102 * DNS entry specified on creation. If so, validates it and completes the
103 * task. If not, continues running. 103 * task. If not, continues running.
104 * @param {object} hostResolverInfo Results a host resolver info query. 104 * @param {object} hostResolverInfo Results of a host resolver info query.
105 */ 105 */
106 onHostResolverInfoChanged: function(hostResolverInfo) { 106 onHostResolverInfoChanged: function(hostResolverInfo) {
107 if (!this.isDone()) { 107 if (!this.isDone()) {
108 checkDisplay(hostResolverInfo); 108 checkDisplay(hostResolverInfo);
109 109
110 var index = findEntry(hostResolverInfo, this.hostname_); 110 var index = findEntry(hostResolverInfo, this.hostname_);
111 if (index >= 0) { 111 if (index >= 0) {
112 var entry = hostResolverInfo.cache.entries[index]; 112 var entry = hostResolverInfo.cache.entries[index];
113 if (this.netError_) { 113 if (this.netError_) {
114 this.checkError_(entry); 114 this.checkError_(entry);
115 } else { 115 } else {
116 this.checkSuccess_(entry); 116 this.checkSuccess_(entry);
117 } 117 }
118 var expirationDate = timeutil.convertTimeTicksToDate(entry.expiration); 118 var expirationDate = timeutil.convertTimeTicksToDate(entry.expiration);
119 expectEquals(this.expired_, expirationDate < new Date()); 119 expectEquals(this.expired_, expirationDate < new Date());
120 120
121 // Expect at least one active or expired entry, depending on |expired_|. 121 // Expect at least one active or expired entry, depending on |expired_|.
122 // To avoid any chance of a race, exact values are not tested. 122 // To avoid any chance of a race, exact values are not tested.
123 var activeMin = this.expired_ ? 0 : 1; 123 var activeMin = this.expired_ ? 0 : 1;
124 var expiredMin = this.expired_ ? 1 : 0; 124 var expiredMin = this.expired_ ? 1 : 0;
125 expectLE(activeMin, parseInt($(DnsView.ACTIVE_SPAN_ID).innerText)); 125 expectLE(activeMin, parseInt($(DnsView.ACTIVE_SPAN_ID).innerText));
126 expectLE(expiredMin, parseInt($(DnsView.EXPIRED_SPAN_ID).innerText)); 126 expectLE(expiredMin, parseInt($(DnsView.EXPIRED_SPAN_ID).innerText));
127 127
128 // Text for the expiration time of the entry should contain 'Expired' 128 // Text for the expiration time of the entry should contain 'Expired'
129 // only if |expired_| is true. Only checked for entries we add 129 // only if |expired_| is true. Only checked for entries we add
130 // ourselves to avoid any expiration time race. 130 // ourselves to avoid any expiration time race.
131 var expirationText = 131 var expirationText =
132 NetInternalsTest.getTbodyText(DnsView.CACHE_TBODY_ID, index, 3); 132 NetInternalsTest.getTbodyText(DnsView.CACHE_TBODY_ID, index, 4);
133 expectEquals(this.expired_, /expired/i.test(expirationText)); 133 expectEquals(this.expired_, /expired/i.test(expirationText));
134 134
135 this.onTaskDone(); 135 this.onTaskDone();
136 } 136 }
137 } 137 }
138 }, 138 },
139 139
140 checkError_: function(entry) { 140 checkError_: function(entry) {
141 expectEquals(this.netError_, entry.error); 141 expectEquals(this.netError_, entry.error);
142 }, 142 },
143 143
144 checkSuccess_: function(entry) { 144 checkSuccess_: function(entry) {
145 expectEquals(undefined, entry.error); 145 expectEquals(undefined, entry.error);
146 expectEquals(1, entry.addresses.length); 146 expectEquals(1, entry.addresses.length);
147 expectEquals(0, entry.addresses[0].search(this.ipAddress_)); 147 expectEquals(0, entry.addresses[0].search(this.ipAddress_));
148 } 148 }
149 }; 149 };
150 150
151 /** 151 /**
152 * A Task clears the cache by simulating a button click. 152 * A Task that simulates a network change and checks that cache entries are
153 * expired.
154 * @extends {NetInternalsTest.Task}
155 */
156 function NetworkChangeTask() {
157 NetInternalsTest.Task.call(this);
158 }
159
160 NetworkChangeTask.prototype = {
161 __proto__: NetInternalsTest.Task.prototype,
162
163 start: function() {
164 chrome.send('changeNetwork');
165 g_browser.addHostResolverInfoObserver(this, false);
166 },
167
168 /**
169 * Callback from the BrowserBridge. Checks if the entry has been expired.
170 * If so, the task completes.
171 * @param {object} hostResolverInfo Results of a host resolver info query.
172 */
173 onHostResolverInfoChanged: function(hostResolverInfo) {
174 if (!this.isDone()) {
175 checkDisplay(hostResolverInfo);
176
177 var entries = hostResolverInfo.cache.entries;
178 var tableId = DnsView.CACHE_TBODY_ID;
179 var foundExpired = false;
180
181 // Look for an entry that's expired due to a network change.
182 for (var row = 0; row < entries.length; ++row) {
183 var text = NetInternalsTest.getTbodyText(tableId, row, 5);
184 if (/expired/i.test(text)) {
185 foundExpired = true;
186 };
187 }
188
189 if (foundExpired) {
190 // Expect at least one expired entry and at least one network change.
191 // To avoid any chance of a race, exact values are not tested.
192 expectLE(0, parseInt($(DnsView.ACTIVE_SPAN_ID).innerText));
193 expectLE(1, parseInt($(DnsView.EXPIRED_SPAN_ID).innerText));
194 expectLE(1, parseInt($(DnsView.NETWORK_SPAN_ID).innerText));
195 this.onTaskDone();
196 }
197 }
198 }
199 };
200
201 /**
202 * A Task that clears the cache by simulating a button click.
153 * @extends {NetInternalsTest.Task} 203 * @extends {NetInternalsTest.Task}
154 */ 204 */
155 function ClearCacheTask() { 205 function ClearCacheTask() {
156 NetInternalsTest.Task.call(this); 206 NetInternalsTest.Task.call(this);
157 } 207 }
158 208
159 ClearCacheTask.prototype = { 209 ClearCacheTask.prototype = {
160 __proto__: NetInternalsTest.Task.prototype, 210 __proto__: NetInternalsTest.Task.prototype,
161 211
162 start: function() { 212 start: function() {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 NetInternalsTest.switchToView('dns'); 318 NetInternalsTest.switchToView('dns');
269 var taskQueue = new NetInternalsTest.TaskQueue(true); 319 var taskQueue = new NetInternalsTest.TaskQueue(true);
270 taskQueue.addTask(new NetInternalsTest.CreateIncognitoBrowserTask()); 320 taskQueue.addTask(new NetInternalsTest.CreateIncognitoBrowserTask());
271 taskQueue.addTask(new AddCacheEntryTask( 321 taskQueue.addTask(new AddCacheEntryTask(
272 'somewhere.com', '1.2.3.4', 0, true)); 322 'somewhere.com', '1.2.3.4', 0, true));
273 taskQueue.addTask(NetInternalsTest.getCloseIncognitoBrowserTask()); 323 taskQueue.addTask(NetInternalsTest.getCloseIncognitoBrowserTask());
274 taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com')); 324 taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
275 taskQueue.run(true); 325 taskQueue.run(true);
276 }); 326 });
277 327
328 /**
329 * Adds a successful lookup to the DNS cache, then simulates a network change
330 * and checks that the entry expires.
331 */
332 TEST_F('NetInternalsTest', 'netInternalsDnsViewNetworkChanged', function() {
333 NetInternalsTest.switchToView('dns');
334 var taskQueue = new NetInternalsTest.TaskQueue(true);
335 taskQueue.addTask(new AddCacheEntryTask(
336 'somewhere.com', '1.2.3.4', 0, false));
337 taskQueue.addTask(new NetworkChangeTask());
338 taskQueue.addTask(new ClearCacheTask());
339 taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
340 taskQueue.run(true);
341 });
342
278 })(); // Anonymous namespace 343 })(); // Anonymous namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc ('k') | net/dns/host_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698