1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/message_loop.h" 12 #include "chrome/common/net/url_fetcher.h" 13 #include "googleurl/src/gurl.h" 14 #include "net/url_request/url_request_status.h" 15 16 namespace chromeos { 17 18 // Simulates a URL fetch by posting a delayed task. This fetch expects to be 19 // canceled, and fails the test if it is not 20 class ExpectCanceledFetcher : public URLFetcher { 21 public: 22 ExpectCanceledFetcher(bool success, 23 const GURL& url, 24 const std::string& results, 25 URLFetcher::RequestType request_type, 26 URLFetcher::Delegate* d); 27 virtual ~ExpectCanceledFetcher(); 28 29 void Start(); 30 31 static void CompleteFetch(); 32 33 private: 34 CancelableTask* task_; 35 36 DISALLOW_COPY_AND_ASSIGN(ExpectCanceledFetcher); 37 }; 38 39 class GotCanceledFetcher : public URLFetcher { 40 public: 41 GotCanceledFetcher(bool success, 42 const GURL& url, 43 const std::string& results, 44 URLFetcher::RequestType request_type, 45 URLFetcher::Delegate* d); 46 virtual ~GotCanceledFetcher(); 47 48 void Start(); 49 50 private: 51 GURL url_; 52 53 DISALLOW_COPY_AND_ASSIGN(GotCanceledFetcher); 54 }; 55 56 class SuccessFetcher : public URLFetcher { 57 public: 58 SuccessFetcher(bool success, 59 const GURL& url, 60 const std::string& results, 61 URLFetcher::RequestType request_type, 62 URLFetcher::Delegate* d); 63 virtual ~SuccessFetcher(); 64 65 void Start(); 66 67 private: 68 GURL url_; 69 70 DISALLOW_COPY_AND_ASSIGN(SuccessFetcher); 71 }; 72 73 class FailFetcher : public URLFetcher { 74 public: 75 FailFetcher(bool success, 76 const GURL& url, 77 const std::string& results, 78 URLFetcher::RequestType request_type, 79 URLFetcher::Delegate* d); 80 virtual ~FailFetcher(); 81 82 void Start(); 83 84 private: 85 GURL url_; 86 87 DISALLOW_COPY_AND_ASSIGN(FailFetcher); 88 }; 89 90 class CaptchaFetcher : public URLFetcher { 91 public: 92 CaptchaFetcher(bool success, 93 const GURL& url, 94 const std::string& results, 95 URLFetcher::RequestType request_type, 96 URLFetcher::Delegate* d); 97 virtual ~CaptchaFetcher(); 98 99 static std::string GetCaptchaToken(); 100 static std::string GetCaptchaUrl(); 101 static std::string GetUnlockUrl(); 102 103 void Start(); 104 105 private: 106 static const char kCaptchaToken[]; 107 static const char kCaptchaUrlBase[]; 108 static const char kCaptchaUrlFragment[]; 109 static const char kUnlockUrl[]; 110 GURL url_; 111 112 DISALLOW_COPY_AND_ASSIGN(CaptchaFetcher); 113 }; 114 115 class HostedFetcher : public URLFetcher { 116 public: 117 HostedFetcher(bool success, 118 const GURL& url, 119 const std::string& results, 120 URLFetcher::RequestType request_type, 121 URLFetcher::Delegate* d); 122 virtual ~HostedFetcher(); 123 124 void Start(); 125 126 private: 127 GURL url_; 128 129 DISALLOW_COPY_AND_ASSIGN(HostedFetcher); 130 }; 131 132 } // namespace chromeos 133 134 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ 135