1a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 2a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch// found in the LICENSE file. 4a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 5a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <set> 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/json/json_reader.h" 10a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "testing/gmock/include/gmock/gmock.h" 11a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "testing/gtest/include/gtest/gtest.h" 12a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)using testing::StrictMock; 14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)using testing::_; 15a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 16a3f7b4e666c476898878fa745f637129375cd889Ben Murdochnamespace local_discovery { 17a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 18a3f7b4e666c476898878fa745f637129375cd889Ben Murdochnamespace { 19a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 20a3f7b4e666c476898878fa745f637129375cd889Ben Murdochconst char kSampleConfirmResponse[] = "{" 21a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch " \"success\": true" 22a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch "}"; 23a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 24a3f7b4e666c476898878fa745f637129375cd889Ben Murdochconst char kFailedConfirmResponse[] = "{" 25a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch " \"success\": false" 26a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch "}"; 27a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST(PrivetConfirmApiFlowTest, Params) { 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PrivetConfirmApiCallFlow confirmation( 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) "123", PrivetConfirmApiCallFlow::ResponseCallback()); 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(GURL("https://www.google.com/cloudprint/confirm?token=123"), 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) confirmation.GetURL()); 33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ("https://www.googleapis.com/auth/cloudprint", 34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) confirmation.GetOAuthScope()); 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(net::URLFetcher::GET, confirmation.GetRequestType()); 36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(confirmation.GetExtraRequestHeaders().empty()); 37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 38a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class MockDelegate { 40a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch public: 41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) MOCK_METHOD1(Callback, void(GCDApiFlow::Status)); 42a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch}; 43a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST(PrivetConfirmApiFlowTest, Parsing) { 45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) StrictMock<MockDelegate> delegate; 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PrivetConfirmApiCallFlow confirmation( 47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) "123", base::Bind(&MockDelegate::Callback, base::Unretained(&delegate))); 48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_CALL(delegate, Callback(GCDApiFlow::SUCCESS)).Times(1); 490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) scoped_ptr<base::Value> value(base::JSONReader::Read(kSampleConfirmResponse)); 51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const base::DictionaryValue* dictionary = NULL; 52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(value->GetAsDictionary(&dictionary)); 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) confirmation.OnGCDAPIFlowComplete(*dictionary); 540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_CALL(delegate, Callback(GCDApiFlow::ERROR_FROM_SERVER)).Times(1); 56a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) value.reset(base::JSONReader::Read(kFailedConfirmResponse)); 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(value->GetAsDictionary(&dictionary)); 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) confirmation.OnGCDAPIFlowComplete(*dictionary); 60a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch} 61a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 62a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch} // namespace 63a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 64a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch} // namespace local_discovery 65