1 // Copyright (c) 2012 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']);
12 * Checks the display on the HTTP Pipelining tab against the information it
13 * should be displaying.
14 * @param {object} httpPipelineStatus Results from a http pipeline status query.
16 function checkDisplay(httpPipelineStatus) {
17 expectEquals(httpPipelineStatus.pipelining_enabled,
18 $(HttpPipelineView.ENABLED_SPAN_ID).innerText == "true");
22 * Finds an entry with the specified host name and port in the
23 * |pipelinedHostInfo| cache, and returns its index.
24 * @param {object} pipelinedHostInfo Results to search.
25 * @param {string} hostname The host name of the host to find.
26 * @param {int} port The port of the host to find.
27 * @return {int} Index of the specified host. -1 if not found.
29 function findEntry(pipelinedHostInfo, hostname, port) {
30 var expected = hostname + ":" + port;
31 for (var i = 0; i < pipelinedHostInfo.length; ++i) {
32 if (pipelinedHostInfo[i].host == expected)
39 * A Task that adds a pipeline capability to the known hosts map and waits for
40 * it to appear in the data we receive from the browser.
41 * @param {string} hostname Name of host address we're waiting for.
42 * @param {int} port Port of the host we're waiting for.
43 * @param {string} capability The capability to set.
44 * @extends {NetInternalsTest.Task}
46 function AddPipelineCapabilityTask(hostname, port, capability) {
47 this.hostname_ = hostname;
49 this.capability_ = capability;
50 NetInternalsTest.Task.call(this);
53 AddPipelineCapabilityTask.prototype = {
54 __proto__: NetInternalsTest.Task.prototype,
57 * Adds an entry to the host map and starts waiting to receive the results
58 * from the browser process.
61 var addPipelineCapabilityParams = [
66 chrome.send('addDummyHttpPipelineFeedback', addPipelineCapabilityParams);
67 g_browser.addHttpPipeliningStatusObserver(this, false);
71 * Callback from the BrowserBridge. Checks if |httpPipelineStatus| has the
72 * known host specified on creation. If so, validates it and completes the
73 * task. If not, continues running.
74 * @param {object} httpPipelineStatus Result of a http pipeline status query.
76 onHttpPipeliningStatusChanged: function(httpPipelineStatus) {
78 checkDisplay(httpPipelineStatus);
80 var index = findEntry(httpPipelineStatus.pipelined_host_info,
81 this.hostname_, this.port_);
83 var entry = httpPipelineStatus.pipelined_host_info[index];
84 expectEquals(this.capability_, entry.capability);
86 var hostPortText = NetInternalsTest.getTbodyText(
87 HttpPipelineView.KNOWN_HOSTS_TABLE_ID, index, 0);
88 expectEquals(this.hostname_ + ":" + this.port_, hostPortText);
89 var capabilityText = NetInternalsTest.getTbodyText(
90 HttpPipelineView.KNOWN_HOSTS_TABLE_ID, index, 1);
91 expectEquals(this.capability_, capabilityText);
100 * Adds a capable pipelining host.
102 TEST_F('NetInternalsTest', 'netInternalsHttpPipelineViewCapable', function() {
103 // Since this is called before we switch to the HTTP Pipelining view, we'll
104 // never see the original pipelining state.
105 chrome.send('enableHttpPipelining', [true]);
107 NetInternalsTest.switchToView('httpPipeline');
108 var taskQueue = new NetInternalsTest.TaskQueue(true);
109 taskQueue.addTask(new AddPipelineCapabilityTask(
110 'somewhere.com', 80, 'capable'));
115 * Adds an incapable pipelining host.
117 TEST_F('NetInternalsTest', 'netInternalsHttpPipelineViewIncapable', function() {
118 // Since this is called before we switch to the HTTP Pipelining view, we'll
119 // never see the original pipelining state.
120 chrome.send('enableHttpPipelining', [true]);
122 NetInternalsTest.switchToView('httpPipeline');
123 var taskQueue = new NetInternalsTest.TaskQueue(true);
124 taskQueue.addTask(new AddPipelineCapabilityTask(
125 'elsewhere.com', 1234, 'incapable'));
130 * Checks with pipelining disabled.
131 * TODO(mmenke): Make this test wait to receive pipelining state. Currently
132 * just checks the default state, before data is received.
134 TEST_F('NetInternalsTest', 'netInternalsHttpPipelineViewDisabled', function() {
135 NetInternalsTest.switchToView('httpPipeline');
136 var expected_status = { pipelining_enabled: false }
137 checkDisplay(expected_status);
141 })(); // Anonymous namespace