#include <signal.h>
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/task/sequenced_task_runner.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/first_run/first_run_dialog.h"
#include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
namespace first_run {
class FirstRunInternalPosixTest : public InProcessBrowserTest {
protected:
FirstRunInternalPosixTest() = default;
FirstRunInternalPosixTest(const FirstRunInternalPosixTest&) = delete;
FirstRunInternalPosixTest& operator=(const FirstRunInternalPosixTest&) =
delete;
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kForceFirstRun);
}
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
bool SetUpUserDataDirectory() override {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
const base::FilePath local_state_file =
user_data_dir.Append(chrome::kLocalStateFilename);
const std::string empty_prefs = "{}";
base::WriteFile(local_state_file, empty_prefs.data());
return true;
}
#endif
void SetUpInProcessBrowserTestFixture() override {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
internal::ForceFirstRunDialogShownForTesting(true);
#endif
GetBeforeShowFirstRunDialogHookForTesting() = base::BindOnce(
&FirstRunInternalPosixTest::SetupNestedTask, base::Unretained(this));
EXPECT_FALSE(inspected_state_);
}
void TearDownInProcessBrowserTestFixture() override {
EXPECT_TRUE(inspected_state_);
EXPECT_FALSE(GetBeforeShowFirstRunDialogHookForTesting());
GetBeforeShowFirstRunDialogHookForTesting().Reset();
InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
}
private:
void SetupNestedTask() {
EXPECT_TRUE(base::SequencedTaskRunner::GetCurrentDefault());
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&FirstRunInternalPosixTest::InspectState,
base::Unretained(this)));
}
void InspectState() {
raise(SIGINT);
inspected_state_ = true;
}
bool inspected_state_ = false;
};
#if BUILDFLAG(IS_LINUX) && defined(ADDRESS_SANITIZER)
#define MAYBE_HandleSigint DISABLED_HandleSigint
#else
#define MAYBE_HandleSigint HandleSigint
#endif
IN_PROC_BROWSER_TEST_F(FirstRunInternalPosixTest, MAYBE_HandleSigint) {
ADD_FAILURE() << "Should never be called";
}
}