Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / google_apis / gcm / engine / gcm_request_test_base.h
blob2af7b0ae7bc355a8bcf857d263e50a185b8f13a4
1 // Copyright 2015 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 "base/memory/ref_counted.h"
6 #include "base/test/test_mock_time_task_runner.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "net/base/backoff_entry.h"
9 #include "net/url_request/test_url_fetcher_factory.h"
10 #include "net/url_request/url_request_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace gcm {
15 // The base class for testing various GCM requests that contains all the common
16 // logic to set up a task runner and complete a request with retries.
17 class GCMRequestTestBase : public testing::Test {
18 public:
19 GCMRequestTestBase();
20 ~GCMRequestTestBase() override;
22 const net::BackoffEntry::Policy& GetBackoffPolicy() const;
23 net::TestURLFetcher* GetFetcher() const;
25 // Set the response status and body that will be returned by the URL fetch.
26 void SetResponse(net::HttpStatusCode status_code,
27 const std::string& response_body);
29 // Completes the URL fetch.
30 // It can be overridden by the test class to add additional logic.
31 virtual void CompleteFetch();
33 net::URLRequestContextGetter* url_request_context_getter() const {
34 return url_request_context_getter_.get();
37 private:
38 // Fast forward the timer used in the test to retry the request immediately.
39 void FastForwardToTriggerNextRetry();
41 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
42 base::ThreadTaskRunnerHandle task_runner_handle_;
43 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
45 net::TestURLFetcherFactory url_fetcher_factory_;
47 // Tracks the number of retries so far.
48 int retry_count_;
50 DISALLOW_COPY_AND_ASSIGN(GCMRequestTestBase);
53 } // namespace gcm