1// Copyright (c) 2009 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/common/net/gaia/gaia_authenticator.h"
6
7#include <string>
8
9#include "chrome/common/net/http_return.h"
10#include "googleurl/src/gurl.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13using std::string;
14
15namespace gaia {
16
17class GaiaAuthenticatorTest : public testing::Test { };
18
19class GaiaAuthMockForGaiaAuthenticator : public GaiaAuthenticator {
20 public:
21  GaiaAuthMockForGaiaAuthenticator()
22      : GaiaAuthenticator("useragent", "serviceid", "http://gaia_url") {}
23  ~GaiaAuthMockForGaiaAuthenticator() {}
24 protected:
25  bool Post(const GURL& url, const string& post_body,
26            unsigned long* response_code, string* response_body) {
27    *response_code = RC_REQUEST_OK;
28    response_body->assign("body\n");
29    return true;
30  }
31
32  int GetBackoffDelaySeconds(
33      int current_backoff_delay) {
34    // Dummy delay value.
35    return 5;
36  }
37};
38
39TEST(GaiaAuthenticatorTest, TestNewlineAtEndOfAuthTokenRemoved) {
40  GaiaAuthMockForGaiaAuthenticator mock_auth;
41  MessageLoop message_loop;
42  mock_auth.set_message_loop(&message_loop);
43  GaiaAuthenticator::AuthResults results;
44  EXPECT_TRUE(mock_auth.IssueAuthToken(&results, "sid"));
45  EXPECT_EQ(0, results.auth_token.compare("body"));
46}
47
48}  // namespace gaia
49
50