// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h" #include <stddef.h> #include <memory> #include <utility> #include "base/values.h" #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" #include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/web_request/web_request_info.h" #include "net/http/http_util.h" #include "services/network/public/mojom/fetch_api.mojom-shared.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace extensions { keys; namespace { const char kUnknownConditionName[] = …; TEST(WebRequestConditionAttributeTest, CreateConditionAttribute) { … } TEST(WebRequestConditionAttributeTest, ResourceType) { … } TEST(WebRequestConditionAttributeTest, ContentType) { … } // Testing WebRequestConditionAttributeStages. This iterates over all stages, // and tests a couple of "stage" attributes -- one created with an empty set of // applicable stages, one for each stage applicable for that stage, and one // applicable in all stages. TEST(WebRequestConditionAttributeTest, Stages) { … } namespace { // Builds a vector of vectors of string pointers from an array of strings. // |array| is in fact a sequence of arrays. The array |sizes| captures the sizes // of all parts of |array|, and |size| is the length of |sizes| itself. // Example (this is pseudo-code, not C++): // array = { "a", "b", "c", "d", "e", "f" } // sizes = { 2, 0, 4 } // size = 3 // results in out == { {&"a", &"b"}, {}, {&"c", &"d", &"e", &"f"} } void GetArrayAsVector(const std::string array[], const size_t sizes[], const size_t size, std::vector< std::vector<const std::string*> >* out) { … } // Builds a base::Value::Dict from an array of the form {name1, value1, name2, // value2, ...}. Values for the same key are grouped in a List. base::Value::Dict GetDictFromArray( const std::vector<const std::string*>& array) { … } // Returns whether the response headers from |request_info| satisfy the match // criteria given in |tests|. For at least one |i| all tests from |tests[i]| // must pass. void MatchAndCheck(const std::vector<std::vector<const std::string*>>& tests, const std::string& key, RequestStage stage, const WebRequestInfo& request_info, bool* result) { … } } // namespace // Here we test WebRequestConditionAttributeRequestHeaders for matching // correctly against request headers. This test is not as extensive as // "ResponseHeaders" (below), because the header-matching code is shared // by both types of condition attributes, so it is enough to test it once. TEST(WebRequestConditionAttributeTest, RequestHeaders) { … } // Here we test WebRequestConditionAttributeResponseHeaders for: // 1. Correct implementation of prefix/suffix/contains/equals matching. // 2. Performing logical disjunction (||) between multiple specifications. // 3. Negating the match in case of 'doesNotContainHeaders'. TEST(WebRequestConditionAttributeTest, ResponseHeaders) { … } TEST(WebRequestConditionAttributeTest, HideResponseHeaders) { … } } // namespace } // namespace extensions