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