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

Side by Side Diff: net/spdy/spdy_alt_svc_wire_format_test.cc

Issue 1407643005: Add quotation marks around probability value in Alternative Services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 2 months 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
« no previous file with comments | « net/spdy/spdy_alt_svc_wire_format.cc ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_alt_svc_wire_format.h" 5 #include "net/spdy/spdy_alt_svc_wire_format.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 header_field_value->append("mA=1111"); 81 header_field_value->append("mA=1111");
82 if (i & 2 << 2) { 82 if (i & 2 << 2) {
83 header_field_value->append(" "); 83 header_field_value->append(" ");
84 } 84 }
85 } 85 }
86 if (i & 1 << 4) { 86 if (i & 1 << 4) {
87 header_field_value->append("; J=s"); 87 header_field_value->append("; J=s");
88 } 88 }
89 if (i & 1 << 5) { 89 if (i & 1 << 5) {
90 expected_altsvc->probability = 0.33; 90 expected_altsvc->probability = 0.33;
91 header_field_value->append("; P=.33"); 91 header_field_value->append("; P=\".33\"");
92 } 92 }
93 if (i & 1 << 6) { 93 if (i & 1 << 6) {
94 expected_altsvc->probability = 0.0; 94 expected_altsvc->probability = 0.0;
95 expected_altsvc->version = 24; 95 expected_altsvc->version = 24;
96 header_field_value->append("; p=0;v=24"); 96 header_field_value->append("; p=\"0\";v=24");
97 } 97 }
98 if (i & 1 << 7) { 98 if (i & 1 << 7) {
99 expected_altsvc->max_age = 999999999; 99 expected_altsvc->max_age = 999999999;
100 header_field_value->append("; Ma=999999999"); 100 header_field_value->append("; Ma=999999999");
101 } 101 }
102 if (i & 1 << 8) { 102 if (i & 1 << 8) {
103 expected_altsvc->probability = 0.0; 103 expected_altsvc->probability = 0.0;
104 header_field_value->append("; P=0."); 104 header_field_value->append("; P=\"0.\"");
105 } 105 }
106 if (i & 1 << 9) { 106 if (i & 1 << 9) {
107 header_field_value->append(";"); 107 header_field_value->append(";");
108 } 108 }
109 if (i & 1 << 10) { 109 if (i & 1 << 10) {
110 header_field_value->append(" "); 110 header_field_value->append(" ");
111 } 111 }
112 if (i & 1 << 11) { 112 if (i & 1 << 11) {
113 header_field_value->append(","); 113 header_field_value->append(",");
114 } 114 }
(...skipping 19 matching lines...) Expand all
134 if (i & 1 << 1) { 134 if (i & 1 << 1) {
135 altsvc->version = 24; 135 altsvc->version = 24;
136 expected_header_field_value->append("; v=24"); 136 expected_header_field_value->append("; v=24");
137 } 137 }
138 if (i & 1 << 2) { 138 if (i & 1 << 2) {
139 altsvc->max_age = 1111; 139 altsvc->max_age = 1111;
140 expected_header_field_value->append("; ma=1111"); 140 expected_header_field_value->append("; ma=1111");
141 } 141 }
142 if (i & 1 << 3) { 142 if (i & 1 << 3) {
143 altsvc->probability = 0.33; 143 altsvc->probability = 0.33;
144 expected_header_field_value->append("; p=0.33"); 144 expected_header_field_value->append("; p=\"0.33\"");
145 } 145 }
146 } 146 }
147 147
148 class SpdyAltSvcWireFormatTest : public ::testing::Test {}; 148 class SpdyAltSvcWireFormatTest : public ::testing::Test {};
149 149
150 // Tests of public API. 150 // Tests of public API.
151 151
152 TEST(SpdyAltSvcWireFormatTest, DefaultValues) { 152 TEST(SpdyAltSvcWireFormatTest, DefaultValues) {
153 SpdyAltSvcWireFormat::AlternativeService altsvc; 153 SpdyAltSvcWireFormat::AlternativeService altsvc;
154 EXPECT_EQ("", altsvc.protocol_id); 154 EXPECT_EQ("", altsvc.protocol_id);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 // ParseHeaderFieldValue() should return false on malformed field values: 262 // ParseHeaderFieldValue() should return false on malformed field values:
263 // invalid percent encoding, unmatched quotation mark, empty port, non-numeric 263 // invalid percent encoding, unmatched quotation mark, empty port, non-numeric
264 // characters in numeric fields, negative or larger than 1.0 probability. 264 // characters in numeric fields, negative or larger than 1.0 probability.
265 TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueInvalid) { 265 TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueInvalid) {
266 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; 266 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
267 const char* invalid_field_value_array[] = {"a%", "a%x", "a%b", "a%9z", 267 const char* invalid_field_value_array[] = {"a%", "a%x", "a%b", "a%9z",
268 "a=", "a=\"", "a=\"b\"", "a=\":\"", "a=\"c:\"", "a=\"c:foo\"", 268 "a=", "a=\"", "a=\"b\"", "a=\":\"", "a=\"c:\"", "a=\"c:foo\"",
269 "a=\"c:42foo\"", "a=\"b:42\"bar", "a=\"b:42\" ; m", 269 "a=\"c:42foo\"", "a=\"b:42\"bar", "a=\"b:42\" ; m",
270 "a=\"b:42\" ; min-age", "a=\"b:42\" ; ma", "a=\"b:42\" ; ma=", 270 "a=\"b:42\" ; min-age", "a=\"b:42\" ; ma", "a=\"b:42\" ; ma=",
271 "a=\"b:42\" ; ma=ma", "a=\"b:42\" ; ma=123bar", "a=\"b:42\" ; p=-2", 271 "a=\"b:42\" ; ma=ma", "a=\"b:42\" ; ma=123bar", "a=\"b:42\" ; p=\"-2\"",
272 "a=\"b:42\" ; p=..", "a=\"b:42\" ; p=1.05", 272 "a=\"b:42\" ; p=\"..\"", "a=\"b:42\" ; p=\"1.05\"", "a=\"b:42\" ; p=0.4",
273 "a=\"b:42\" ; v=-3", "a=\"b:42\" ; v=1.2"}; 273 "a=\"b:42\" ; p=\" 1.0\"", "a=\"b:42\" ; v=-3", "a=\"b:42\" ; v=1.2"};
274 for (const char* invalid_field_value : invalid_field_value_array) { 274 for (const char* invalid_field_value : invalid_field_value_array) {
275 EXPECT_FALSE(SpdyAltSvcWireFormat::ParseHeaderFieldValue( 275 EXPECT_FALSE(SpdyAltSvcWireFormat::ParseHeaderFieldValue(
276 invalid_field_value, &altsvc_vector)) 276 invalid_field_value, &altsvc_vector))
277 << invalid_field_value; 277 << invalid_field_value;
278 } 278 }
279 } 279 }
280 280
281 // ParseHeaderFieldValue() should return false on a field values truncated 281 // ParseHeaderFieldValue() should return false on a field values truncated
282 // before closing quotation mark, without trying to access memory beyond the end 282 // before closing quotation mark, without trying to access memory beyond the end
283 // of the input. 283 // of the input.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 StringPiece input(invalid_input); 503 StringPiece input(invalid_input);
504 double probability; 504 double probability;
505 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability( 505 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability(
506 input.begin(), input.end(), &probability)); 506 input.begin(), input.end(), &probability));
507 } 507 }
508 } 508 }
509 509
510 } // namespace 510 } // namespace
511 511
512 } // namespace net 512 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_alt_svc_wire_format.cc ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698