Home | History | Annotate | Download | only in login
      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 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h"
      6 
      7 #include <string>
      8 
      9 #include "base/message_loop.h"
     10 #include "chrome/common/net/url_fetcher.h"
     11 #include "googleurl/src/gurl.h"
     12 #include "net/url_request/url_request_status.h"
     13 #include "testing/gmock/include/gmock/gmock.h"
     14 
     15 namespace chromeos {
     16 
     17 using ::testing::_;
     18 using ::testing::Invoke;
     19 
     20 MockAuthResponseHandler::MockAuthResponseHandler(
     21     const GURL& url,
     22     const net::URLRequestStatus& status,
     23     const int code,
     24     const std::string& data)
     25     : remote_(url),
     26       status_(status),
     27       http_response_code_(code),
     28       data_(data) {
     29   // Take the args sent to Handle() and pass them to MockNetwork(), which will
     30   // use the data passed to the constructor here to fill out the call to
     31   // OnURLFetchComplete().
     32   ON_CALL(*this, Handle(_,_))
     33       .WillByDefault(Invoke(this, &MockAuthResponseHandler::MockNetwork));
     34 }
     35 
     36 void MockAuthResponseHandler::CompleteFetch(URLFetcher::Delegate* delegate,
     37                                             const GURL remote,
     38                                             const net::URLRequestStatus status,
     39                                             const int http_response_code,
     40                                             const std::string data) {
     41   delegate->OnURLFetchComplete(NULL,
     42                                remote,
     43                                status,
     44                                http_response_code,
     45                                ResponseCookies(),
     46                                data);
     47 }
     48 
     49 URLFetcher* MockAuthResponseHandler::MockNetwork(
     50     std::string data,
     51     URLFetcher::Delegate* delegate) {
     52   MessageLoop::current()->PostTask(
     53       FROM_HERE,
     54       NewRunnableFunction(MockAuthResponseHandler::CompleteFetch,
     55                           delegate,
     56                           remote_,
     57                           status_,
     58                           http_response_code_,
     59                           data_));
     60   return new URLFetcher(GURL(), URLFetcher::GET, delegate);
     61 }
     62 
     63 }  // namespace chromeos
     64