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

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

Issue 1420783002: Add quotation marks around probability value in Alternative Services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2526
Patch Set: 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 if (i & 2 << 2) { 83 if (i & 2 << 2) {
84 header_field_value->append(" "); 84 header_field_value->append(" ");
85 } 85 }
86 } 86 }
87 if (i & 1 << 4) { 87 if (i & 1 << 4) {
88 header_field_value->append("; J=s"); 88 header_field_value->append("; J=s");
89 } 89 }
90 expected_altsvc->p = 1.0; 90 expected_altsvc->p = 1.0;
91 if (i & 1 << 5) { 91 if (i & 1 << 5) {
92 expected_altsvc->p = 0.33; 92 expected_altsvc->p = 0.33;
93 header_field_value->append("; P=.33"); 93 header_field_value->append("; P=\".33\"");
94 } 94 }
95 if (i & 1 << 6) { 95 if (i & 1 << 6) {
96 expected_altsvc->p = 0.0; 96 expected_altsvc->p = 0.0;
97 header_field_value->append("; p=0"); 97 header_field_value->append("; p=\"0\"");
98 } 98 }
99 if (i & 1 << 7) { 99 if (i & 1 << 7) {
100 expected_altsvc->max_age = 999999999; 100 expected_altsvc->max_age = 999999999;
101 header_field_value->append("; Ma=999999999"); 101 header_field_value->append("; Ma=999999999");
102 } 102 }
103 if (i & 1 << 8) { 103 if (i & 1 << 8) {
104 expected_altsvc->p = 0.0; 104 expected_altsvc->p = 0.0;
105 header_field_value->append("; P=0."); 105 header_field_value->append("; P=\"0.\"");
106 } 106 }
107 if (i & 1 << 9) { 107 if (i & 1 << 9) {
108 header_field_value->append(";"); 108 header_field_value->append(";");
109 } 109 }
110 if (i & 1 << 10) { 110 if (i & 1 << 10) {
111 header_field_value->append(" "); 111 header_field_value->append(" ");
112 } 112 }
113 if (i & 1 << 11) { 113 if (i & 1 << 11) {
114 header_field_value->append(","); 114 header_field_value->append(",");
115 } 115 }
(...skipping 17 matching lines...) Expand all
133 } 133 }
134 expected_header_field_value->append(":42\""); 134 expected_header_field_value->append(":42\"");
135 altsvc->max_age = 86400; 135 altsvc->max_age = 86400;
136 if (i & 1 << 1) { 136 if (i & 1 << 1) {
137 altsvc->max_age = 1111; 137 altsvc->max_age = 1111;
138 expected_header_field_value->append("; ma=1111"); 138 expected_header_field_value->append("; ma=1111");
139 } 139 }
140 altsvc->p = 1.0; 140 altsvc->p = 1.0;
141 if (i & 1 << 2) { 141 if (i & 1 << 2) {
142 altsvc->p = 0.33; 142 altsvc->p = 0.33;
143 expected_header_field_value->append("; p=0.33"); 143 expected_header_field_value->append("; p=\"0.33\"");
144 } 144 }
145 } 145 }
146 146
147 class SpdyAltSvcWireFormatTest : public ::testing::Test {}; 147 class SpdyAltSvcWireFormatTest : public ::testing::Test {};
148 148
149 // Tests of public API. 149 // Tests of public API.
150 150
151 TEST(SpdyAltSvcWireFormatTest, ParseEmptyHeaderFieldValue) { 151 TEST(SpdyAltSvcWireFormatTest, ParseEmptyHeaderFieldValue) {
152 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; 152 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
153 ASSERT_TRUE(SpdyAltSvcWireFormat::ParseHeaderFieldValue("", &altsvc_vector)); 153 ASSERT_TRUE(SpdyAltSvcWireFormat::ParseHeaderFieldValue("", &altsvc_vector));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 // ParseHeaderFieldValue() should return false on malformed field values: 241 // ParseHeaderFieldValue() should return false on malformed field values:
242 // invalid percent encoding, unmatched quotation mark, empty port, non-numeric 242 // invalid percent encoding, unmatched quotation mark, empty port, non-numeric
243 // characters in numeric fields, negative or larger than 1.0 probability. 243 // characters in numeric fields, negative or larger than 1.0 probability.
244 TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueInvalid) { 244 TEST(SpdyAltSvcWireFormatTest, ParseHeaderFieldValueInvalid) {
245 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; 245 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector;
246 const char* invalid_field_value_array[] = {"a%", "a%x", "a%b", "a%9z", 246 const char* invalid_field_value_array[] = {"a%", "a%x", "a%b", "a%9z",
247 "a=", "a=\"", "a=\"b\"", "a=\":\"", "a=\"c:\"", "a=\"c:foo\"", 247 "a=", "a=\"", "a=\"b\"", "a=\":\"", "a=\"c:\"", "a=\"c:foo\"",
248 "a=\"c:42foo\"", "a=\"b:42\"bar", "a=\"b:42\" ; m", 248 "a=\"c:42foo\"", "a=\"b:42\"bar", "a=\"b:42\" ; m",
249 "a=\"b:42\" ; min-age", "a=\"b:42\" ; ma", "a=\"b:42\" ; ma=", 249 "a=\"b:42\" ; min-age", "a=\"b:42\" ; ma", "a=\"b:42\" ; ma=",
250 "a=\"b:42\" ; ma=ma", "a=\"b:42\" ; ma=123bar", "a=\"b:42\" ; p=-2", 250 "a=\"b:42\" ; ma=ma", "a=\"b:42\" ; ma=123bar", "a=\"b:42\" ; p=\"-2\"",
251 "a=\"b:42\" ; p=..", "a=\"b:42\" ; p=1.05"}; 251 "a=\"b:42\" ; p=\"..\"", "a=\"b:42\" ; p=\"1.05\"", "a=\"b:42\" ; p=0.4",
252 "a=\"b:42\" ; p=\" 1.0\""};
252 for (const char* invalid_field_value : invalid_field_value_array) { 253 for (const char* invalid_field_value : invalid_field_value_array) {
253 EXPECT_FALSE(SpdyAltSvcWireFormat::ParseHeaderFieldValue( 254 EXPECT_FALSE(SpdyAltSvcWireFormat::ParseHeaderFieldValue(
254 invalid_field_value, &altsvc_vector)) 255 invalid_field_value, &altsvc_vector))
255 << invalid_field_value; 256 << invalid_field_value;
256 } 257 }
257 } 258 }
258 259
259 // ParseHeaderFieldValue() should return false on a field values truncated 260 // ParseHeaderFieldValue() should return false on a field values truncated
260 // before closing quotation mark, without trying to access memory beyond the end 261 // before closing quotation mark, without trying to access memory beyond the end
261 // of the input. 262 // of the input.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 StringPiece input(invalid_input); 482 StringPiece input(invalid_input);
482 double probability; 483 double probability;
483 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability( 484 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability(
484 input.begin(), input.end(), &probability)); 485 input.begin(), input.end(), &probability));
485 } 486 }
486 } 487 }
487 488
488 } // namespace 489 } // namespace
489 490
490 } // namespace net 491 } // 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