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.
5 // Include test fixture.
6 GEN_INCLUDE(['net_internals_test.js']);
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
15 var BASE_PATH
= 'files/sdch/base-page.html?iframe_url=';
18 * Checks the display on the SDCH tab against the information it should be
20 * @param {object} sdchInfo Results from a sdch manager info query.
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
);
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
));
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
));
51 // At least Domain cell should not be empty.
52 expectNotEquals(text
, '');
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}
63 function LoadSdchDictionaryTask() {
64 NetInternalsTest
.Task
.call(this);
67 LoadSdchDictionaryTask
.prototype = {
68 __proto__
: NetInternalsTest
.Task
.prototype,
71 * Navigates to the page and starts waiting to receive the results from
72 * the browser process.
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');
80 chrome
.send('loadPage', [url
]);
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.
89 onSdchInfoChanged: function(sdchInfo
) {
93 checkDisplay(sdchInfo
);
95 if (sdchInfo
.dictionaries
.length
> 0) {
96 var testDict
= sdchInfo
.dictionaries
.filter(function(dictionary
) {
97 return dictionary
.domain
=== 'sub.testdomain.com';
99 if (testDict
.length
=== 0)
102 expectEquals(1, testDict
.length
);
103 var dict
= testDict
[0];
104 expectEquals('/', dict
.path
);
105 expectTrue(dict
.url
.indexOf('/files/sdch/dict') !== -1);
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);
112 expectEquals(dict
.domain
, domain
);
113 expectEquals(dict
.path
, path
);
114 expectEquals(dict
.url
, url
);
116 this.onTaskDone(this.url_
);
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}
127 function LoadPageWithDecodeErrorTask(reason
) {
128 NetInternalsTest
.Task
.call(this);
129 this.reason_
= reason
;
132 LoadPageWithDecodeErrorTask
.prototype = {
133 __proto__
: NetInternalsTest
.Task
.prototype,
136 * Navigates to the page and starts waiting to receive the results from
137 * the browser process.
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
]);
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.
153 onSdchInfoChanged: function(sdchInfo
) {
157 checkDisplay(sdchInfo
);
159 if (sdchInfo
.blacklisted
.length
> 0) {
160 var testDomains
= sdchInfo
.blacklisted
.filter(function(entry
) {
161 return entry
.domain
=== 'sub.testdomain.com';
163 if (testDomains
.length
=== 0)
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
);
180 * Load a page, which results in downloading a SDCH dictionary. Make sure its
183 TEST_F('NetInternalsTest', 'netInternalsSdchViewFetchDictionary', function() {
184 var taskQueue
= new NetInternalsTest
.TaskQueue(true);
186 new NetInternalsTest
.GetTestServerURLTask(
187 BASE_PATH
+ encodeURI('/files/sdch/page.html')));
188 taskQueue
.addTask(new LoadSdchDictionaryTask());
193 * Load a page, get the dictionary for it, and get decoding error to see
194 * the blacklist in action.
196 TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistMeta', function() {
197 var taskQueue
= new NetInternalsTest
.TaskQueue(true);
199 new NetInternalsTest
.GetTestServerURLTask(
200 BASE_PATH
+ encodeURI('/files/sdch/page.html')));
201 taskQueue
.addTask(new LoadSdchDictionaryTask());
203 new NetInternalsTest
.GetTestServerURLTask(
204 BASE_PATH
+ encodeURI('/files/sdch/non-html')));
206 new LoadPageWithDecodeErrorTask('META_REFRESH_UNSUPPORTED'));
211 * Load a page, which is said to be SDCH-encoded, though we don't expect it.
213 TEST_F('NetInternalsTest', 'netInternalsSdchViewBlacklistNonSdch', function() {
214 var taskQueue
= new NetInternalsTest
.TaskQueue(true);
216 new NetInternalsTest
.GetTestServerURLTask(
217 BASE_PATH
+ encodeURI('/files/sdch/non-sdch.html')));
219 new LoadPageWithDecodeErrorTask('PASSING_THROUGH_NON_SDCH'));
223 })(); // Anonymous namespace