OLD | NEW |
(Empty) | |
| 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 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/common/net/url_fetcher.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/url_request/url_request_status.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace chromeos { |
| 15 |
| 16 ExpectCanceledFetcher::ExpectCanceledFetcher( |
| 17 bool success, |
| 18 const GURL& url, |
| 19 const std::string& results, |
| 20 URLFetcher::RequestType request_type, |
| 21 URLFetcher::Delegate* d) |
| 22 : URLFetcher(url, request_type, d) { |
| 23 } |
| 24 |
| 25 ExpectCanceledFetcher::~ExpectCanceledFetcher() { |
| 26 task_->Cancel(); |
| 27 } |
| 28 |
| 29 void ExpectCanceledFetcher::Start() { |
| 30 LOG(INFO) << "Delaying fetch completion in mock"; |
| 31 task_ = NewRunnableFunction(&ExpectCanceledFetcher::CompleteFetch); |
| 32 ChromeThread::PostDelayedTask(ChromeThread::UI, |
| 33 FROM_HERE, |
| 34 task_, |
| 35 100); |
| 36 } |
| 37 |
| 38 // static |
| 39 void ExpectCanceledFetcher::CompleteFetch() { |
| 40 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!"; |
| 41 MessageLoop::current()->Quit(); // Allow exiting even if we mess up. |
| 42 } |
| 43 |
| 44 GotCanceledFetcher::GotCanceledFetcher(bool success, |
| 45 const GURL& url, |
| 46 const std::string& results, |
| 47 URLFetcher::RequestType request_type, |
| 48 URLFetcher::Delegate* d) |
| 49 : URLFetcher(url, request_type, d), |
| 50 url_(url) { |
| 51 LOG(INFO) << url_.spec(); |
| 52 } |
| 53 |
| 54 GotCanceledFetcher::~GotCanceledFetcher() {} |
| 55 |
| 56 void GotCanceledFetcher::Start() { |
| 57 URLRequestStatus status; |
| 58 status.set_status(URLRequestStatus::CANCELED); |
| 59 delegate()->OnURLFetchComplete(this, |
| 60 url_, |
| 61 status, |
| 62 403, |
| 63 ResponseCookies(), |
| 64 std::string()); |
| 65 } |
| 66 |
| 67 } // namespace chromeos |
OLD | NEW |