fix(accounts): keep first login launch in one window

This commit is contained in:
chengma
2026-07-14 17:22:52 +08:00
parent a4ac3f8ee5
commit 699625ea0e
10 changed files with 608 additions and 60 deletions
+51 -1
View File
@@ -236,6 +236,8 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
self.assertIn("--remote-debugging-port=9222", args)
self.assertIn("--remote-allow-origins=*", args)
self.assertIn(f"--user-data-dir={user_data_dir}", args)
self.assertNotIn("--no-first-run", args)
self.assertNotIn("--no-default-browser-check", args)
self.assertTrue(os.path.isdir(user_data_dir))
self.assert_removed(temp_dir)
@@ -255,6 +257,45 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_build_launch_args_appends_valid_initial_url_once(self):
with self.make_temp_dir() as temp_dir:
cfg = {"chrome_path": "chrome.exe", "user_data_root": temp_dir}
account = {"alias": "alias", "debug_port": 9222}
initial_url = "https://seller.shopee.tw/portal/"
args = chrome.build_launch_args(
account,
config=cfg,
initial_url=initial_url,
)
self.assertEqual(initial_url, args[-1])
self.assertEqual(1, args.count(initial_url))
self.assertEqual(1, args.count("--no-first-run"))
self.assertEqual(1, args.count("--no-default-browser-check"))
self.assert_removed(temp_dir)
def test_build_launch_args_rejects_untrusted_initial_url(self):
account = {"alias": "alias", "debug_port": 9222}
cfg = {"chrome_path": "chrome.exe"}
for initial_url in (
"ftp://seller.shopee.tw/portal/",
"https://example.com/portal/",
"https://evilshopee.tw/portal/",
"https://user:secret@seller.shopee.tw/portal/",
"https:///portal/",
):
with self.subTest(initial_url=initial_url), self.assertRaises(
chrome.ChromeLaunchError
):
chrome.build_launch_args(
account,
config=cfg,
initial_url=initial_url,
)
def test_build_launch_args_rejects_invalid_account(self):
with self.assertRaises(chrome.ChromeLaunchError):
chrome.build_launch_args(
@@ -268,8 +309,13 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
cfg = {"chrome_path": "chrome.exe", "user_data_root": temp_dir}
process = object()
initial_url = "https://seller.shopee.tw/portal/"
with mock.patch("app.chrome.subprocess.Popen", return_value=process) as popen:
result = chrome.launch_chrome(account, config=cfg)
result = chrome.launch_chrome(
account,
config=cfg,
initial_url=initial_url,
)
self.assertIs(process, result)
popen.assert_called_once()
@@ -277,6 +323,7 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
self.assertEqual("chrome.exe", args[0])
self.assertIn("--remote-debugging-port=9222", args)
self.assertIn("--remote-allow-origins=*", args)
self.assertEqual(initial_url, args[-1])
self.assert_removed(temp_dir)
@@ -309,6 +356,9 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
self.assertIn("--remote-allow-origins=*", script)
self.assertIn("--user-data-dir=", script)
self.assertIn("profile with space", script)
self.assertNotIn("seller.shopee", script)
self.assertNotIn("--no-first-run", script)
self.assertNotIn("--no-default-browser-check", script)
self.assert_removed(temp_dir)