1 // Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var equalASCIIFoldTests = []struct {
17 {"WebSocket", "websocket", true},
18 {"websocket", "WebSocket", true},
19 {"Öyster", "öyster", false},
20 {"WebSocket", "WetSocket", false},
23 func TestEqualASCIIFold(t *testing.T) {
24 for _, tt := range equalASCIIFoldTests {
25 eq := equalASCIIFold(tt.s, tt.t)
27 t.Errorf("equalASCIIFold(%q, %q) = %v, want %v", tt.s, tt.t, eq, tt.eq)
32 var tokenListContainsValueTests = []struct {
39 {"websockets", false},
40 {"x websocket", false},
41 {"websocket x", false},
42 {"other,websocket,more", true},
43 {"other, websocket, more", true},
46 func TestTokenListContainsValue(t *testing.T) {
47 for _, tt := range tokenListContainsValueTests {
48 h := http.Header{"Upgrade": {tt.value}}
49 ok := tokenListContainsValue(h, "Upgrade", "websocket")
51 t.Errorf("tokenListContainsValue(h, n, %q) = %v, want %v", tt.value, ok, tt.ok)
56 var parseExtensionTests = []struct {
58 extensions []map[string]string
60 {`foo`, []map[string]string{{"": "foo"}}},
61 {`foo, bar; baz=2`, []map[string]string{
63 {"": "bar", "baz": "2"}}},
64 {`foo; bar="b,a;z"`, []map[string]string{
65 {"": "foo", "bar": "b,a;z"}}},
66 {`foo , bar; baz = 2`, []map[string]string{
68 {"": "bar", "baz": "2"}}},
69 {`foo, bar; baz=2 junk`, []map[string]string{
71 {`foo junk, bar; baz=2 junk`, nil},
72 {`mux; max-channels=4; flow-control, deflate-stream`, []map[string]string{
73 {"": "mux", "max-channels": "4", "flow-control": ""},
74 {"": "deflate-stream"}}},
75 {`permessage-foo; x="10"`, []map[string]string{
76 {"": "permessage-foo", "x": "10"}}},
77 {`permessage-foo; use_y, permessage-foo`, []map[string]string{
78 {"": "permessage-foo", "use_y": ""},
79 {"": "permessage-foo"}}},
80 {`permessage-deflate; client_max_window_bits; server_max_window_bits=10 , permessage-deflate; client_max_window_bits`, []map[string]string{
81 {"": "permessage-deflate", "client_max_window_bits": "", "server_max_window_bits": "10"},
82 {"": "permessage-deflate", "client_max_window_bits": ""}}},
83 {"permessage-deflate; server_no_context_takeover; client_max_window_bits=15", []map[string]string{
84 {"": "permessage-deflate", "server_no_context_takeover": "", "client_max_window_bits": "15"},
88 func TestParseExtensions(t *testing.T) {
89 for _, tt := range parseExtensionTests {
90 h := http.Header{http.CanonicalHeaderKey("Sec-WebSocket-Extensions"): {tt.value}}
91 extensions := parseExtensions(h)
92 if !reflect.DeepEqual(extensions, tt.extensions) {
93 t.Errorf("parseExtensions(%q)\n = %v,\nwant %v", tt.value, extensions, tt.extensions)