From 4db0be3b81fc8fc8d753677807fa9216b46d1168 Mon Sep 17 00:00:00 2001 From: Ivan Efremov Date: Wed, 11 Nov 2020 12:36:05 +0700 Subject: [PATCH] 12351: Fix flaky adblocker test. https://github.com/brave/brave-browser/issues/12351 --- .../ad_block_service_browsertest.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index e5b282d205ed..2158b7e53d3e 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -497,8 +497,7 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, NewTabContinuesToBlock) { } // XHRs and ads in a cross-site iframe are blocked as well. -// Enable when https://github.com/brave/brave-browser/issues/12351 is fixed -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, DISABLED_SubFrame) { +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SubFrame) { SetDefaultComponentIdAndBase64PublicKeyForTest( kDefaultAdBlockComponentTestId, kDefaultAdBlockComponentTestBase64PublicKey); @@ -517,10 +516,16 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, DISABLED_SubFrame) { // Check also an explicit request for a script since it is a common real-world // scenario. - ASSERT_TRUE(ExecuteScript(contents->GetAllFrames()[1], - "var s = document.createElement('script');" - "s.setAttribute('src', 'adbanner.js?2');" - "document.head.appendChild(s);")); + ASSERT_EQ(true, EvalJs(contents->GetAllFrames()[1], + R"( + new Promise(function (resolve, reject) { + var s = document.createElement('script'); + s.onload = reject; + s.onerror = () => resolve(true); + s.src = 'adbanner.js?2'; + document.head.appendChild(s); + }) + )")); content::RunAllTasksUntilIdle(); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 2ULL); }