"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "add_headers_fetcher_test.cc" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
1.13.35.2_vs_1.14.36.1.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 //
21 // Unit tests for AddHeadersFetcher.
22 //
23 #include "pagespeed/system/add_headers_fetcher.h"
24
25 #include "net/instaweb/http/public/mock_callback.h"
26 #include "net/instaweb/http/public/reflecting_test_fetcher.h"
27 #include "net/instaweb/http/public/request_context.h"
28 #include "net/instaweb/rewriter/public/rewrite_options.h"
29 #include "net/instaweb/rewriter/public/rewrite_options_test_base.h"
30 #include "pagespeed/kernel/base/google_message_handler.h"
31 #include "pagespeed/kernel/base/gtest.h"
32 #include "pagespeed/kernel/base/scoped_ptr.h"
33 #include "pagespeed/kernel/base/string_util.h"
34 #include "pagespeed/kernel/base/thread_system.h" // for ThreadSystem
35 #include "pagespeed/kernel/http/request_headers.h"
36 #include "pagespeed/kernel/http/response_headers.h"
37 #include "pagespeed/kernel/util/platform.h"
38
39 namespace net_instaweb {
40
41 namespace {
42
43 class AddHeadersFetcherTest : public RewriteOptionsTestBase<RewriteOptions> {
44 public:
45 AddHeadersFetcherTest()
46 : thread_system_(Platform::CreateThreadSystem()),
47 options_(thread_system_.get()) {
48 options_.AddCustomFetchHeader("Custom", "custom-header");
49 options_.AddCustomFetchHeader("Extra", "extra-header");
50 add_headers_fetcher_.reset(new AddHeadersFetcher(
51 &options_, &reflecting_fetcher_));
52 }
53
54 protected:
55 scoped_ptr<AddHeadersFetcher> add_headers_fetcher_;
56 GoogleMessageHandler handler_;
57 scoped_ptr<ThreadSystem> thread_system_;
58 RewriteOptions options_;
59 ReflectingTestFetcher reflecting_fetcher_;
60 };
61
62 TEST_F(AddHeadersFetcherTest, AddsHeaders) {
63 ExpectStringAsyncFetch dest(
64 true, RequestContext::NewTestRequestContext(thread_system_.get()));
65 add_headers_fetcher_->Fetch("http://example.com/path", &handler_, &dest);
66 EXPECT_STREQ("http://example.com/path", dest.buffer());
67 EXPECT_STREQ("custom-header", dest.response_headers()->Lookup1("Custom"));
68 EXPECT_STREQ("extra-header", dest.response_headers()->Lookup1("Extra"));
69 }
70
71 TEST_F(AddHeadersFetcherTest, ReplacesHeaders) {
72 RequestHeaders request_headers;
73 ExpectStringAsyncFetch dest(
74 true, RequestContext::NewTestRequestContext(thread_system_.get()));
75 request_headers.Add("Custom", "original");
76 request_headers.Add("AlsoCustom", "original");
77 dest.set_request_headers(&request_headers);
78 add_headers_fetcher_->Fetch("http://example.com/path", &handler_, &dest);
79 EXPECT_STREQ("http://example.com/path", dest.buffer());
80
81 // Overwritten by the add headers fetcher.
82 EXPECT_STREQ("custom-header", dest.response_headers()->Lookup1("Custom"));
83
84 // Passed through unmodified.
85 EXPECT_STREQ("original", dest.response_headers()->Lookup1("AlsoCustom"));
86 }
87
88 } // namespace
89
90 } // namespace net_instaweb
91