Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fetcher_test.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
20 
21 #ifndef NET_INSTAWEB_HTTP_PUBLIC_FETCHER_TEST_H_
22 #define NET_INSTAWEB_HTTP_PUBLIC_FETCHER_TEST_H_
23 
24 #include "base/logging.h"
28 #include "net/instaweb/http/public/request_context.h"
38 
39 namespace net_instaweb {
40 
41 class ResponseHeaders;
42 class UrlAsyncFetcher;
43 
44 class FetcherTest : public testing::Test {
45  protected:
46  static const char kStartDate[];
47  static const char kHtmlContent[];
48  static const char kGoodUrl[];
49  static const char kNotCachedUrl[];
50  static const char kBadUrl[];
51  static const char kHeaderName[];
52  static const char kHeaderValue[];
53  static const char kErrorMessage[];
54 
55  FetcherTest();
56 
58 
63  return &wait_url_async_fetcher_;
64  }
65 
66  CountingUrlAsyncFetcher* counting_fetcher() { return &counting_fetcher_; }
67 
71  public:
72  CheckCallback(const RequestContextPtr& ctx, bool expect_success,
73  bool check_error_message,
74  bool* callback_called)
75  : StringAsyncFetch(ctx),
76  expect_success_(expect_success),
77  check_error_message_(check_error_message),
78  callback_called_(callback_called) {
79  }
80 
81  virtual void HandleDone(bool success) {
82  *callback_called_ = true;
83  CHECK_EQ(expect_success_, success);
85  success, check_error_message_, buffer(), *response_headers());
86  delete this;
87  }
88 
89  private:
90  bool expect_success_;
91  bool check_error_message_;
92  bool* callback_called_;
93 
94 
95  };
96 
98  static void ValidateMockFetcherResponse(
99  bool success, bool check_error_message, const GoogleString& content,
100  const ResponseHeaders& response_headers);
101 
105  int CountFetchesAsync(const StringPiece& url, bool expect_success,
106  bool* callback_called);
107 
110  int CountFetchesAsync(const StringPiece& url, UrlAsyncFetcher* fetcher,
111  bool expect_success, bool check_error_message,
112  bool* callback_called);
113 
118  LOG(FATAL) << "async_fetcher() must be overridden before use.";
119  return NULL;
120  };
121 
122  GoogleString TestFilename() {
123  return (GTestSrcDir() +
124  "/net/instaweb/http/testdata/google.http");
125  }
126 
129  void ValidateOutput(const GoogleString& content,
130  const ResponseHeaders& response_headers);
131 
132  GoogleMessageHandler message_handler_;
133  MockUrlFetcher mock_fetcher_;
134  WaitUrlAsyncFetcher wait_url_async_fetcher_;
135  CountingUrlAsyncFetcher counting_fetcher_;
136  scoped_ptr<ThreadSystem> thread_system_;
137  SimpleStats statistics_;
138 
139  private:
140  void Populate(const char* cache_control,
141  ResponseHeaders* response_headers,
142  GoogleString* content);
143 
144 
145 };
146 
147 }
148 
149 #endif
Definition: counting_url_async_fetcher.h:36
Definition: fetcher_test.h:70
ResponseHeaders * response_headers()
See doc for request_headers and set_request_headers.
Read/write API for HTTP response headers.
Definition: response_headers.h:37
virtual UrlAsyncFetcher * async_fetcher()
Definition: fetcher_test.h:117
WaitUrlAsyncFetcher * wait_fetcher()
Helpful classes for testing.
Definition: fetcher_test.h:62
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: fetcher_test.h:44
Definition: wait_url_async_fetcher.h:37
static void ValidateMockFetcherResponse(bool success, bool check_error_message, const GoogleString &content, const ResponseHeaders &response_headers)
This checks that response matches the mock response we setup.
void ValidateOutput(const GoogleString &content, const ResponseHeaders &response_headers)
Definition: async_fetch.h:192
int CountFetchesAsync(const StringPiece &url, bool expect_success, bool *callback_called)
Definition: url_async_fetcher.h:33