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

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

Powered by Google App Engine
This is Rietveld 408576698