Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2195)

Unified Diff: chrome/browser/local_discovery/gcd_registration_ticket_request_unittest.cc

Issue 307353008: GCD registration ticket creation flow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/local_discovery/gcd_registration_ticket_request.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « chrome/browser/local_discovery/gcd_registration_ticket_request.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698