Chromium Code Reviews| Index: chrome/test/data/webui/net_internals/dns_view.js |
| diff --git a/chrome/test/data/webui/net_internals/dns_view.js b/chrome/test/data/webui/net_internals/dns_view.js |
| index acdabc50b5b69eabac3ed2d8ca09597cbc236b10..f2e317a7d344efcd90c60439d89a78adc5d84446 100644 |
| --- a/chrome/test/data/webui/net_internals/dns_view.js |
| +++ b/chrome/test/data/webui/net_internals/dns_view.js |
| @@ -1,3 +1,4 @@ |
| + |
|
eroman
2017/03/28 22:41:59
nit: remove this change
mgersh
2017/03/29 18:15:25
Done.
|
| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -101,7 +102,7 @@ AddCacheEntryTask.prototype = { |
| * Callback from the BrowserBridge. Checks if |hostResolverInfo| has the |
| * DNS entry specified on creation. If so, validates it and completes the |
| * task. If not, continues running. |
| - * @param {object} hostResolverInfo Results a host resolver info query. |
| + * @param {object} hostResolverInfo Results of a host resolver info query. |
| */ |
| onHostResolverInfoChanged: function(hostResolverInfo) { |
| if (!this.isDone()) { |
| @@ -129,7 +130,7 @@ AddCacheEntryTask.prototype = { |
| // only if |expired_| is true. Only checked for entries we add |
| // ourselves to avoid any expiration time race. |
| var expirationText = |
| - NetInternalsTest.getTbodyText(DnsView.CACHE_TBODY_ID, index, 3); |
| + NetInternalsTest.getTbodyText(DnsView.CACHE_TBODY_ID, index, 4); |
| expectEquals(this.expired_, /expired/i.test(expirationText)); |
| this.onTaskDone(); |
| @@ -149,7 +150,57 @@ AddCacheEntryTask.prototype = { |
| }; |
| /** |
| - * A Task clears the cache by simulating a button click. |
| + * A Task that simulates a network change and checks that cache entries are |
|
eroman
2017/03/28 22:41:59
nice job adding tests!
mgersh
2017/03/29 18:15:25
thanks :)
|
| + * expired. |
| + * @extends {NetInternalsTest.Task} |
| + */ |
| +function NetworkChangeTask() { |
| + NetInternalsTest.Task.call(this); |
| +} |
| + |
| +NetworkChangeTask.prototype = { |
| + __proto__: NetInternalsTest.Task.prototype, |
| + |
| + start: function() { |
| + chrome.send('changeNetwork'); |
| + g_browser.addHostResolverInfoObserver(this, false); |
| + }, |
| + |
| + /** |
| + * Callback from the BrowserBridge. Checks if the entry has been expired. |
| + * If so, the task completes. |
| + * @param {object} hostResolverInfo Results of a host resolver info query. |
| + */ |
| + onHostResolverInfoChanged: function(hostResolverInfo) { |
| + if (!this.isDone()) { |
| + checkDisplay(hostResolverInfo); |
| + |
| + var entries = hostResolverInfo.cache.entries; |
| + var tableId = DnsView.CACHE_TBODY_ID; |
| + var foundExpired = false; |
| + |
| + // Look for an entry that's expired due to a network change. |
| + for (var row = 0; row < entries.length; ++row) { |
| + var text = NetInternalsTest.getTbodyText(tableId, row, 5); |
| + if (/expired/i.test(text)) { |
| + foundExpired = true; |
| + }; |
| + } |
| + |
| + if (foundExpired) { |
| + // Expect at least one expired entry and at least one network change. |
| + // To avoid any chance of a race, exact values are not tested. |
| + expectLE(0, parseInt($(DnsView.ACTIVE_SPAN_ID).innerText)); |
| + expectLE(1, parseInt($(DnsView.EXPIRED_SPAN_ID).innerText)); |
| + expectLE(1, parseInt($(DnsView.NETWORK_SPAN_ID).innerText)); |
| + this.onTaskDone(); |
| + } |
| + } |
| + } |
| +}; |
| + |
| +/** |
| + * A Task that clears the cache by simulating a button click. |
| * @extends {NetInternalsTest.Task} |
| */ |
| function ClearCacheTask() { |
| @@ -275,4 +326,19 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewIncognitoClears', function() { |
| taskQueue.run(true); |
| }); |
| +/** |
| + * Adds a successful lookup to the DNS cache, then simulates a network change |
| + * and checks that the entry expires. |
| + */ |
| +TEST_F('NetInternalsTest', 'netInternalsDnsViewNetworkChanged', function() { |
| + NetInternalsTest.switchToView('dns'); |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask(new AddCacheEntryTask( |
| + 'somewhere.com', '1.2.3.4', 0, false)); |
| + taskQueue.addTask(new NetworkChangeTask()); |
| + taskQueue.addTask(new ClearCacheTask()); |
| + taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com')); |
| + taskQueue.run(true); |
| +}); |
| + |
| })(); // Anonymous namespace |