1 // Copyright 2014 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.
5 #include "chrome/browser/local_discovery/gcd_registration_ticket_request.h"
7 #include "base/json/json_reader.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using testing::StrictMock
;
13 namespace local_discovery
{
17 const char kSampleResponse
[] =
19 "\"kind\": \"clouddevices#registrationTicket\","
20 "\"id\": \"SampleTicketID\","
21 "\"deviceId\": \"SampleDeviceID\""
24 const char kErrorResponse
[] =
26 "\"kind\": \"clouddevices#error\""
29 TEST(GCDRegistrationTicketRequestTest
, Params
) {
30 GCDRegistrationTicketRequest::ResponseCallback null_callback
;
31 GCDRegistrationTicketRequest
request(null_callback
);
34 GURL("https://www.googleapis.com/clouddevices/v1/registrationTickets"),
36 EXPECT_EQ("https://www.googleapis.com/auth/clouddevices",
37 request
.GetOAuthScope());
38 EXPECT_EQ(net::URLFetcher::POST
, request
.GetRequestType());
39 EXPECT_TRUE(request
.GetExtraRequestHeaders().empty());
44 MOCK_METHOD2(Callback
,
45 void(const std::string
& ticket_id
,
46 const std::string
& device_id
));
49 TEST(GCDRegistrationTicketRequestTest
, Parsing
) {
50 StrictMock
<MockDelegate
> delegate
;
51 GCDRegistrationTicketRequest
request(
52 base::Bind(&MockDelegate::Callback
, base::Unretained(&delegate
)));
54 EXPECT_CALL(delegate
, Callback("SampleTicketID", "SampleDeviceID"));
56 scoped_ptr
<base::Value
> value
= base::JSONReader::Read(kSampleResponse
);
57 const base::DictionaryValue
* dictionary
= NULL
;
58 ASSERT_TRUE(value
->GetAsDictionary(&dictionary
));
59 request
.OnGCDAPIFlowComplete(*dictionary
);
61 EXPECT_CALL(delegate
, Callback("", ""));
63 value
.reset(base::JSONReader::DeprecatedRead(kErrorResponse
));
64 ASSERT_TRUE(value
->GetAsDictionary(&dictionary
));
65 request
.OnGCDAPIFlowComplete(*dictionary
);
70 } // namespace local_discovery