Chromium Code Reviews| Index: chrome/test/data/webui/net_internals/sdch_view.js |
| diff --git a/chrome/test/data/webui/net_internals/sdch_view.js b/chrome/test/data/webui/net_internals/sdch_view.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..100a7e5fd3f007e596a3c3a29175722c4ab81711 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/net_internals/sdch_view.js |
| @@ -0,0 +1,212 @@ |
| +// Copyright 2014 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. |
| + |
| +// Include test fixture. |
| +GEN_INCLUDE(['net_internals_test.js']); |
| + |
| +// Anonymous namespace |
| +(function() { |
| + |
| +/** |
| + * Checks the display on the SDCH tab against the information it should be |
| + * displaying. |
| + * @param {object} sdchInfo Results from a sdch manager info query. |
| + */ |
| +function checkDisplay(sdchInfo) { |
| + var tab = $(SdchView.MAIN_BOX_ID); |
| + var stateLis = tab.querySelectorAll('ul>li'); |
|
Randy Smith (Not in Mondays)
2014/10/29 16:15:46
I don't think of this selector as being as "future
baranovich
2014/10/29 18:28:43
Done.
|
| + expectEquals(2, stateLis.length); |
| + expectEquals(sdchInfo.sdch_enabled, |
| + stateLis[0].querySelector('span').innerText === 'true'); |
| + expectEquals(sdchInfo.secure_scheme_support, |
| + stateLis[1].querySelector('span').innerText === 'true'); |
| + NetInternalsTest.checkTbodyRows(SdchView.BLACKLIST_TBODY_ID, |
| + sdchInfo.blacklisted.length); |
| + NetInternalsTest.checkTbodyRows(SdchView.DICTIONARIES_TBODY_ID, |
| + sdchInfo.dictionaries.length); |
| + |
| + // Rather than check the exact string in every position, just make sure every |
| + // entry does not have 'undefined' anywhere, which should find a fair number |
| + // of potential output errors. |
| + for (var row = 0; row < sdchInfo.blacklisted.length; ++row) { |
| + for (column = 0; column < 3; ++column) { |
| + var text = NetInternalsTest.getTbodyText( |
| + SdchView.BLACKLIST_TBODY_ID, row, column); |
| + expectFalse(/undefined/i.test(text)); |
| + } |
| + } |
| + |
| + for (var row = 0; row < sdchInfo.dictionaries.length; ++row) { |
| + for (column = 0; column < 6; ++column) { |
| + var text = NetInternalsTest.getTbodyText( |
| + SdchView.DICTIONARIES_TBODY_ID, row, column); |
| + expectFalse(/undefined/i.test(text)); |
| + } |
| + } |
| +} |
| + |
| +/** |
| + * A Task that loads provided page and waits for the SDCH dictionary to be |
| + * downloaded. The page response headers should provide Get-Dictionary header. |
| + * @extends {NetInternalsTest.Task} |
| + */ |
| +function LoadSdchDictionaryTask() { |
| + NetInternalsTest.Task.call(this); |
| +} |
| + |
| +LoadSdchDictionaryTask.prototype = { |
| + __proto__: NetInternalsTest.Task.prototype, |
| + |
| + /** |
| + * Navigates to the page and starts waiting to receive the results from |
| + * the browser process. |
| + */ |
| + start: function(url) { |
| + g_browser.addSdchInfoObserver(this, false) |
| + NetInternalsTest.switchToView('sdch'); |
| + // 127.0.0.1 is not allowed to be an SDCH domain, so we need another one. |
| + url = url.replace('127.0.0.1', 'testdomain.com'); |
| + this.url_ = url; |
| + console.log(url); |
| + chrome.send('loadPage', [url]); |
| + }, |
| + |
| + /** |
| + * Callback from the BrowserBridge. Checks if |sdchInfo| has the SDCH |
| + * dictionary info for the dictionary the page has advertised. If so, |
| + * validates it and completes the task. If not, continues running. |
| + * @param {object} sdchInfo Results a SDCH manager info query. |
| + */ |
| + onSdchInfoChanged: function(sdchInfo) { |
| + if (this.isDone()) |
| + return; |
| + |
| + checkDisplay(sdchInfo); |
| + |
| + if (sdchInfo.dictionaries.length > 0) { |
|
Randy Smith (Not in Mondays)
2014/10/29 16:15:46
There's an anti-pattern here I want to call out, t
baranovich
2014/10/29 18:28:43
I don't like that either, but this approach is use
mmenke
2014/10/29 22:03:21
This is a valid point. I suppose we could wait on
mmenke
2014/10/29 22:51:14
Thinking about it a bit more, waiting on the NetLo
|
| + var testDict = sdchInfo.dictionaries.filter(function(e) { |
|
mmenke
2014/10/29 22:03:21
nit: Per the style guide, don't use single-letter
baranovich
2014/10/30 00:33:22
Done.
|
| + return e.domain === 'testdomain.com'; |
| + }); |
| + if (testDict.length === 0) |
| + return; |
| + |
| + expectEquals(1, testDict.length); |
| + var dict = testDict[0]; |
| + expectEquals('/', dict.path); |
| + expectTrue(dict.url.indexOf('/files/sdch/dict') !== -1); |
| + |
| + var tableId = SdchView.DICTIONARIES_TBODY_ID; |
| + var domain = NetInternalsTest.getTbodyText(tableId, 0, 0); |
| + var path = NetInternalsTest.getTbodyText(tableId, 0, 1); |
| + var url = NetInternalsTest.getTbodyText(tableId, 0, 5); |
| + |
| + expectEquals(dict.domain, domain); |
| + expectEquals(dict.path, path); |
| + expectEquals(dict.url, url); |
| + |
| + this.onTaskDone(this.url_); |
| + } |
| + } |
| +}; |
| + |
| +/** |
| + * A Task that loads provided page and waits for its domain to appear in SDCH |
| + * blacklist with the specified reason. |
| + * @param {string} reason Blacklist reason we're waiting for. |
| + * @extends {NetInternalsTest.Task} |
| + */ |
| +function LoadPageWithDecodeErrorTask(reason) { |
| + NetInternalsTest.Task.call(this); |
| + this.reason_ = reason; |
| +} |
| + |
| +LoadPageWithDecodeErrorTask.prototype = { |
| + __proto__: NetInternalsTest.Task.prototype, |
| + |
| + /** |
| + * Navigates to the page and starts waiting to receive the results from |
| + * the browser process. |
| + */ |
| + start: function(url) { |
| + g_browser.addSdchInfoObserver(this, false) |
| + NetInternalsTest.switchToView('sdch'); |
| + // 127.0.0.1 is not allowed to be an SDCH domain, so we need another one. |
| + url = url.replace('127.0.0.1', 'testdomain.com'); |
| + console.log(url); |
| + chrome.send('loadPage', [url]); |
| + }, |
| + |
| + /** |
| + * Callback from the BrowserBridge. Checks if |sdchInfo.blacklisted| contains |
| + * the test domain with the reason specified on creation. If so, validates it |
| + * and completes the task. If not, continues running. |
| + * @param {object} sdchInfo Results a SDCH manager info query. |
| + */ |
| + onSdchInfoChanged: function(sdchInfo) { |
| + if (this.isDone()) |
| + return; |
| + |
| + checkDisplay(sdchInfo); |
| + |
| + if (sdchInfo.blacklisted.length > 0) { |
|
Randy Smith (Not in Mondays)
2014/10/29 16:15:46
Might there be a way to avoid the anti-pattern I m
mmenke
2014/10/29 22:03:21
The blacklist is pulled, not pushed, so not quite
|
| + var testDomains = sdchInfo.blacklisted.filter(function(e) { |
| + return e.domain === 'testdomain.com'; |
| + }); |
| + if (testDomains.length === 0) |
| + return; |
| + |
| + expectEquals(1, testDomains.length); |
| + var entry = testDomains[0]; |
| + expectEquals(this.reason_, |
| + sdchProblemCodeToString(entry.reason)); |
|
Randy Smith (Not in Mondays)
2014/10/29 16:15:46
nit: Looks like these two lines could fit in one l
baranovich
2014/10/29 18:28:43
Done.
|
| + var tableId = SdchView.BLACKLIST_TBODY_ID; |
| + var domain = NetInternalsTest.getTbodyText(tableId, 0, 0); |
| + var reason = NetInternalsTest.getTbodyText(tableId, 0, 1); |
| + expectEquals(entry.domain, domain); |
| + expectEquals(this.reason_, reason); |
| + this.onTaskDone(); |
| + } |
| + } |
| +}; |
| + |
| +/** |
| + * Load a page, which provide SDCH dictionary. Make sure we have its data |
| + * displayed. |
| + */ |
| +TEST_F('NetInternalsTest', 'netInternalsSdchViewFetchDictionary', function() { |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask( |
| + new NetInternalsTest.GetTestServerURLTask('files/sdch/page.html')); |
| + taskQueue.addTask(new LoadSdchDictionaryTask()); |
| + taskQueue.run(); |
| +}); |
| + |
| +/** |
| + * Load a page, get the dictionary for it, and get decoding error to see |
| + * the blacklist in action. |
| + */ |
| +TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistMeta', function() { |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask( |
| + new NetInternalsTest.GetTestServerURLTask('files/sdch/page.html')); |
| + taskQueue.addTask(new LoadSdchDictionaryTask()); |
| + taskQueue.addTask( |
| + new NetInternalsTest.GetTestServerURLTask('files/sdch/non-sdch.html')); |
| + taskQueue.addTask(new LoadPageWithDecodeErrorTask('META_REFRESH_RECOVERY')); |
| + taskQueue.run(); |
| +}); |
| + |
| +/** |
| + * Load a page, which is said to be SDCH-encoded, though we don't expect it. |
| + */ |
| +TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistNonSdch', function() { |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask( |
| + new NetInternalsTest.GetTestServerURLTask('files/sdch/non-sdch.html')); |
| + taskQueue.addTask( |
| + new LoadPageWithDecodeErrorTask('PASSING_THROUGH_NON_SDCH')); |
| + taskQueue.run(); |
| +}); |
| + |
| +})(); // Anonymous namespace |