OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 /*count=*/1))); | 376 /*count=*/1))); |
377 } | 377 } |
378 | 378 |
379 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ShouldFetchSuccessfully) { | 379 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ShouldFetchSuccessfully) { |
380 const std::string kJsonStr = | 380 const std::string kJsonStr = |
381 "{\"snippet\" : [{" | 381 "{\"snippet\" : [{" |
382 " \"id\" : [\"http://localhost/foobar\"]," | 382 " \"id\" : [\"http://localhost/foobar\"]," |
383 " \"title\" : \"Foo Barred from Baz\"," | 383 " \"title\" : \"Foo Barred from Baz\"," |
384 " \"summaryText\" : \"...\"," | 384 " \"summaryText\" : \"...\"," |
385 " \"fullPageUrl\" : \"http://localhost/foobar\"," | 385 " \"fullPageUrl\" : \"http://localhost/foobar\"," |
386 " \"publishTime\" : {" | 386 " \"publishTime\" : \"2016-06-30T11:01:37.000Z\"," |
387 " \"seconds\": 1466510682," | 387 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," |
388 " \"nanos\": 552743000 " | |
389 " }," | |
390 " \"expirationTime\" : {" | |
391 " \"seconds\" : 1466597082," | |
392 " \"nanos\" : 552743000 " | |
393 " }," | |
394 " \"publisherName\" : \"Foo News\"," | 388 " \"publisherName\" : \"Foo News\"," |
395 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," | 389 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," |
396 " \"ampUrl\" : \"http://localhost/amp\"," | 390 " \"ampUrl\" : \"http://localhost/amp\"," |
397 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " | 391 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
398 "}]}"; | 392 "}]}"; |
399 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, | 393 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, |
400 net::URLRequestStatus::SUCCESS); | 394 net::URLRequestStatus::SUCCESS); |
401 EXPECT_CALL(mock_callback(), Run(/*snippets=*/PointeeSizeIs(1))).Times(1); | 395 EXPECT_CALL(mock_callback(), Run(/*snippets=*/PointeeSizeIs(1))).Times(1); |
402 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), | 396 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
403 /*count=*/1); | 397 /*count=*/1); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 if (snippets) { | 563 if (snippets) { |
570 // Matchers above aren't any more precise than this, so this is sufficient | 564 // Matchers above aren't any more precise than this, so this is sufficient |
571 // for test-failure diagnostics. | 565 // for test-failure diagnostics. |
572 return os << "list with " << snippets->size() << " elements"; | 566 return os << "list with " << snippets->size() << " elements"; |
573 } else { | 567 } else { |
574 return os << "null"; | 568 return os << "null"; |
575 } | 569 } |
576 } | 570 } |
577 | 571 |
578 } // namespace ntp_snippets | 572 } // namespace ntp_snippets |
OLD | NEW |