| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/json/json_reader.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using testing::Mock; | |
| 16 using testing::SaveArg; | |
| 17 using testing::StrictMock; | |
| 18 using testing::_; | |
| 19 | |
| 20 namespace local_discovery { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const char kSampleSuccessResponseOAuth[] = "{" | |
| 25 " \"success\": true," | |
| 26 " \"printers\": [" | |
| 27 " {\"id\" : \"someID\"," | |
| 28 " \"displayName\": \"someDisplayName\"," | |
| 29 " \"description\": \"someDescription\"}" | |
| 30 " ]" | |
| 31 "}"; | |
| 32 | |
| 33 class MockDelegate : public CloudPrintPrinterList::Delegate { | |
| 34 public: | |
| 35 MOCK_METHOD1(OnDeviceListReady, | |
| 36 void(const CloudPrintPrinterList::DeviceList&)); | |
| 37 MOCK_METHOD0(OnDeviceListUnavailable, void()); | |
| 38 }; | |
| 39 | |
| 40 TEST(CloudPrintPrinterListTest, Params) { | |
| 41 CloudPrintPrinterList device_list(NULL); | |
| 42 EXPECT_EQ(GURL("https://www.google.com/cloudprint/search"), | |
| 43 device_list.GetURL()); | |
| 44 EXPECT_EQ("https://www.googleapis.com/auth/cloudprint", | |
| 45 device_list.GetOAuthScope()); | |
| 46 EXPECT_EQ(net::URLFetcher::GET, device_list.GetRequestType()); | |
| 47 EXPECT_FALSE(device_list.GetExtraRequestHeaders().empty()); | |
| 48 } | |
| 49 | |
| 50 TEST(CloudPrintPrinterListTest, Parsing) { | |
| 51 StrictMock<MockDelegate> delegate; | |
| 52 CloudPrintPrinterList device_list(&delegate); | |
| 53 CloudPrintPrinterList::DeviceList devices; | |
| 54 EXPECT_CALL(delegate, OnDeviceListReady(_)).WillOnce(SaveArg<0>(&devices)); | |
| 55 | |
| 56 scoped_ptr<base::Value> value = | |
| 57 base::JSONReader::Read(kSampleSuccessResponseOAuth); | |
| 58 const base::DictionaryValue* dictionary = NULL; | |
| 59 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 60 device_list.OnGCDAPIFlowComplete(*dictionary); | |
| 61 | |
| 62 Mock::VerifyAndClear(&delegate); | |
| 63 | |
| 64 std::set<std::string> ids_found; | |
| 65 std::set<std::string> ids_expected; | |
| 66 ids_expected.insert("someID"); | |
| 67 | |
| 68 for (size_t i = 0; i != devices.size(); ++i) { | |
| 69 ids_found.insert(devices[i].id); | |
| 70 } | |
| 71 | |
| 72 ASSERT_EQ(ids_expected, ids_found); | |
| 73 | |
| 74 EXPECT_EQ("someID", devices[0].id); | |
| 75 EXPECT_EQ("someDisplayName", devices[0].display_name); | |
| 76 EXPECT_EQ("someDescription", devices[0].description); | |
| 77 } | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 } // namespace local_discovery | |
| OLD | NEW |