Commit d2522626 authored by fhorschig's avatar fhorschig Committed by Commit bot

Use improved VariationParamsManager to hide details.

Resolved a TODO: The testing::variations::VariationParamsManager
replaces a mock.

In order to enable Feature-associated params, the tested RequestBuilder
needed to be mocked. Since CL 645447, Feature-association works now and
exposing implementation details and mocking is now unnecessary.

BUG=634892

Review-Url: https://codereview.chromium.org/2552813005
Cr-Commit-Position: refs/heads/master@{#438122}
parent b48231c1
...@@ -145,6 +145,16 @@ int Get5xxRetryCount(bool interactive_request) { ...@@ -145,6 +145,16 @@ int Get5xxRetryCount(bool interactive_request) {
kBackground5xxRetriesName, 0)); kBackground5xxRetriesName, 0));
} }
bool IsSendingTopLanguagesEnabled() {
return IsBooleanParameterEnabled(kSendTopLanguagesName,
/*default_value=*/false);
}
bool IsSendingUserClassEnabled() {
return IsBooleanParameterEnabled(kSendUserClassName,
/*default_value=*/false);
}
bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
if (endpoint == kChromeReaderServer) { if (endpoint == kChromeReaderServer) {
return false; return false;
...@@ -674,16 +684,6 @@ NTPSnippetsFetcher::RequestBuilder::SetUserClassifier( ...@@ -674,16 +684,6 @@ NTPSnippetsFetcher::RequestBuilder::SetUserClassifier(
return *this; return *this;
} }
bool NTPSnippetsFetcher::RequestBuilder::IsSendingTopLanguagesEnabled() const {
return IsBooleanParameterEnabled(kSendTopLanguagesName,
/*default_value=*/false);
}
bool NTPSnippetsFetcher::RequestBuilder::IsSendingUserClassEnabled() const {
return IsBooleanParameterEnabled(kSendUserClassName,
/*default_value=*/false);
}
std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const { std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const {
net::HttpRequestHeaders headers; net::HttpRequestHeaders headers;
headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); headers.SetHeader("Content-Type", "application/json; charset=UTF-8");
......
...@@ -173,17 +173,21 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, ...@@ -173,17 +173,21 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
} }
private: private:
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestAuthenticated); FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestUnauthenticated); BuildRequestAuthenticated);
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestExcludedIds); FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestNoUserClass); BuildRequestUnauthenticated);
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
BuildRequestExcludedIds);
FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
BuildRequestNoUserClass);
FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
BuildRequestWithTwoLanguages); BuildRequestWithTwoLanguages);
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
BuildRequestWithUILanguageOnly); BuildRequestWithUILanguageOnly);
FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest,
BuildRequestWithOtherLanguageOnly); BuildRequestWithOtherLanguageOnly);
friend class NTPSnippetsFetcherTest; friend class ChromeReaderSnippetsFetcherTest;
enum FetchAPI { enum FetchAPI {
CHROME_READER_API, CHROME_READER_API,
...@@ -235,12 +239,6 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, ...@@ -235,12 +239,6 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
return *this; return *this;
} }
protected:
// TODO(fhorschig): As soon as crbug.com/crbug.com/645447 is resolved,
// make these an implementation detail in the body and remove the mock.
virtual bool IsSendingTopLanguagesEnabled() const;
virtual bool IsSendingUserClassEnabled() const;
private: private:
std::string BuildHeaders() const; std::string BuildHeaders() const;
std::string BuildBody() const; std::string BuildBody() const;
......
...@@ -276,30 +276,17 @@ void ParseJsonDelayed( ...@@ -276,30 +276,17 @@ void ParseJsonDelayed(
} // namespace } // namespace
class NTPSnippetsFetcherTest : public testing::Test { class NTPSnippetsFetcherTestBase : public testing::Test {
public: public:
// TODO(fhorschig): As soon as crbug.com/645447 is resolved, use explicit NTPSnippetsFetcherTestBase(const GURL& gurl)
// variations::testing::VariationParamsManager to configure these values. : default_variation_params_(
class RequestBuilderWithMockedFlagsForTesting {{"send_top_languages", "true"}, {"send_user_class", "true"}}),
: public NTPSnippetsFetcher::RequestBuilder { params_manager_(
public:
RequestBuilderWithMockedFlagsForTesting() : RequestBuilder() {}
private:
bool IsSendingUserClassEnabled() const override { return true; }
bool IsSendingTopLanguagesEnabled() const override { return true; }
};
NTPSnippetsFetcherTest()
: NTPSnippetsFetcherTest(GURL(kTestChromeReaderUrl),
std::map<std::string, std::string>()) {}
NTPSnippetsFetcherTest(const GURL& gurl,
const std::map<std::string, std::string>& params)
: params_manager_(
base::MakeUnique<variations::testing::VariationParamsManager>( base::MakeUnique<variations::testing::VariationParamsManager>(
ntp_snippets::kStudyName, ntp_snippets::kStudyName,
params)), default_variation_params_,
std::set<std::string>{
ntp_snippets::kArticleSuggestionsFeature.name})),
mock_task_runner_(new base::TestMockTimeTaskRunner()), mock_task_runner_(new base::TestMockTimeTaskRunner()),
mock_task_runner_handle_(mock_task_runner_), mock_task_runner_handle_(mock_task_runner_),
signin_client_(base::MakeUnique<TestSigninClient>(nullptr)), signin_client_(base::MakeUnique<TestSigninClient>(nullptr)),
...@@ -361,14 +348,22 @@ class NTPSnippetsFetcherTest : public testing::Test { ...@@ -361,14 +348,22 @@ class NTPSnippetsFetcherTest : public testing::Test {
/*default_factory=*/&failing_url_fetcher_factory_)); /*default_factory=*/&failing_url_fetcher_factory_));
} }
void SetFetchingPersonalizationVariation( void SetDefaultVariationParam(std::string param_name, std::string value) {
const std::string& personalization_string) { default_variation_params_[param_name] = value;
SetVariationParam(param_name, value);
}
void SetVariationParam(std::string param_name, std::string value) {
params_manager_.reset(); params_manager_.reset();
std::map<std::string, std::string> params = {
{"fetching_personalization", personalization_string}}; std::map<std::string, std::string> params = default_variation_params_;
params[param_name] = value;
params_manager_ = params_manager_ =
base::MakeUnique<variations::testing::VariationParamsManager>( base::MakeUnique<variations::testing::VariationParamsManager>(
ntp_snippets::kStudyName, params); ntp_snippets::kStudyName, params,
std::set<std::string>{
ntp_snippets::kArticleSuggestionsFeature.name});
} }
void SetVariationParametersForFeatures( void SetVariationParametersForFeatures(
...@@ -404,7 +399,8 @@ class NTPSnippetsFetcherTest : public testing::Test { ...@@ -404,7 +399,8 @@ class NTPSnippetsFetcherTest : public testing::Test {
TestingPrefServiceSimple* pref_service() const { return pref_service_.get(); } TestingPrefServiceSimple* pref_service() const { return pref_service_.get(); }
private: private:
// TODO(fhorschig): Make it a simple member as soon as it resets properly. std::map<std::string, std::string> default_variation_params_;
// TODO(fhorschig): Make it a simple member when crbug.com/672010 is resolved.
std::unique_ptr<variations::testing::VariationParamsManager> params_manager_; std::unique_ptr<variations::testing::VariationParamsManager> params_manager_;
scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_;
base::ThreadTaskRunnerHandle mock_task_runner_handle_; base::ThreadTaskRunnerHandle mock_task_runner_handle_;
...@@ -423,18 +419,27 @@ class NTPSnippetsFetcherTest : public testing::Test { ...@@ -423,18 +419,27 @@ class NTPSnippetsFetcherTest : public testing::Test {
const GURL test_url_; const GURL test_url_;
base::HistogramTester histogram_tester_; base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTestBase);
};
class ChromeReaderSnippetsFetcherTest : public NTPSnippetsFetcherTestBase {
public:
ChromeReaderSnippetsFetcherTest()
: NTPSnippetsFetcherTestBase(GURL(kTestChromeReaderUrl)) {}
}; };
class NTPSnippetsContentSuggestionsFetcherTest : public NTPSnippetsFetcherTest { class NTPSnippetsContentSuggestionsFetcherTest
: public NTPSnippetsFetcherTestBase {
public: public:
NTPSnippetsContentSuggestionsFetcherTest() NTPSnippetsContentSuggestionsFetcherTest()
: NTPSnippetsFetcherTest( : NTPSnippetsFetcherTestBase(GURL(kTestChromeContentSuggestionsUrl)) {
GURL(kTestChromeContentSuggestionsUrl), SetDefaultVariationParam("content_suggestions_backend",
{{"content_suggestions_backend", kContentSuggestionsServer}}) {} kContentSuggestionsServer);
ResetSnippetsFetcher();
}
}; };
TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestAuthenticated) {
NTPSnippetsFetcher::RequestBuilder builder; NTPSnippetsFetcher::RequestBuilder builder;
NTPSnippetsFetcher::Params params; NTPSnippetsFetcher::Params params;
params.hosts = {"chromium.org"}; params.hosts = {"chromium.org"};
...@@ -503,7 +508,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { ...@@ -503,7 +508,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestUnauthenticated) {
NTPSnippetsFetcher::RequestBuilder builder; NTPSnippetsFetcher::RequestBuilder builder;
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
params.count_to_fetch = 10; params.count_to_fetch = 10;
...@@ -557,7 +562,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { ...@@ -557,7 +562,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestExcludedIds) {
NTPSnippetsFetcher::RequestBuilder builder; NTPSnippetsFetcher::RequestBuilder builder;
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
params.interactive_request = false; params.interactive_request = false;
...@@ -602,7 +607,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) { ...@@ -602,7 +607,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, BuildRequestNoUserClass) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestNoUserClass) {
NTPSnippetsFetcher::RequestBuilder builder; NTPSnippetsFetcher::RequestBuilder builder;
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
params.interactive_request = false; params.interactive_request = false;
...@@ -619,8 +624,8 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestNoUserClass) { ...@@ -619,8 +624,8 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestNoUserClass) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestWithTwoLanguages) {
RequestBuilderWithMockedFlagsForTesting builder; NTPSnippetsFetcher::RequestBuilder builder;
std::unique_ptr<translate::LanguageModel> language_model = std::unique_ptr<translate::LanguageModel> language_model =
MakeLanguageModel({"de", "en"}); MakeLanguageModel({"de", "en"});
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
...@@ -650,8 +655,8 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) { ...@@ -650,8 +655,8 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestWithTwoLanguages) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) { TEST_F(ChromeReaderSnippetsFetcherTest, BuildRequestWithUILanguageOnly) {
RequestBuilderWithMockedFlagsForTesting builder; NTPSnippetsFetcher::RequestBuilder builder;
std::unique_ptr<translate::LanguageModel> language_model = std::unique_ptr<translate::LanguageModel> language_model =
MakeLanguageModel({"en"}); MakeLanguageModel({"en"});
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
...@@ -675,7 +680,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) { ...@@ -675,7 +680,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestWithUILanguageOnly) {
"}")); "}"));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldNotFetchOnCreation) {
// The lack of registered baked in responses would cause any fetch to fail. // The lack of registered baked in responses would cause any fetch to fail.
FastForwardUntilNoTasksRemain(); FastForwardUntilNoTasksRemain();
EXPECT_THAT(histogram_tester().GetAllSamples( EXPECT_THAT(histogram_tester().GetAllSamples(
...@@ -686,7 +691,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { ...@@ -686,7 +691,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty()); EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty());
} }
TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfully) {
const std::string kJsonStr = const std::string kJsonStr =
"{\"recos\": [{" "{\"recos\": [{"
" \"contentInfo\": {" " \"contentInfo\": {"
...@@ -959,28 +964,28 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) { ...@@ -959,28 +964,28 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) {
EXPECT_THAT(category.snippets[0]->url().spec(), Eq("http://localhost/foo2")); EXPECT_THAT(category.snippets[0]->url().spec(), Eq("http://localhost/foo2"));
} }
TEST_F(NTPSnippetsFetcherTest, PersonalizesDependingOnVariations) { TEST_F(ChromeReaderSnippetsFetcherTest, PersonalizesDependingOnVariations) {
// Default setting should be both personalization options. // Default setting should be both personalization options.
EXPECT_THAT(snippets_fetcher().personalization(), EXPECT_THAT(snippets_fetcher().personalization(),
Eq(NTPSnippetsFetcher::Personalization::kBoth)); Eq(NTPSnippetsFetcher::Personalization::kBoth));
SetFetchingPersonalizationVariation("personal"); SetVariationParam("fetching_personalization", "personal");
ResetSnippetsFetcher(); ResetSnippetsFetcher();
EXPECT_THAT(snippets_fetcher().personalization(), EXPECT_THAT(snippets_fetcher().personalization(),
Eq(NTPSnippetsFetcher::Personalization::kPersonal)); Eq(NTPSnippetsFetcher::Personalization::kPersonal));
SetFetchingPersonalizationVariation("non_personal"); SetVariationParam("fetching_personalization", "non_personal");
ResetSnippetsFetcher(); ResetSnippetsFetcher();
EXPECT_THAT(snippets_fetcher().personalization(), EXPECT_THAT(snippets_fetcher().personalization(),
Eq(NTPSnippetsFetcher::Personalization::kNonPersonal)); Eq(NTPSnippetsFetcher::Personalization::kNonPersonal));
SetFetchingPersonalizationVariation("both"); SetVariationParam("fetching_personalization", "both");
ResetSnippetsFetcher(); ResetSnippetsFetcher();
EXPECT_THAT(snippets_fetcher().personalization(), EXPECT_THAT(snippets_fetcher().personalization(),
Eq(NTPSnippetsFetcher::Personalization::kBoth)); Eq(NTPSnippetsFetcher::Personalization::kBoth));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
const std::string kJsonStr = "{\"recos\": []}"; const std::string kJsonStr = "{\"recos\": []}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
...@@ -999,7 +1004,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { ...@@ -999,7 +1004,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldRestrictToHosts) {
DelegateCallingTestURLFetcherFactory fetcher_factory; DelegateCallingTestURLFetcherFactory fetcher_factory;
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
params.hosts = {"www.somehost1.com", "www.somehost2.com"}; params.hosts = {"www.somehost1.com", "www.somehost2.com"};
...@@ -1033,7 +1038,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) { ...@@ -1033,7 +1038,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) {
EXPECT_THAT(content_selector_value, Eq("www.somehost2.com")); EXPECT_THAT(content_selector_value, Eq("www.somehost2.com"));
} }
TEST_F(NTPSnippetsFetcherTest, RetryOnInteractiveRequests) { TEST_F(ChromeReaderSnippetsFetcherTest, RetryOnInteractiveRequests) {
DelegateCallingTestURLFetcherFactory fetcher_factory; DelegateCallingTestURLFetcherFactory fetcher_factory;
NTPSnippetsFetcher::Params params = test_params(); NTPSnippetsFetcher::Params params = test_params();
params.interactive_request = true; params.interactive_request = true;
...@@ -1046,7 +1051,8 @@ TEST_F(NTPSnippetsFetcherTest, RetryOnInteractiveRequests) { ...@@ -1046,7 +1051,8 @@ TEST_F(NTPSnippetsFetcherTest, RetryOnInteractiveRequests) {
EXPECT_THAT(fetcher->GetMaxRetriesOn5xx(), Eq(2)); EXPECT_THAT(fetcher->GetMaxRetriesOn5xx(), Eq(2));
} }
TEST_F(NTPSnippetsFetcherTest, RetriesConfigurableOnNonInteractiveRequests) { TEST_F(ChromeReaderSnippetsFetcherTest,
RetriesConfigurableOnNonInteractiveRequests) {
struct ExpectationForVariationParam { struct ExpectationForVariationParam {
std::string param_value; std::string param_value;
int expected_value; int expected_value;
...@@ -1077,7 +1083,7 @@ TEST_F(NTPSnippetsFetcherTest, RetriesConfigurableOnNonInteractiveRequests) { ...@@ -1077,7 +1083,7 @@ TEST_F(NTPSnippetsFetcherTest, RetriesConfigurableOnNonInteractiveRequests) {
} }
} }
TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportUrlStatusError) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND, SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND,
net::URLRequestStatus::FAILED); net::URLRequestStatus::FAILED);
EXPECT_CALL(mock_callback(), EXPECT_CALL(mock_callback(),
...@@ -1100,7 +1106,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) { ...@@ -1100,7 +1106,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
Not(IsEmpty())); Not(IsEmpty()));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportHttpError) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND, SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
EXPECT_CALL(mock_callback(), Run(NTPSnippetsFetcher::FetchResult::HTTP_ERROR, EXPECT_CALL(mock_callback(), Run(NTPSnippetsFetcher::FetchResult::HTTP_ERROR,
...@@ -1120,7 +1126,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) { ...@@ -1120,7 +1126,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
Not(IsEmpty())); Not(IsEmpty()));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonError) {
const std::string kInvalidJsonStr = "{ \"recos\": []"; const std::string kInvalidJsonStr = "{ \"recos\": []";
SetFakeResponse(/*response_data=*/kInvalidJsonStr, net::HTTP_OK, SetFakeResponse(/*response_data=*/kInvalidJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
...@@ -1145,7 +1151,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) { ...@@ -1145,7 +1151,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) {
/*count=*/1))); /*count=*/1)));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_OK, SetFakeResponse(/*response_data=*/std::string(), net::HTTP_OK,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
EXPECT_CALL(mock_callback(), EXPECT_CALL(mock_callback(),
...@@ -1164,7 +1170,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { ...@@ -1164,7 +1170,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) {
ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
} }
TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldReportInvalidListError) {
const std::string kJsonStr = const std::string kJsonStr =
"{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}"; "{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
...@@ -1190,7 +1196,8 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) { ...@@ -1190,7 +1196,8 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) {
// This test actually verifies that the test setup itself is sane, to prevent // This test actually verifies that the test setup itself is sane, to prevent
// hard-to-reproduce test failures. // hard-to-reproduce test failures.
TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) { TEST_F(ChromeReaderSnippetsFetcherTest,
ShouldReportHttpErrorForMissingBakedResponse) {
InitFakeURLFetcherFactory(); InitFakeURLFetcherFactory();
EXPECT_CALL(mock_callback(), EXPECT_CALL(mock_callback(),
Run(NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR, Run(NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR,
...@@ -1201,7 +1208,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) { ...@@ -1201,7 +1208,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) {
FastForwardUntilNoTasksRemain(); FastForwardUntilNoTasksRemain();
} }
TEST_F(NTPSnippetsFetcherTest, ShouldProcessConcurrentFetches) { TEST_F(ChromeReaderSnippetsFetcherTest, ShouldProcessConcurrentFetches) {
const std::string kJsonStr = "{ \"recos\": [] }"; const std::string kJsonStr = "{ \"recos\": [] }";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment