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

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

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Declare SdchProblemCode Created 6 years, 1 month 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
(Empty)
1 // Copyright 2014 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 /**
12 * Checks the display on the SDCH tab against the information it should be
13 * displaying.
14 * @param {object} sdchInfo Results from a sdch manager info query.
15 */
16 function checkDisplay(sdchInfo) {
17 var tab = $(SdchView.MAIN_BOX_ID);
18 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.
19 expectEquals(2, stateLis.length);
20 expectEquals(sdchInfo.sdch_enabled,
21 stateLis[0].querySelector('span').innerText === 'true');
22 expectEquals(sdchInfo.secure_scheme_support,
23 stateLis[1].querySelector('span').innerText === 'true');
24 NetInternalsTest.checkTbodyRows(SdchView.BLACKLIST_TBODY_ID,
25 sdchInfo.blacklisted.length);
26 NetInternalsTest.checkTbodyRows(SdchView.DICTIONARIES_TBODY_ID,
27 sdchInfo.dictionaries.length);
28
29 // Rather than check the exact string in every position, just make sure every
30 // entry does not have 'undefined' anywhere, which should find a fair number
31 // of potential output errors.
32 for (var row = 0; row < sdchInfo.blacklisted.length; ++row) {
33 for (column = 0; column < 3; ++column) {
34 var text = NetInternalsTest.getTbodyText(
35 SdchView.BLACKLIST_TBODY_ID, row, column);
36 expectFalse(/undefined/i.test(text));
37 }
38 }
39
40 for (var row = 0; row < sdchInfo.dictionaries.length; ++row) {
41 for (column = 0; column < 6; ++column) {
42 var text = NetInternalsTest.getTbodyText(
43 SdchView.DICTIONARIES_TBODY_ID, row, column);
44 expectFalse(/undefined/i.test(text));
45 }
46 }
47 }
48
49 /**
50 * A Task that loads provided page and waits for the SDCH dictionary to be
51 * downloaded. The page response headers should provide Get-Dictionary header.
52 * @extends {NetInternalsTest.Task}
53 */
54 function LoadSdchDictionaryTask() {
55 NetInternalsTest.Task.call(this);
56 }
57
58 LoadSdchDictionaryTask.prototype = {
59 __proto__: NetInternalsTest.Task.prototype,
60
61 /**
62 * Navigates to the page and starts waiting to receive the results from
63 * the browser process.
64 */
65 start: function(url) {
66 g_browser.addSdchInfoObserver(this, false)
67 NetInternalsTest.switchToView('sdch');
68 // 127.0.0.1 is not allowed to be an SDCH domain, so we need another one.
69 url = url.replace('127.0.0.1', 'testdomain.com');
70 this.url_ = url;
71 console.log(url);
72 chrome.send('loadPage', [url]);
73 },
74
75 /**
76 * Callback from the BrowserBridge. Checks if |sdchInfo| has the SDCH
77 * dictionary info for the dictionary the page has advertised. If so,
78 * validates it and completes the task. If not, continues running.
79 * @param {object} sdchInfo Results a SDCH manager info query.
80 */
81 onSdchInfoChanged: function(sdchInfo) {
82 if (this.isDone())
83 return;
84
85 checkDisplay(sdchInfo);
86
87 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
88 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.
89 return e.domain === 'testdomain.com';
90 });
91 if (testDict.length === 0)
92 return;
93
94 expectEquals(1, testDict.length);
95 var dict = testDict[0];
96 expectEquals('/', dict.path);
97 expectTrue(dict.url.indexOf('/files/sdch/dict') !== -1);
98
99 var tableId = SdchView.DICTIONARIES_TBODY_ID;
100 var domain = NetInternalsTest.getTbodyText(tableId, 0, 0);
101 var path = NetInternalsTest.getTbodyText(tableId, 0, 1);
102 var url = NetInternalsTest.getTbodyText(tableId, 0, 5);
103
104 expectEquals(dict.domain, domain);
105 expectEquals(dict.path, path);
106 expectEquals(dict.url, url);
107
108 this.onTaskDone(this.url_);
109 }
110 }
111 };
112
113 /**
114 * A Task that loads provided page and waits for its domain to appear in SDCH
115 * blacklist with the specified reason.
116 * @param {string} reason Blacklist reason we're waiting for.
117 * @extends {NetInternalsTest.Task}
118 */
119 function LoadPageWithDecodeErrorTask(reason) {
120 NetInternalsTest.Task.call(this);
121 this.reason_ = reason;
122 }
123
124 LoadPageWithDecodeErrorTask.prototype = {
125 __proto__: NetInternalsTest.Task.prototype,
126
127 /**
128 * Navigates to the page and starts waiting to receive the results from
129 * the browser process.
130 */
131 start: function(url) {
132 g_browser.addSdchInfoObserver(this, false)
133 NetInternalsTest.switchToView('sdch');
134 // 127.0.0.1 is not allowed to be an SDCH domain, so we need another one.
135 url = url.replace('127.0.0.1', 'testdomain.com');
136 console.log(url);
137 chrome.send('loadPage', [url]);
138 },
139
140 /**
141 * Callback from the BrowserBridge. Checks if |sdchInfo.blacklisted| contains
142 * the test domain with the reason specified on creation. If so, validates it
143 * and completes the task. If not, continues running.
144 * @param {object} sdchInfo Results a SDCH manager info query.
145 */
146 onSdchInfoChanged: function(sdchInfo) {
147 if (this.isDone())
148 return;
149
150 checkDisplay(sdchInfo);
151
152 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
153 var testDomains = sdchInfo.blacklisted.filter(function(e) {
154 return e.domain === 'testdomain.com';
155 });
156 if (testDomains.length === 0)
157 return;
158
159 expectEquals(1, testDomains.length);
160 var entry = testDomains[0];
161 expectEquals(this.reason_,
162 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.
163 var tableId = SdchView.BLACKLIST_TBODY_ID;
164 var domain = NetInternalsTest.getTbodyText(tableId, 0, 0);
165 var reason = NetInternalsTest.getTbodyText(tableId, 0, 1);
166 expectEquals(entry.domain, domain);
167 expectEquals(this.reason_, reason);
168 this.onTaskDone();
169 }
170 }
171 };
172
173 /**
174 * Load a page, which provide SDCH dictionary. Make sure we have its data
175 * displayed.
176 */
177 TEST_F('NetInternalsTest', 'netInternalsSdchViewFetchDictionary', function() {
178 var taskQueue = new NetInternalsTest.TaskQueue(true);
179 taskQueue.addTask(
180 new NetInternalsTest.GetTestServerURLTask('files/sdch/page.html'));
181 taskQueue.addTask(new LoadSdchDictionaryTask());
182 taskQueue.run();
183 });
184
185 /**
186 * Load a page, get the dictionary for it, and get decoding error to see
187 * the blacklist in action.
188 */
189 TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistMeta', function() {
190 var taskQueue = new NetInternalsTest.TaskQueue(true);
191 taskQueue.addTask(
192 new NetInternalsTest.GetTestServerURLTask('files/sdch/page.html'));
193 taskQueue.addTask(new LoadSdchDictionaryTask());
194 taskQueue.addTask(
195 new NetInternalsTest.GetTestServerURLTask('files/sdch/non-sdch.html'));
196 taskQueue.addTask(new LoadPageWithDecodeErrorTask('META_REFRESH_RECOVERY'));
197 taskQueue.run();
198 });
199
200 /**
201 * Load a page, which is said to be SDCH-encoded, though we don't expect it.
202 */
203 TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistNonSdch', function() {
204 var taskQueue = new NetInternalsTest.TaskQueue(true);
205 taskQueue.addTask(
206 new NetInternalsTest.GetTestServerURLTask('files/sdch/non-sdch.html'));
207 taskQueue.addTask(
208 new LoadPageWithDecodeErrorTask('PASSING_THROUGH_NON_SDCH'));
209 taskQueue.run();
210 });
211
212 })(); // Anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698