0
Files
src/content/web_test/renderer/blink_test_helpers.h
Md Hasibul Hasan 8d4451517d Convert base::StringPiece to std::string_view in //content except for
content/browser

The changes of this CL are made using the following script.
```
target_directory="content"
replace_string_in_files() {
  old_string="$1"
  new_string="$2"

  find "$target_directory" -type d \( -path "$target_directory/browser" -prune \) -o \( -name "*.cc" -o -name "*.h" \) -exec sed -i '' "s/$old_string/$new_string/g" {} +
}

delete_include() {
    find "$target_directory" -type d \( -path "$target_directory/browser" -prune \) -o \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do
        grep -v '#include "base/strings/string_piece.h"' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
    done
}

add_include() {
    find "$target_directory" -type d \( -path "$target_directory/browser" -prune \) -o \( -name "*.h" -o -name "*.cc" \) -print0 | while IFS= read -r -d '' file; do
        local include_added=false
        local tempfile=$(mktemp)

        if grep -qE 'std::(string|u16string)_view' "$file"; then
            while IFS= read -r line; do
                echo "$line" >> "$tempfile"
                if [[ $line =~ ^\s*#include ]]; then
                    if ! $include_added; then
                        echo "#include <string_view>" >> "$tempfile"
                        include_added=true
                    fi
                fi
            done < "$file"

            mv "$tempfile" "$file"

            if $include_added; then
                echo "Added #include <string_view> after the first include line in $file"
            else
                echo "No include line found in $file"
            fi
        else
            echo "std::string_view not found in $file"
        fi
    done
}

replace_string_in_files "base::StringPiece16" "std::u16string_view"
replace_string_in_files "base::StringPiece" "std::string_view"
delete_include
add_include

```
Replaced base::StringPiece16 with std::u16string_view
Replaced base::StringPiece with std::string_view
Removed header "base/strings/string_piece.h"
Added header "<string_view>" where applicable

Bug: 40506050
Change-Id: Ia6d2fd65a16e1a3db59532c085652fbb45dc6abc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5401324
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1285651}
2024-04-11 07:38:50 +00:00

47 lines
1.8 KiB
C++

// 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.
#ifndef CONTENT_WEB_TEST_RENDERER_BLINK_TEST_HELPERS_H_
#define CONTENT_WEB_TEST_RENDERER_BLINK_TEST_HELPERS_H_
#include <string_view>
#include "third_party/blink/public/platform/web_url.h"
namespace blink {
namespace web_pref {
struct WebPreferences;
}
} // namespace blink
namespace content {
struct TestPreferences;
// The TestRunner library keeps its settings in a TestPreferences object.
// The content_shell, however, uses WebPreferences. This method exports the
// settings from the TestRunner library which are relevant for web tests.
void ExportWebTestSpecificPreferences(const TestPreferences& from,
blink::web_pref::WebPreferences* to);
// Rewrites a URL requested from a web test. There are two rules:
// 1. If the URL is an absolute file path requested from a WPT test like
// 'file:///resources/testharness.js', then return a file URL to the file
// under WPT test directory. This is used only when the test is run manually
// with content_shell without a web server.
// 2. If the URL starts with file:///tmp/web_tests/, then return a file URL
// to a temporary file under the web_tests directory.
// 3. If the URL starts with file:///gen/, then return a file URL to the file
// under the gen/ directory of the build out.
blink::WebURL RewriteWebTestsURL(std::string_view utf8_url, bool is_wpt_mode);
// Applies the rewrite rules except 1 of RewriteWebTestsURL().
blink::WebURL RewriteFileURLToLocalResource(std::string_view resource);
// Returns true if |test_url| points to a web platform test (WPT).
bool IsWebPlatformTest(std::string_view test_url);
} // namespace content
#endif // CONTENT_WEB_TEST_RENDERER_BLINK_TEST_HELPERS_H_