Remove SpdySessionTest pre-SPDY/3.1 conditionals.
[chromium-blink-merge.git] / net / http / http_byte_range_unittest.cc
blob0a77da3ed3988ed3076da77a1bcade14043b683f
1 // Copyright (c) 2009 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 "net/http/http_byte_range.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace net {
10 namespace {
12 TEST(HttpByteRangeTest, ValidRanges) {
13 const struct {
14 int64 first_byte_position;
15 int64 last_byte_position;
16 int64 suffix_length;
17 bool valid;
18 } tests[] = {
19 { -1, -1, 0, false },
20 { 0, 0, 0, true },
21 { -10, 0, 0, false },
22 { 10, 0, 0, false },
23 { 10, -1, 0, true },
24 { -1, -1, -1, false },
25 { -1, 50, 0, false },
26 { 10, 10000, 0, true },
27 { -1, -1, 100000, true },
30 for (size_t i = 0; i < arraysize(tests); ++i) {
31 HttpByteRange range;
32 range.set_first_byte_position(tests[i].first_byte_position);
33 range.set_last_byte_position(tests[i].last_byte_position);
34 range.set_suffix_length(tests[i].suffix_length);
35 EXPECT_EQ(tests[i].valid, range.IsValid());
39 TEST(HttpByteRangeTest, SetInstanceSize) {
40 const struct {
41 int64 first_byte_position;
42 int64 last_byte_position;
43 int64 suffix_length;
44 int64 instance_size;
45 bool expected_return_value;
46 int64 expected_lower_bound;
47 int64 expected_upper_bound;
48 } tests[] = {
49 { -10, 0, -1, 0, false, -1, -1 },
50 { 10, 0, -1, 0, false, -1, -1 },
51 // Zero instance size is valid, this is the case that user has to handle.
52 { -1, -1, -1, 0, true, 0, -1 },
53 { -1, -1, 500, 0, true, 0, -1 },
54 { -1, 50, -1, 0, false, -1, -1 },
55 { -1, -1, 500, 300, true, 0, 299 },
56 { -1, -1, -1, 100, true, 0, 99 },
57 { 10, -1, -1, 100, true, 10, 99 },
58 { -1, -1, 500, 1000, true, 500, 999 },
59 { 10, 10000, -1, 1000000, true, 10, 10000 },
62 for (size_t i = 0; i < arraysize(tests); ++i) {
63 HttpByteRange range;
64 range.set_first_byte_position(tests[i].first_byte_position);
65 range.set_last_byte_position(tests[i].last_byte_position);
66 range.set_suffix_length(tests[i].suffix_length);
68 bool return_value = range.ComputeBounds(tests[i].instance_size);
69 EXPECT_EQ(tests[i].expected_return_value, return_value);
70 if (return_value) {
71 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position());
72 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position());
74 // Try to call SetInstanceSize the second time.
75 EXPECT_FALSE(range.ComputeBounds(tests[i].instance_size));
76 // And expect there's no side effect.
77 EXPECT_EQ(tests[i].expected_lower_bound, range.first_byte_position());
78 EXPECT_EQ(tests[i].expected_upper_bound, range.last_byte_position());
79 EXPECT_EQ(tests[i].suffix_length, range.suffix_length());
84 TEST(HttpByteRangeTest, GetHeaderValue) {
85 static const struct {
86 HttpByteRange range;
87 const char* expected;
88 } tests[] = {
89 {HttpByteRange::Bounded(0, 0), "bytes=0-0"},
90 {HttpByteRange::Bounded(0, 100), "bytes=0-100"},
91 {HttpByteRange::Bounded(0, -1), "bytes=0-"},
92 {HttpByteRange::RightUnbounded(100), "bytes=100-"},
93 {HttpByteRange::Suffix(100), "bytes=-100"},
95 for (size_t i = 0; i < arraysize(tests); ++i) {
96 EXPECT_EQ(tests[i].expected, tests[i].range.GetHeaderValue());
100 } // namespace
102 } // namespace net