Skip to content

Commit

Permalink
Update UserDataDir unit tests to follow upstream.
Browse files Browse the repository at this point in the history
Chromium change:

https://source.chromium.org/chromium/chromium/src/+/ff5efbff97142bbf09194aac1542b88b44599d52

commit ff5efbff97142bbf09194aac1542b88b44599d52
Author: Peter Kvitek <[email protected]>
Date:   Thu Sep 26 12:44:23 2024 +0000

    Reland "[headless] Create temporary user data directory early on Windows"

    This is a reland of commit 0496c1d95307bbf203a9830e2c705483902f8429

    This CL fixes unit tests asserts by refactoring failing tests.
    It supersedes the forward fix CL https://crrev.com/c/5889444,
    see the relevant comments there.

    Original change's description:
    > [headless] Create temporary user data directory early on Windows
    >
    > In order to run in parallel with a regular Chrome instance and with
    > other headless Chrome instances each headless Chrome instance needs
    > to have its own user data directory. Normally this is done by adding
    > --user-data-dir switch in headless Chrome initialization code called
    > from ChromeMain. However, on Windows this is already too late since
    > user data directory needs to be present during early crash reporter
    > initialization in ELF.
    >
    > This CL adds --headless switch handling to install_static component
    > which ensures that if the switch is present, the temporary
    > user data directory is created and passed down to the headless
    > Chrome initialization code.
    >
    > Also fixed a couple of browser tests which used to create a
    > temporary user data directory and write some test data into it.
    > Since these were InProcessBrowserTests derived tests they already
    > had user data directory specified in the command line so adding
    > a duplicate --user-data-dir resulted in ambiguity that caused
    > test failure on win-rel.
    >
    > Bug: 362545030, 362301064
  • Loading branch information
mkarolin authored and cdesouza-chromium committed Oct 3, 2024
1 parent 4a5878b commit d126ef8
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@ class ScopedNTRegistryTestingOverride {
TEST(UserDataDir, EmptyResultsInDefault) {
std::wstring result, invalid;

install_static::GetUserDataDirectoryImpl(L"", kFakeInstallConstants, &result,
&invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe", kFakeInstallConstants,
&result, &invalid);
EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix));
EXPECT_EQ(std::wstring(), invalid);

result = L"";
install_static::GetUserDataDirectoryImpl(
L"brave.exe --user-data-dir=", kFakeInstallConstants, &result, &invalid);
EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix));
EXPECT_EQ(std::wstring(), invalid);
}

TEST(UserDataDir, InvalidResultsInDefault) {
std::wstring result, invalid;

install_static::GetUserDataDirectoryImpl(L"<>|:", kFakeInstallConstants,
&result, &invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe --user-data-dir=<>|:",
kFakeInstallConstants, &result,
&invalid);
EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix));
EXPECT_EQ(L"<>|:", invalid);
}
Expand All @@ -84,8 +91,9 @@ TEST(UserDataDir, RegistrySettingsInHKLMOverrides) {
LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy");
ASSERT_EQ(rv, ERROR_SUCCESS);

install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
&result, &invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe --user-data-dir=xxx",
kFakeInstallConstants, &result,
&invalid);

EXPECT_TRUE(EndsWith(result, L"\\yyy"));
EXPECT_EQ(std::wstring(), invalid);
Expand All @@ -106,8 +114,9 @@ TEST(UserDataDir, RegistrySettingsInHKCUOverrides) {
LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy");
ASSERT_EQ(rv, ERROR_SUCCESS);

install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
&result, &invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe --user-data-dir=xxx",
kFakeInstallConstants, &result,
&invalid);

EXPECT_TRUE(EndsWith(result, L"\\yyy"));
EXPECT_EQ(std::wstring(), invalid);
Expand Down Expand Up @@ -135,8 +144,9 @@ TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) {
rv = key2.WriteValue(kUserDataDirRegistryKey, L"222");
ASSERT_EQ(rv, ERROR_SUCCESS);

install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
&result, &invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe --user-data-dir=xxx",
kFakeInstallConstants, &result,
&invalid);

EXPECT_TRUE(EndsWith(result, L"\\111"));
EXPECT_EQ(std::wstring(), invalid);
Expand All @@ -154,8 +164,9 @@ TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) {
LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}");
ASSERT_EQ(rv, ERROR_SUCCESS);

install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
&result, &invalid);
install_static::GetUserDataDirectoryImpl(L"brave.exe --user-data-dir=xxx",
kFakeInstallConstants, &result,
&invalid);

EXPECT_EQ(strlen("X:\\WINDOWS"), result.size());
EXPECT_EQ(std::wstring::npos, result.find(L"${windows}"));
Expand Down

0 comments on commit d126ef8

Please sign in to comment.