Index: chrome/browser/local_discovery/gcd_registration_ticket_request_unittest.cc |
diff --git a/chrome/browser/local_discovery/gcd_registration_ticket_request_unittest.cc b/chrome/browser/local_discovery/gcd_registration_ticket_request_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4259a839639e8064ea9aad7bb678d913854fa872 |
--- /dev/null |
+++ b/chrome/browser/local_discovery/gcd_registration_ticket_request_unittest.cc |
@@ -0,0 +1,67 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/local_discovery/gcd_registration_ticket_request.h" |
+ |
+#include "base/json/json_reader.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using testing::StrictMock; |
+ |
+namespace local_discovery { |
+ |
+namespace { |
+ |
+const char kSampleResponse[] = |
+ "{" |
+ "\"kind\": \"clouddevices#registrationTicket\"," |
+ "\"id\": \"SampleTicketID\"" |
+ "}"; |
+ |
+const char kErrorResponse[] = |
+ "{" |
+ "\"kind\": \"clouddevices#error\"" |
+ "}"; |
+ |
+TEST(GCDRegistrationTicketRequestTest, Params) { |
+ GCDRegistrationTicketRequest::ResponseCallback null_callback; |
+ GCDRegistrationTicketRequest request(null_callback); |
+ |
+ EXPECT_EQ( |
+ GURL("https://www.googleapis.com/clouddevices/v1/registrationTickets"), |
+ request.GetURL()); |
+ EXPECT_EQ("https://www.googleapis.com/auth/clouddevices", |
+ request.GetOAuthScope()); |
+ EXPECT_EQ(net::URLFetcher::POST, request.GetRequestType()); |
+ EXPECT_TRUE(request.GetExtraRequestHeaders().empty()); |
+} |
+ |
+class MockDelegate { |
+ public: |
+ MOCK_METHOD1(Callback, void(const std::string& ticket_id)); |
+}; |
+ |
+TEST(GCDRegistrationTicketRequestTest, Parsing) { |
+ StrictMock<MockDelegate> delegate; |
+ GCDRegistrationTicketRequest request( |
+ base::Bind(&MockDelegate::Callback, base::Unretained(&delegate))); |
+ |
+ EXPECT_CALL(delegate, Callback("SampleTicketID")); |
+ |
+ scoped_ptr<base::Value> value(base::JSONReader::Read(kSampleResponse)); |
+ const base::DictionaryValue* dictionary = NULL; |
+ ASSERT_TRUE(value->GetAsDictionary(&dictionary)); |
+ request.OnGCDAPIFlowComplete(*dictionary); |
+ |
+ EXPECT_CALL(delegate, Callback("")); |
+ |
+ value.reset(base::JSONReader::Read(kErrorResponse)); |
+ ASSERT_TRUE(value->GetAsDictionary(&dictionary)); |
+ request.OnGCDAPIFlowComplete(*dictionary); |
+} |
+ |
+} // namespace |
+ |
+} // namespace local_discovery |