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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 1978513002: Getting the personalization info in chrome://snippets-internals correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After code review #2 Created 4 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 unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 "{ \"recos\": [ " + base::JoinString(snippets1, ", ") + "]}"); 404 "{ \"recos\": [ " + base::JoinString(snippets1, ", ") + "]}");
405 ASSERT_THAT(service()->snippets(), SizeIs(snippets1.size())); 405 ASSERT_THAT(service()->snippets(), SizeIs(snippets1.size()));
406 406
407 LoadFromJSONString( 407 LoadFromJSONString(
408 "{ \"recos\": [ " + base::JoinString(snippets2, ", ") + "]}"); 408 "{ \"recos\": [ " + base::JoinString(snippets2, ", ") + "]}");
409 EXPECT_THAT(service()->snippets(), SizeIs(max_snippet_count)); 409 EXPECT_THAT(service()->snippets(), SizeIs(max_snippet_count));
410 } 410 }
411 411
412 TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) { 412 TEST_F(NTPSnippetsServiceTest, LoadInvalidJson) {
413 LoadFromJSONString(GetInvalidJson()); 413 LoadFromJSONString(GetInvalidJson());
414 EXPECT_THAT(service()->last_status(), StartsWith("Received invalid JSON")); 414 EXPECT_THAT(service()->snippets_fetcher()->last_status(),
415 StartsWith("Received invalid JSON"));
415 EXPECT_THAT(service()->snippets(), IsEmpty()); 416 EXPECT_THAT(service()->snippets(), IsEmpty());
416 } 417 }
417 418
418 TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) { 419 TEST_F(NTPSnippetsServiceTest, LoadInvalidJsonWithExistingSnippets) {
419 LoadFromJSONString(GetTestJson()); 420 LoadFromJSONString(GetTestJson());
420 ASSERT_THAT(service()->snippets(), SizeIs(1)); 421 ASSERT_THAT(service()->snippets(), SizeIs(1));
421 ASSERT_EQ("OK", service()->last_status()); 422 ASSERT_EQ("OK", service()->snippets_fetcher()->last_status());
422 423
423 LoadFromJSONString(GetInvalidJson()); 424 LoadFromJSONString(GetInvalidJson());
424 EXPECT_THAT(service()->last_status(), StartsWith("Received invalid JSON")); 425 EXPECT_THAT(service()->snippets_fetcher()->last_status(),
426 StartsWith("Received invalid JSON"));
425 // This should not have changed the existing snippets. 427 // This should not have changed the existing snippets.
426 EXPECT_THAT(service()->snippets(), SizeIs(1)); 428 EXPECT_THAT(service()->snippets(), SizeIs(1));
427 } 429 }
428 430
429 TEST_F(NTPSnippetsServiceTest, LoadIncompleteJson) { 431 TEST_F(NTPSnippetsServiceTest, LoadIncompleteJson) {
430 LoadFromJSONString(GetIncompleteJson()); 432 LoadFromJSONString(GetIncompleteJson());
431 EXPECT_EQ("Invalid / empty list.", service()->last_status()); 433 EXPECT_EQ("Invalid / empty list.",
434 service()->snippets_fetcher()->last_status());
432 EXPECT_THAT(service()->snippets(), IsEmpty()); 435 EXPECT_THAT(service()->snippets(), IsEmpty());
433 } 436 }
434 437
435 TEST_F(NTPSnippetsServiceTest, LoadIncompleteJsonWithExistingSnippets) { 438 TEST_F(NTPSnippetsServiceTest, LoadIncompleteJsonWithExistingSnippets) {
436 LoadFromJSONString(GetTestJson()); 439 LoadFromJSONString(GetTestJson());
437 ASSERT_THAT(service()->snippets(), SizeIs(1)); 440 ASSERT_THAT(service()->snippets(), SizeIs(1));
438 441
439 LoadFromJSONString(GetIncompleteJson()); 442 LoadFromJSONString(GetIncompleteJson());
440 EXPECT_EQ("Invalid / empty list.", service()->last_status()); 443 EXPECT_EQ("Invalid / empty list.",
444 service()->snippets_fetcher()->last_status());
441 // This should not have changed the existing snippets. 445 // This should not have changed the existing snippets.
442 EXPECT_THAT(service()->snippets(), SizeIs(1)); 446 EXPECT_THAT(service()->snippets(), SizeIs(1));
443 } 447 }
444 448
445 TEST_F(NTPSnippetsServiceTest, Discard) { 449 TEST_F(NTPSnippetsServiceTest, Discard) {
446 std::vector<std::string> source_urls, publishers, amp_urls; 450 std::vector<std::string> source_urls, publishers, amp_urls;
447 source_urls.push_back(std::string("http://site.com")); 451 source_urls.push_back(std::string("http://site.com"));
448 publishers.push_back(std::string("Source 1")); 452 publishers.push_back(std::string("Source 1"));
449 amp_urls.push_back(std::string()); 453 amp_urls.push_back(std::string());
450 std::string json_str( 454 std::string json_str(
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 LoadFromJSONString(base::StringPrintf( 843 LoadFromJSONString(base::StringPrintf(
840 kChromeReaderResponseMultipleUrls, url_aol.c_str(), 844 kChromeReaderResponseMultipleUrls, url_aol.c_str(),
841 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(), 845 NTPSnippet::TimeToJsonString(GetDefaultCreationTime()).c_str(),
842 NTPSnippet::TimeToJsonString(base::Time::Now() + 846 NTPSnippet::TimeToJsonString(base::Time::Now() +
843 base::TimeDelta::FromHours(1)) 847 base::TimeDelta::FromHours(1))
844 .c_str())); 848 .c_str()));
845 ASSERT_THAT(service()->snippets(), IsEmpty()); 849 ASSERT_THAT(service()->snippets(), IsEmpty());
846 } 850 }
847 851
848 } // namespace ntp_snippets 852 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698