blob: 455837c7492046cdfb63402b9935f3d2337d9a5f [file] [log] [blame]
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ui/file_name.h"
#include <string>
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_pdf {
TEST(FileNameTest, GetFileNameForSaveFromUrl) {
EXPECT_EQ("b.pdf", GetFileNameForSaveFromUrl("https://test/a/b.pdf"));
// File extensions should be kept as-is.
EXPECT_EQ("b.hat", GetFileNameForSaveFromUrl("https://test/a/b.hat"));
// Most escaped characters should be unescaped.
EXPECT_EQ("a b.pdf", GetFileNameForSaveFromUrl("https://test/%61%20b.pdf"));
// Escaped file path delimiters and control codes should be replaced by a
// placeholder.
EXPECT_EQ("a_b_.pdf", GetFileNameForSaveFromUrl("https://test/a%2Fb%01.pdf"));
// UTF-8 characters, including ones left escaped by UnescapeURLComponent() for
// security reasons, are allowed in file paths.
} // namespace chrome_pdf