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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/nacl_http_response_headers_unittest.cc

Issue 16569002: Use HTTP response headers for PNaCl caching instead of bitcode hash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use RunAndClear Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "native_client/src/trusted/plugin/nacl_http_response_headers.h"
6
7 #include <string>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 // Test that we are able to discover the cache validator headers.
12 TEST(NaClHttpResponseHeadersTest, TestGetValidators) {
13 // Test a single (weak) ETag.
14 std::string one_val_headers("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
15 "Server: Apache/2.0.52 (CentOS)\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Connection: close\n"
18 "Accept-Ranges: bytes\n"
19 "ETag: w\"abcdefg\"\n"
20 "Content-Length: 2912652\n");
21 std::string one_val_expected("ETag:w\"abcdefg\"");
22 plugin::NaClHttpResponseHeaders parser_1;
23 parser_1.Parse(one_val_headers);
24 EXPECT_EQ(parser_1.GetCacheValidators(), one_val_expected);
25
26 // Test a Last-Modified Header.
27 std::string mod_val_headers("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
28 "Server: Apache/2.0.52 (CentOS)\n"
29 "Content-Type: text/plain; charset=UTF-8\n"
30 "Connection: close\n"
31 "Accept-Ranges: bytes\n"
32 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
33 "Content-Length: 2912652\n");
34 std::string mod_val_expected("Last-Modified:Wed, 15 Nov 1995 04:58:08 GMT");
35 plugin::NaClHttpResponseHeaders parser_1b;
36 parser_1b.Parse(mod_val_headers);
37 EXPECT_EQ(parser_1b.GetCacheValidators(), mod_val_expected);
38
39 // Test both (strong) ETag and Last-Modified, with some whitespace.
40 std::string two_val_headers("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
41 "Last-modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
42 "Server: Apache/2.0.52 (CentOS)\n"
43 "etag \t :\t \"/abcdefg:A-Z0-9+/==\"\n"
44 "Content-Type: text/plain; charset=UTF-8\n"
45 "cache-control: no-cache\n"
46 "Connection: close\n"
47 "Accept-Ranges: bytes\n"
48 "Content-Length: 2912652\n");
49 // Note that the value can still have white-space.
50 std::string two_val_expected("Last-modified:Wed, 15 Nov 1995 04:58:08 GMT&"
51 "etag:\"/abcdefg:A-Z0-9+/==\"");
52 plugin::NaClHttpResponseHeaders parser_2;
53 parser_2.Parse(two_val_headers);
54 EXPECT_EQ(parser_2.GetCacheValidators(), two_val_expected);
55
56 // Some etag generators like python HTTP server use ' instead of "
57 std::string single_q_headers("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
58 "Server: BaseHTTP/0.3 Python/2.7.3\n"
59 "ETag: '/usr/local/some_file.nmf'\n");
60 std::string single_q_expected("ETag:'/usr/local/some_file.nmf'");
61 plugin::NaClHttpResponseHeaders parser_3;
62 parser_3.Parse(single_q_headers);
63 EXPECT_EQ(parser_3.GetCacheValidators(), single_q_expected);
64
65 // Keys w/ leading whitespace are invalid.
66 // See: HttpResponseHeadersTest.NormalizeHeadersLeadingWhitespace.
67 std::string bad_headers("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
68 "Server: BaseHTTP/0.3 Python/2.7.3\n"
69 " ETag: '/usr/local/some_file.nmf'\n");
70 std::string bad_expected("");
71 plugin::NaClHttpResponseHeaders parser_4;
72 parser_4.Parse(bad_headers);
73 EXPECT_EQ(parser_4.GetCacheValidators(), bad_expected);
74 }
75
76 // Test that we are able to determine when there is a no-store
77 // Cache-Control header, among all the Cache-Control headers.
78 TEST(NaClHttpResponseHeadersTest, TestFindNoStore) {
79 // Say that there isn't one, when there isn't one.
80 std::string headers_0("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
81 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
82 "ETag: '/tmp/blah.nmf'\n"
83 "Cache-Control: max-age=3600\n");
84 plugin::NaClHttpResponseHeaders parser_0;
85 parser_0.Parse(headers_0);
86 EXPECT_FALSE(parser_0.CacheControlNoStore());
87
88 // Say that there is one, when there is one.
89 std::string headers_1("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
90 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
91 "ETag: \"/abcdefgA-Z0-9+/\"\n"
92 "Cache-Control: no-store\n");
93 plugin::NaClHttpResponseHeaders parser_1;
94 parser_1.Parse(headers_1);
95 EXPECT_TRUE(parser_1.CacheControlNoStore());
96
97 // Say that there is one, when comma separated.
98 std::string headers_2("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
99 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
100 "ETag: \"/abcdefgA-Z0-9+/\"\n"
101 "Cache-Control: no-store, no-cache\n");
102 plugin::NaClHttpResponseHeaders parser_2;
103 parser_2.Parse(headers_2);
104 EXPECT_TRUE(parser_2.CacheControlNoStore());
105
106 // Comma separated, in a different position.
107 std::string headers_3("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
108 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
109 "ETag: \"/abcdefgA-Z0-9+/\"\n"
110 "Cache-control: no-cache, max-age=60, no-store\n");
111 plugin::NaClHttpResponseHeaders parser_3;
112 parser_3.Parse(headers_3);
113 EXPECT_TRUE(parser_3.CacheControlNoStore());
114
115 // Test multiple cache-control lines, plus extra space before colon.
116 std::string headers_4("Date: Wed, 15 Nov 1995 06:25:24 GMT\n"
117 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT\n"
118 "ETag: \"/abcdefgA-Z0-9+/\"\n"
119 "cache-control: no-cache\n"
120 "cache-control \t : max-age=60, no-store, max-stale\n");
121 plugin::NaClHttpResponseHeaders parser_4;
122 parser_4.Parse(headers_4);
123 EXPECT_TRUE(parser_4.CacheControlNoStore());
124
125 // Test with extra whitespace, in the values.
126 std::string headers_5("Date: Wed, 15 Nov 1995 06:25:24 GMT \n"
127 "Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT \n"
128 "ETag: \"/abcdefgA-Z0-9+/\" \n"
129 ": empty key \n"
130 ": empty key2 \n"
131 "Blank-Header : \n"
132 "Connection: close\n"
133 "cache-control:max-age=60, no-store \n"
134 "cache-control: no-cache\n");
135 plugin::NaClHttpResponseHeaders parser_5;
136 parser_5.Parse(headers_5);
137 EXPECT_TRUE(parser_5.CacheControlNoStore());
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698