Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/common/net/gaia/google_service_auth_error_unittest.cc

Issue 10928017: Moving google_apis and GaiaClient to src/google_apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/google_service_auth_error.h"
6
7 #include <string>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/values_test_util.h"
11 #include "base/values.h"
12 #include "net/base/net_errors.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 using base::ExpectDictStringValue;
18
19 class GoogleServiceAuthErrorTest : public testing::Test {};
20
21 void TestSimpleState(GoogleServiceAuthError::State state) {
22 GoogleServiceAuthError error(state);
23 scoped_ptr<DictionaryValue> value(error.ToValue());
24 EXPECT_EQ(1u, value->size());
25 std::string state_str;
26 EXPECT_TRUE(value->GetString("state", &state_str));
27 EXPECT_FALSE(state_str.empty());
28 EXPECT_NE("CONNECTION_FAILED", state_str);
29 EXPECT_NE("CAPTCHA_REQUIRED", state_str);
30 }
31
32 TEST_F(GoogleServiceAuthErrorTest, SimpleToValue) {
33 for (int i = GoogleServiceAuthError::NONE;
34 i <= GoogleServiceAuthError::USER_NOT_SIGNED_UP; ++i) {
35 TestSimpleState(static_cast<GoogleServiceAuthError::State>(i));
36 }
37 }
38
39 TEST_F(GoogleServiceAuthErrorTest, None) {
40 GoogleServiceAuthError error(GoogleServiceAuthError::None());
41 scoped_ptr<DictionaryValue> value(error.ToValue());
42 EXPECT_EQ(1u, value->size());
43 ExpectDictStringValue("NONE", *value, "state");
44 }
45
46 TEST_F(GoogleServiceAuthErrorTest, ConnectionFailed) {
47 GoogleServiceAuthError error(
48 GoogleServiceAuthError::FromConnectionError(net::OK));
49 scoped_ptr<DictionaryValue> value(error.ToValue());
50 EXPECT_EQ(2u, value->size());
51 ExpectDictStringValue("CONNECTION_FAILED", *value, "state");
52 ExpectDictStringValue("net::OK", *value, "networkError");
53 }
54
55 TEST_F(GoogleServiceAuthErrorTest, CaptchaChallenge) {
56 GoogleServiceAuthError error(
57 GoogleServiceAuthError::FromClientLoginCaptchaChallenge(
58 "captcha_token", GURL("http://www.google.com"),
59 GURL("http://www.bing.com")));
60 scoped_ptr<DictionaryValue> value(error.ToValue());
61 EXPECT_EQ(2u, value->size());
62 ExpectDictStringValue("CAPTCHA_REQUIRED", *value, "state");
63 DictionaryValue* captcha_value = NULL;
64 EXPECT_TRUE(value->GetDictionary("captcha", &captcha_value));
65 ASSERT_TRUE(captcha_value);
66 ExpectDictStringValue("captcha_token", *captcha_value, "token");
67 ExpectDictStringValue("", *captcha_value, "audioUrl");
68 ExpectDictStringValue("http://www.google.com/", *captcha_value, "imageUrl");
69 ExpectDictStringValue("http://www.bing.com/", *captcha_value, "unlockUrl");
70 ExpectDictIntegerValue(0, *captcha_value, "imageWidth");
71 ExpectDictIntegerValue(0, *captcha_value, "imageHeight");
72 }
73
74 TEST_F(GoogleServiceAuthErrorTest, CaptchaChallenge2) {
75 GoogleServiceAuthError error(
76 GoogleServiceAuthError::FromCaptchaChallenge(
77 "captcha_token", GURL("http://www.audio.com"),
78 GURL("http://www.image.com"), 320, 200));
79 scoped_ptr<DictionaryValue> value(error.ToValue());
80 EXPECT_EQ(2u, value->size());
81 ExpectDictStringValue("CAPTCHA_REQUIRED", *value, "state");
82 DictionaryValue* captcha_value = NULL;
83 EXPECT_TRUE(value->GetDictionary("captcha", &captcha_value));
84 ASSERT_TRUE(captcha_value);
85 ExpectDictStringValue("captcha_token", *captcha_value, "token");
86 ExpectDictStringValue("http://www.audio.com/", *captcha_value, "audioUrl");
87 ExpectDictStringValue("http://www.image.com/", *captcha_value, "imageUrl");
88 ExpectDictIntegerValue(320, *captcha_value, "imageWidth");
89 ExpectDictIntegerValue(200, *captcha_value, "imageHeight");
90 }
91
92 TEST_F(GoogleServiceAuthErrorTest, TwoFactorChallenge) {
93 GoogleServiceAuthError error(
94 GoogleServiceAuthError::FromSecondFactorChallenge(
95 "two_factor_token", "prompt_text", "alternate_text", 10));
96 scoped_ptr<DictionaryValue> value(error.ToValue());
97 EXPECT_EQ(2u, value->size());
98 ExpectDictStringValue("TWO_FACTOR", *value, "state");
99 DictionaryValue* two_factor_value = NULL;
100 EXPECT_TRUE(value->GetDictionary("two_factor", &two_factor_value));
101 ASSERT_TRUE(two_factor_value);
102 ExpectDictStringValue("two_factor_token", *two_factor_value, "token");
103 ExpectDictStringValue("prompt_text", *two_factor_value, "promptText");
104 ExpectDictStringValue("alternate_text", *two_factor_value, "alternateText");
105 ExpectDictIntegerValue(10, *two_factor_value, "fieldLength");
106 }
107
108 TEST_F(GoogleServiceAuthErrorTest, ClientOAuthError) {
109 // Test that a malformed/incomplete ClientOAuth response generates
110 // a connection problem error.
111 GoogleServiceAuthError error1(
112 GoogleServiceAuthError::FromClientOAuthError("{}"));
113 EXPECT_EQ(GoogleServiceAuthError::CONNECTION_FAILED, error1.state());
114
115 // Test that a well formed ClientOAuth response generates an invalid
116 // credentials error with the given error message.
117 GoogleServiceAuthError error2(
118 GoogleServiceAuthError::FromClientOAuthError(
119 "{\"cause\":\"foo\",\"explanation\":\"error_message\"}"));
120 EXPECT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, error2.state());
121 EXPECT_EQ("error_message", error2.error_message());
122 }
123
124 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/google_service_auth_error.cc ('k') | chrome/common/net/gaia/mock_url_fetcher_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698