• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 // A collection of classes that are useful when testing things that use a
6 // GaiaAuthFetcher.
7 
8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_
9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_
10 #pragma once
11 
12 #include <string>
13 
14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
15 #include "chrome/common/net/url_fetcher.h"
16 #include "chrome/common/net/http_return.h"
17 #include "net/url_request/url_request_status.h"
18 
19 // Responds as though ClientLogin returned from the server.
20 class MockFetcher : public URLFetcher {
21  public:
22   MockFetcher(bool success,
23               const GURL& url,
24               const std::string& results,
25               URLFetcher::RequestType request_type,
26               URLFetcher::Delegate* d);
27 
28   virtual ~MockFetcher();
29 
30   virtual void Start();
31 
32  private:
33   bool success_;
34   GURL url_;
35   std::string results_;
36   DISALLOW_COPY_AND_ASSIGN(MockFetcher);
37 };
38 
39 template<typename T>
40 class MockFactory : public URLFetcher::Factory {
41  public:
MockFactory()42   MockFactory()
43       : success_(true) {}
~MockFactory()44   ~MockFactory() {}
CreateURLFetcher(int id,const GURL & url,URLFetcher::RequestType request_type,URLFetcher::Delegate * d)45   URLFetcher* CreateURLFetcher(int id,
46                                const GURL& url,
47                                URLFetcher::RequestType request_type,
48                                URLFetcher::Delegate* d) {
49     return new T(success_, url, results_, request_type, d);
50   }
set_success(bool success)51   void set_success(bool success) {
52     success_ = success;
53   }
set_results(const std::string & results)54   void set_results(const std::string& results) {
55     results_ = results;
56   }
57  private:
58   bool success_;
59   std::string results_;
60   DISALLOW_COPY_AND_ASSIGN(MockFactory);
61 };
62 
63 #endif  // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_
64