| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/local_discovery/privet_confirm_api_flow.h" | |
| 6 | |
| 7 #include <set> | |
| 8 | |
| 9 #include "base/json/json_reader.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 using testing::StrictMock; | |
| 14 using testing::_; | |
| 15 | |
| 16 namespace local_discovery { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char kSampleConfirmResponse[] = "{" | |
| 21 " \"success\": true" | |
| 22 "}"; | |
| 23 | |
| 24 const char kFailedConfirmResponse[] = "{" | |
| 25 " \"success\": false" | |
| 26 "}"; | |
| 27 | |
| 28 TEST(PrivetConfirmApiFlowTest, Params) { | |
| 29 PrivetConfirmApiCallFlow confirmation( | |
| 30 "123", PrivetConfirmApiCallFlow::ResponseCallback()); | |
| 31 EXPECT_EQ(GURL("https://www.google.com/cloudprint/confirm?token=123"), | |
| 32 confirmation.GetURL()); | |
| 33 EXPECT_EQ("https://www.googleapis.com/auth/cloudprint", | |
| 34 confirmation.GetOAuthScope()); | |
| 35 EXPECT_EQ(net::URLFetcher::GET, confirmation.GetRequestType()); | |
| 36 EXPECT_FALSE(confirmation.GetExtraRequestHeaders().empty()); | |
| 37 } | |
| 38 | |
| 39 class MockDelegate { | |
| 40 public: | |
| 41 MOCK_METHOD1(Callback, void(GCDApiFlow::Status)); | |
| 42 }; | |
| 43 | |
| 44 TEST(PrivetConfirmApiFlowTest, Parsing) { | |
| 45 StrictMock<MockDelegate> delegate; | |
| 46 PrivetConfirmApiCallFlow confirmation( | |
| 47 "123", base::Bind(&MockDelegate::Callback, base::Unretained(&delegate))); | |
| 48 EXPECT_CALL(delegate, Callback(GCDApiFlow::SUCCESS)).Times(1); | |
| 49 | |
| 50 scoped_ptr<base::Value> value = | |
| 51 base::JSONReader::Read(kSampleConfirmResponse); | |
| 52 const base::DictionaryValue* dictionary = NULL; | |
| 53 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 54 confirmation.OnGCDAPIFlowComplete(*dictionary); | |
| 55 | |
| 56 EXPECT_CALL(delegate, Callback(GCDApiFlow::ERROR_FROM_SERVER)).Times(1); | |
| 57 | |
| 58 value = base::JSONReader::Read(kFailedConfirmResponse); | |
| 59 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 60 confirmation.OnGCDAPIFlowComplete(*dictionary); | |
| 61 } | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 } // namespace local_discovery | |
| OLD | NEW |