OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche
r.h" | 9 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche
r.h" |
10 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" | 10 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" |
11 #include "net/url_request/test_url_fetcher_factory.h" | 11 #include "net/url_request/test_url_fetcher_factory.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 static const char kGoodData[] = "{ \"id\" : \"My-channel-id\" }"; | 15 static const char kGoodData[] = "{ \"id\" : \"My-channel-id\" }"; |
16 static const char kBadJsonData[] = "I am not a JSON string"; | 16 static const char kBadJsonData[] = "I am not a JSON string"; |
17 static const char kDictionaryMissingIdData[] = "{ \"foo\" : \"bar\" }"; | 17 static const char kDictionaryMissingIdData[] = "{ \"foo\" : \"bar\" }"; |
18 static const char kNonDictionaryJsonData[] = "{ 0.5 }"; | 18 static const char kNonDictionaryJsonData[] = "{ 0.5 }"; |
19 | 19 |
20 // Delegate class for catching notifications from the ObfuscatedGaiaIdFetcher. | 20 // Delegate class for catching notifications from the ObfuscatedGaiaIdFetcher. |
21 class TestDelegate : public extensions::ObfuscatedGaiaIdFetcher::Delegate { | 21 class TestDelegate : public extensions::ObfuscatedGaiaIdFetcher::Delegate { |
22 public: | 22 public: |
23 virtual void OnObfuscatedGaiaIdFetchSuccess( | 23 virtual void OnObfuscatedGaiaIdFetchSuccess( |
24 const std::string& obfuscated_id) OVERRIDE { | 24 const std::string& obfuscated_id) override { |
25 succeeded_ = true; | 25 succeeded_ = true; |
26 } | 26 } |
27 virtual void OnObfuscatedGaiaIdFetchFailure( | 27 virtual void OnObfuscatedGaiaIdFetchFailure( |
28 const GoogleServiceAuthError& error) OVERRIDE { | 28 const GoogleServiceAuthError& error) override { |
29 failed_ = true; | 29 failed_ = true; |
30 } | 30 } |
31 TestDelegate() : succeeded_(false), failed_(false) {} | 31 TestDelegate() : succeeded_(false), failed_(false) {} |
32 virtual ~TestDelegate() {} | 32 virtual ~TestDelegate() {} |
33 bool succeeded() const { return succeeded_; } | 33 bool succeeded() const { return succeeded_; } |
34 bool failed() const { return failed_; } | 34 bool failed() const { return failed_; } |
35 | 35 |
36 private: | 36 private: |
37 bool succeeded_; | 37 bool succeeded_; |
38 bool failed_; | 38 bool failed_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 // Test with bad data, ensure it fails. | 99 // Test with bad data, ensure it fails. |
100 fetcher.ProcessApiCallSuccess(&url_fetcher); | 100 fetcher.ProcessApiCallSuccess(&url_fetcher); |
101 EXPECT_TRUE(delegate.failed()); | 101 EXPECT_TRUE(delegate.failed()); |
102 | 102 |
103 // TODO(petewil): add case for when the base class fails and calls | 103 // TODO(petewil): add case for when the base class fails and calls |
104 // ProcessApiCallFailure | 104 // ProcessApiCallFailure |
105 } | 105 } |
106 | 106 |
107 } // namespace extensions | 107 } // namespace extensions |
OLD | NEW |