Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / local_discovery / cloud_device_list_unittest.cc
blob38d116d5a08f926cc71117827cdff5edbd33f577
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/cloud_device_list.h"
7 #include <set>
9 #include "base/json/json_reader.h"
10 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using testing::Mock;
15 using testing::SaveArg;
16 using testing::StrictMock;
17 using testing::_;
19 namespace local_discovery {
21 namespace {
23 const char kSampleSuccessResponseOAuth[] =
24 "{"
25 "\"kind\": \"clouddevices#devicesListResponse\","
26 "\"devices\": [{"
27 " \"kind\": \"clouddevices#device\","
28 " \"id\": \"someID\","
29 " \"deviceKind\": \"someType\","
30 " \"creationTimeMs\": \"123\","
31 " \"systemName\": \"someDisplayName\","
32 " \"owner\": \"user@domain.com\","
33 " \"description\": \"someDescription\","
34 " \"state\": {"
35 " \"base\": {"
36 " \"connectionStatus\": \"offline\""
37 " }"
38 " },"
39 " \"channel\": {"
40 " \"supportedType\": \"xmpp\""
41 " },"
42 " \"personalizedInfo\": {"
43 " \"maxRole\": \"owner\""
44 " }}]}";
46 class MockDelegate : public CloudDeviceListDelegate {
47 public:
48 MOCK_METHOD1(OnDeviceListReady, void(const DeviceList&));
49 MOCK_METHOD0(OnDeviceListUnavailable, void());
52 TEST(CloudDeviceListTest, Params) {
53 CloudDeviceList device_list(NULL);
54 EXPECT_EQ(GURL("https://www.googleapis.com/clouddevices/v1/devices"),
55 device_list.GetURL());
56 EXPECT_EQ("https://www.googleapis.com/auth/clouddevices",
57 device_list.GetOAuthScope());
58 EXPECT_EQ(net::URLFetcher::GET, device_list.GetRequestType());
59 EXPECT_TRUE(device_list.GetExtraRequestHeaders().empty());
62 TEST(CloudDeviceListTest, Parsing) {
63 StrictMock<MockDelegate> delegate;
64 CloudDeviceList device_list(&delegate);
65 CloudDeviceListDelegate::DeviceList devices;
66 EXPECT_CALL(delegate, OnDeviceListReady(_)).WillOnce(SaveArg<0>(&devices));
68 scoped_ptr<base::Value> value(
69 base::JSONReader::Read(kSampleSuccessResponseOAuth));
70 const base::DictionaryValue* dictionary = NULL;
71 ASSERT_TRUE(value->GetAsDictionary(&dictionary));
72 device_list.OnGCDAPIFlowComplete(*dictionary);
74 Mock::VerifyAndClear(&delegate);
76 std::set<std::string> ids_found;
77 std::set<std::string> ids_expected;
78 ids_expected.insert("someID");
80 for (size_t i = 0; i != devices.size(); ++i) {
81 ids_found.insert(devices[i].id);
84 ASSERT_EQ(ids_expected, ids_found);
86 EXPECT_EQ("someID", devices[0].id);
87 EXPECT_EQ("someDisplayName", devices[0].display_name);
88 EXPECT_EQ("someDescription", devices[0].description);
89 EXPECT_EQ("someType", devices[0].type);
92 } // namespace
94 } // namespace local_discovery