src/net/reporting/reporting_header_parser_unittest.cc
// TODO(juliatuttle): Ideally these tests should be expecting that JSON parsing
// (and therefore header parsing) may happen asynchronously, but the entire
// pipeline is also tested by NetworkErrorLoggingEndToEndTest.
Ideally these tests should be expecting that JSON parsing
(and therefore header parsing) may happen asynchronously, but the entire
pipeline is also tested by NetworkErrorLoggingEndToEndTest.
Ideally these tests should be expecting that JSON parsing ( and therefore header parsing ) may happen asynchronously but the entire pipeline is also tested by NetworkErrorLoggingEndToEndTest .
TEST_P(ReportingHeaderParserTest, Invalid) {
  static const struct {
    const char* header_value;
    const char* description;
  } kInvalidHeaderTestCases[] = {
      {"{\"max_age\":1, \"endpoints\": [{}]}", "missing url"},
      {"{\"max_age\":1, \"endpoints\": [{\"url\":0}]}", "non-string url"},
      {"{\"max_age\":1, \"endpoints\": [{\"url\":\"//scheme/relative\"}]}",
       "scheme-relative url"},
      {"{\"max_age\":1, \"endpoints\": [{\"url\":\"relative/path\"}]}",
       "path relative url"},
      {"{\"max_age\":1, \"endpoints\": [{\"url\":\"http://insecure/\"}]}",
       "insecure url"},
      {"{\"endpoints\": [{\"url\":\"https://endpoint/\"}]}", "missing max_age"},
      {"{\"max_age\":\"\", \"endpoints\": [{\"url\":\"https://endpoint/\"}]}",
       "non-integer max_age"},
      {"{\"max_age\":-1, \"endpoints\": [{\"url\":\"https://endpoint/\"}]}",
       "negative max_age"},
      {"{\"max_age\":1, \"group\":0, "
       "\"endpoints\": [{\"url\":\"https://endpoint/\"}]}",
       "non-string group"},
      {"{\"max_age\":1, "
       "\"endpoints\": [{\"url\":\"https://endpoint/\",\"priority\":\"\"}]}",
       "non-integer priority"},
      {"{\"max_age\":1, "
       "\"endpoints\": [{\"url\":\"https://endpoint/\",\"priority\":-1}]}",
       "negative priority"},
      {"{\"max_age\":1, "
       "\"endpoints\": [{\"url\":\"https://endpoint/\",\"weight\":\"\"}]}",
       "non-integer weight"},
      {"{\"max_age\":1, "
       "\"endpoints\": [{\"url\":\"https://endpoint/\",\"weight\":-1}]}",
       "negative weight"},
      {"[{\"max_age\":1, \"endpoints\": [{\"url\":\"https://a/\"}]},"
       "{\"max_age\":1, \"endpoints\": [{\"url\":\"https://b/\"}]}]",
       "wrapped in list"}};
  for (size_t i = 0; i < base::size(kInvalidHeaderTestCases); ++i) {
    auto& test_case = kInvalidHeaderTestCases[i];
    ParseHeader(kUrl_, test_case.header_value);
    EXPECT_EQ(0u, cache()->GetEndpointCount())
        << "Invalid Report-To header (" << test_case.description << ": \""
        << test_case.header_value << "\") parsed as valid.";
    if (mock_store()) {
      mock_store()->Flush();
      EXPECT_EQ(0, mock_store()->StoredEndpointsCount());
      EXPECT_EQ(0, mock_store()->StoredEndpointGroupsCount());
    }
  }
}
TEST_P ( ReportingHeaderParserTest , Invalid ) { static const struct { const char * header_value ; const char * description ; } kInvalidHeaderTestCases [ ] = { { " \" \" \" \" " , " " } , { " \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" " " \" \" \" \" \" \" " , " " } , { " \" \" " " \" \" \" \" \" \" \" \" \" \" " , " " } , { " \" \" " " \" \" \" \" \" \" \" \" " , " " } , { " \" \" " " \" \" \" \" \" \" \" \" \" \" " , " " } , { " \" \" " " \" \" \" \" \" \" \" \" " , " " } , { " \" \" \" \" \" \" \" \" " " \" \" \" \" \" \" \" \" " , " " } } ; for ( size_t i = 0 ; i < base :: size ( kInvalidHeaderTestCases ) ; ++ i ) { auto & test_case = kInvalidHeaderTestCases [ i ] ; ParseHeader ( kUrl_ , test_case . header_value ) ; EXPECT_EQ ( 0u , cache ( ) -> GetEndpointCount ( ) ) << " " << test_case . description << " \" " << test_case . header_value << " \" " ; if ( mock_store ( ) ) { mock_store ( ) -> Flush ( ) ; EXPECT_EQ ( 0 , mock_store ( ) -> StoredEndpointsCount ( ) ) ; EXPECT_EQ ( 0 , mock_store ( ) -> StoredEndpointGroupsCount ( ) ) ; } } }
TODO(juliatuttle): Ideally these tests should be expecting that JSON parsing
(and therefore header parsing) may happen asynchronously, but the entire
pipeline is also tested by NetworkErrorLoggingEndToEndTest.
TODO ( juliatuttle ) : Ideally these tests should be expecting that JSON parsing ( and therefore header parsing ) may happen asynchronously but the entire pipeline is also tested by NetworkErrorLoggingEndToEndTest .
// Note that a non-boolean include_subdomains field is *not* invalid, per // the spec. // Priority should be a nonnegative integer. // Weight should be a non-negative integer.