#include <string_view>
#include "base/compiler_specific.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/types/fixed_array.h"
#include "build/build_config.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/public/browser/network_context_client_base.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace {
struct UploadResponse { … };
void GrantAccess(const base::FilePath& file, int process_id) { … }
void CreateFile(const base::FilePath& path, const char* content) { … }
void ValidateFileContents(base::File& file, std::string_view expected_content) { … }
const int kBrowserProcessId = …;
const int kRendererProcessId = …;
const char kFileContent1[] = …;
const char kFileContent2[] = …;
}
class NetworkContextClientBaseTest : public testing::Test { … };
TEST_F(NetworkContextClientBaseTest, UploadNoFiles) { … }
TEST_F(NetworkContextClientBaseTest, UploadOneValidAsyncFile) { … }
TEST_F(NetworkContextClientBaseTest, UploadOneValidFile) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(NetworkContextClientBaseTest,
DISABLED_UploadOneValidFileWithContentUri) {
base::FilePath image_path;
EXPECT_TRUE(
base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &image_path));
image_path = image_path.AppendASCII("content")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII("blank.jpg");
EXPECT_TRUE(base::PathExists(image_path));
base::FilePath content_path = base::InsertImageIntoMediaStore(image_path);
EXPECT_TRUE(content_path.IsContentUri());
EXPECT_TRUE(base::PathExists(content_path));
GrantAccess(content_path, kRendererProcessId);
UploadResponse response;
client_.OnFileUploadRequested(kRendererProcessId, false, {content_path},
GURL(),
std::move(response.callback));
task_environment_.RunUntilIdle();
EXPECT_EQ(net::OK, response.error_code);
ASSERT_EQ(1U, response.opened_files.size());
EXPECT_FALSE(response.opened_files[0].async());
std::string contents;
EXPECT_TRUE(base::ReadFileToString(image_path, &contents));
ValidateFileContents(response.opened_files[0], contents);
}
#endif
TEST_F(NetworkContextClientBaseTest, UploadTwoValidFiles) { … }
TEST_F(NetworkContextClientBaseTest, UploadOneUnauthorizedFile) { … }
TEST_F(NetworkContextClientBaseTest, UploadOneValidFileAndOneUnauthorized) { … }
TEST_F(NetworkContextClientBaseTest, UploadOneValidFileAndOneNotFound) { … }
TEST_F(NetworkContextClientBaseTest, UploadFromBrowserProcess) { … }
}