BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / local_discovery / gcd_registration_ticket_request_unittest.cc
blobff708f41964db5ea8d05a0065eeff824f8049213
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 {
15 namespace {
17 const char kSampleResponse[] =
18 "{"
19 "\"kind\": \"clouddevices#registrationTicket\","
20 "\"id\": \"SampleTicketID\","
21 "\"deviceId\": \"SampleDeviceID\""
22 "}";
24 const char kErrorResponse[] =
25 "{"
26 "\"kind\": \"clouddevices#error\""
27 "}";
29 TEST(GCDRegistrationTicketRequestTest, Params) {
30 GCDRegistrationTicketRequest::ResponseCallback null_callback;
31 GCDRegistrationTicketRequest request(null_callback);
33 EXPECT_EQ(
34 GURL("https://www.googleapis.com/clouddevices/v1/registrationTickets"),
35 request.GetURL());
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());
42 class MockDelegate {
43 public:
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 = base::JSONReader::Read(kErrorResponse);
64 ASSERT_TRUE(value->GetAsDictionary(&dictionary));
65 request.OnGCDAPIFlowComplete(*dictionary);
68 } // namespace
70 } // namespace local_discovery