Clean up MFYI by adding suppressions for new bugs
[chromium-blink-merge.git] / net / http / http_vary_data_unittest.cc
blobcffa2d299ac85b7dd9a39837baeddda2c73a8b14
1 // Copyright (c) 2006-2008 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 <algorithm>
7 #include "net/http/http_request_info.h"
8 #include "net/http/http_response_headers.h"
9 #include "net/http/http_vary_data.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace {
14 typedef testing::Test HttpVaryDataTest;
16 struct TestTransaction {
17 net::HttpRequestInfo request;
18 scoped_refptr<net::HttpResponseHeaders> response;
20 void Init(const std::string& request_headers,
21 const std::string& response_headers) {
22 std::string temp(response_headers);
23 std::replace(temp.begin(), temp.end(), '\n', '\0');
24 response = new net::HttpResponseHeaders(temp);
26 request.extra_headers.Clear();
27 request.extra_headers.AddHeadersFromString(request_headers);
31 } // namespace
33 TEST(HttpVaryDataTest, IsInvalid) {
34 // All of these responses should result in an invalid vary data object.
35 const char* kTestResponses[] = {
36 "HTTP/1.1 200 OK\n\n",
37 "HTTP/1.1 200 OK\nVary: *\n\n",
38 "HTTP/1.1 200 OK\nVary: cookie, *, bar\n\n",
39 "HTTP/1.1 200 OK\nVary: cookie\nFoo: 1\nVary: *\n\n",
42 for (size_t i = 0; i < arraysize(kTestResponses); ++i) {
43 TestTransaction t;
44 t.Init(std::string(), kTestResponses[i]);
46 net::HttpVaryData v;
47 EXPECT_FALSE(v.is_valid());
48 EXPECT_FALSE(v.Init(t.request, *t.response.get()));
49 EXPECT_FALSE(v.is_valid());
53 TEST(HttpVaryDataTest, MultipleInit) {
54 net::HttpVaryData v;
56 // Init to something valid.
57 TestTransaction t1;
58 t1.Init("Foo: 1\r\nbar: 23", "HTTP/1.1 200 OK\nVary: foo, bar\n\n");
59 EXPECT_TRUE(v.Init(t1.request, *t1.response.get()));
60 EXPECT_TRUE(v.is_valid());
62 // Now overwrite by initializing to something invalid.
63 TestTransaction t2;
64 t2.Init("Foo: 1\r\nbar: 23", "HTTP/1.1 200 OK\nVary: *\n\n");
65 EXPECT_FALSE(v.Init(t2.request, *t2.response.get()));
66 EXPECT_FALSE(v.is_valid());
69 TEST(HttpVaryDataTest, DoesVary) {
70 TestTransaction a;
71 a.Init("Foo: 1", "HTTP/1.1 200 OK\nVary: foo\n\n");
73 TestTransaction b;
74 b.Init("Foo: 2", "HTTP/1.1 200 OK\nVary: foo\n\n");
76 net::HttpVaryData v;
77 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
79 EXPECT_FALSE(v.MatchesRequest(b.request, *b.response.get()));
82 TEST(HttpVaryDataTest, DoesVary2) {
83 TestTransaction a;
84 a.Init("Foo: 1\r\nbar: 23", "HTTP/1.1 200 OK\nVary: foo, bar\n\n");
86 TestTransaction b;
87 b.Init("Foo: 12\r\nbar: 3", "HTTP/1.1 200 OK\nVary: foo, bar\n\n");
89 net::HttpVaryData v;
90 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
92 EXPECT_FALSE(v.MatchesRequest(b.request, *b.response.get()));
95 TEST(HttpVaryDataTest, DoesntVary) {
96 TestTransaction a;
97 a.Init("Foo: 1", "HTTP/1.1 200 OK\nVary: foo\n\n");
99 TestTransaction b;
100 b.Init("Foo: 1", "HTTP/1.1 200 OK\nVary: foo\n\n");
102 net::HttpVaryData v;
103 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
105 EXPECT_TRUE(v.MatchesRequest(b.request, *b.response.get()));
108 TEST(HttpVaryDataTest, DoesntVary2) {
109 TestTransaction a;
110 a.Init("Foo: 1\r\nbAr: 2", "HTTP/1.1 200 OK\nVary: foo, bar\n\n");
112 TestTransaction b;
113 b.Init("Foo: 1\r\nbaR: 2", "HTTP/1.1 200 OK\nVary: foo\nVary: bar\n\n");
115 net::HttpVaryData v;
116 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
118 EXPECT_TRUE(v.MatchesRequest(b.request, *b.response.get()));
121 TEST(HttpVaryDataTest, ImplicitCookieForRedirect) {
122 TestTransaction a;
123 a.Init("Cookie: 1", "HTTP/1.1 301 Moved\nLocation: x\n\n");
125 TestTransaction b;
126 b.Init("Cookie: 2", "HTTP/1.1 301 Moved\nLocation: x\n\n");
128 net::HttpVaryData v;
129 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
131 EXPECT_FALSE(v.MatchesRequest(b.request, *b.response.get()));
134 TEST(HttpVaryDataTest, ImplicitCookieForRedirect2) {
135 // This should be no different than the test above
137 TestTransaction a;
138 a.Init("Cookie: 1", "HTTP/1.1 301 Moved\nLocation: x\nVary: coOkie\n\n");
140 TestTransaction b;
141 b.Init("Cookie: 2", "HTTP/1.1 301 Moved\nLocation: x\nVary: cooKie\n\n");
143 net::HttpVaryData v;
144 EXPECT_TRUE(v.Init(a.request, *a.response.get()));
146 EXPECT_FALSE(v.MatchesRequest(b.request, *b.response.get()));