// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file contains the ResponseAnalyzerTests (which test the response // analyzer's behavior in several parameterized test scenarios) and at the end // includes the CrossOriginReadBlockingTests, which are more typical unittests. #include <initializer_list> #include <memory> #include <string> #include <string_view> #include <utility> #include <vector> #include "base/test/task_environment.h" #include "net/base/mime_sniffer.h" #include "net/http/http_util.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_builder.h" #include "net/url_request/url_request_test_util.h" #include "services/network/orb/orb_impl.h" #include "services/network/orb/orb_mimetypes.h" #include "services/network/public/mojom/url_response_head.mojom.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace network::orb { namespace { // CORB's verdict on a given scenario. kAllowBecauseOutOfData occurs when one of // the sniffers still desires more data but the response has run out, or // net::kMaxBytesToSniff has been reached. enum class Verdict { … }; constexpr int kVerdictPacketForHeadersBasedVerdict = …; constexpr int kVerdictPacketForInconclusiveSniffing = …; // This struct is used to describe each test case in this file. It's passed as // a test parameter to each TEST_P test. struct TestScenario { … }; inline std::ostream& operator<<(std::ostream& out, const MimeType& value) { … } // Stream operator to let GetParam() print a useful result if any tests fail. ::std::ostream& operator<<(::std::ostream& os, const TestScenario& scenario) { … } // An HTML response with an HTML comment that's longer than the sniffing // threshold. We don't sniff past net::kMaxBytesToSniff, so these are not // protected const char kHTMLWithTooLongComment[] = …; // A set of test cases that verify CrossSiteDocumentResourceHandler correctly // classifies network responses as allowed or blocked. These TestScenarios are // passed to the TEST_P tests below as test parameters. const TestScenario kScenarios[] = …; } // namespace // Tests that verify ResponseAnalyzer correctly classifies network responses as // allowed or blocked. // // The various test cases are passed as a list of TestScenario structs. class ResponseAnalyzerTest : public testing::Test, public testing::WithParamInterface<TestScenario> { … }; // namespace network TEST_P(ResponseAnalyzerTest, OpaqueResponseBlocking) { … } INSTANTIATE_TEST_SUITE_P(…); // ============================================================================= // The following individual tests check the behaviour of various methods in // isolation. // ============================================================================= mojom::URLResponseHeadPtr CreateResponse(std::string raw_headers) { … } TEST(CrossOriginReadBlockingTest, OrbReportsIssuesOnARAResponse) { … } } // namespace network::orb