Allow the minimum time between banner trigger visits to be varied via field trials.
[chromium-blink-merge.git] / chrome / browser / local_discovery / cloud_print_printer_list_unittest.cc
blobc57c5a677c589602daddc3458be3e618fdb405fc
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.
5 #include "chrome/browser/local_discovery/cloud_print_printer_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 " \"success\": true,"
25 " \"printers\": ["
26 " {\"id\" : \"someID\","
27 " \"displayName\": \"someDisplayName\","
28 " \"description\": \"someDescription\"}"
29 " ]"
30 "}";
32 class MockDelegate : public CloudDeviceListDelegate {
33 public:
34 MOCK_METHOD1(OnDeviceListReady, void(const DeviceList&));
35 MOCK_METHOD0(OnDeviceListUnavailable, void());
38 TEST(CloudPrintPrinterListTest, Params) {
39 CloudPrintPrinterList device_list(NULL);
40 EXPECT_EQ(GURL("https://www.google.com/cloudprint/search"),
41 device_list.GetURL());
42 EXPECT_EQ("https://www.googleapis.com/auth/cloudprint",
43 device_list.GetOAuthScope());
44 EXPECT_EQ(net::URLFetcher::GET, device_list.GetRequestType());
45 EXPECT_FALSE(device_list.GetExtraRequestHeaders().empty());
48 TEST(CloudPrintPrinterListTest, Parsing) {
49 StrictMock<MockDelegate> delegate;
50 CloudPrintPrinterList device_list(&delegate);
51 CloudDeviceListDelegate::DeviceList devices;
52 EXPECT_CALL(delegate, OnDeviceListReady(_)).WillOnce(SaveArg<0>(&devices));
54 scoped_ptr<base::Value> value(
55 base::JSONReader::DeprecatedRead(kSampleSuccessResponseOAuth));
56 const base::DictionaryValue* dictionary = NULL;
57 ASSERT_TRUE(value->GetAsDictionary(&dictionary));
58 device_list.OnGCDAPIFlowComplete(*dictionary);
60 Mock::VerifyAndClear(&delegate);
62 std::set<std::string> ids_found;
63 std::set<std::string> ids_expected;
64 ids_expected.insert("someID");
66 for (size_t i = 0; i != devices.size(); ++i) {
67 ids_found.insert(devices[i].id);
70 ASSERT_EQ(ids_expected, ids_found);
72 EXPECT_EQ("someID", devices[0].id);
73 EXPECT_EQ("someDisplayName", devices[0].display_name);
74 EXPECT_EQ("someDescription", devices[0].description);
75 EXPECT_EQ("printer", devices[0].type);
78 } // namespace
80 } // namespace local_discovery