Skip to content

Commit 63fcbf8

Browse files
committed
Uplift of #25499 (squashed) to release
1 parent 56b6307 commit 63fcbf8

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SelectorsPollerScript.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ window.__firefox__.execute(function($) {
564564
return false
565565
} else if (queryResults.foundFirstPartyResource) {
566566
return true
567+
} else if (showsSignificantText(element)) {
568+
// If the subtree HAS a significant amount of text (e.g., it doesn't just says "Advertisement")
569+
// it should be unhidden.
570+
return true
567571
} else if (queryResults.foundThirdPartyResource || queryResults.pendingSrcAttributes.size > 0) {
568572
if (pendingSrcAttributes !== undefined) {
569573
queryResults.pendingSrcAttributes.forEach((src) => {
@@ -572,12 +576,8 @@ window.__firefox__.execute(function($) {
572576
}
573577

574578
return false
575-
} else {
576-
// If the subtree doesn't have a significant amount of text (e.g., it
577-
// just says "Advertisement"), then no need to change anything; it should
578-
// stay hidden.
579-
return showsSignificantText(element)
580579
}
580+
return false
581581
}
582582

583583
const shouldUnhideElementAsync = async (element) => {

ios/brave-ios/Tests/ClientTests/Resources/html/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ <h1>Test Ads</h1>
2727

2828
<div id="test-ad-3rd-party">
2929
<img src="http://3rd_party.localhost/image.gif">
30-
This element should be always hidden (standard or aggressive mode) because it's a 3rd party ad.
30+
</div>
31+
32+
<div id="test-ad-3rd-party-sig-text">
33+
<img src="http://3rd_party.localhost/image.gif">
34+
This element should be not be hidden in standard mode because it contains significant amount of text.
35+
It should still be hidden in aggressive mode.
3136
</div>
3237

3338
<div id="test-ad-simple">

ios/brave-ios/Tests/ClientTests/User Scripts/ScriptExecutionTests.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ final class ScriptExecutionTests: XCTestCase {
224224
let initialStandardSelectors = Set([".test-ads-primary-standard div"])
225225
let initialAggressiveSelectors = Set([".test-ads-primary-aggressive div"])
226226
let polledAggressiveIds = ["test-ad-aggressive"]
227-
let polledStandardIds = ["test-ad-1st-party", "test-ad-3rd-party", "test-ad-simple"]
227+
let polledStandardIds = [
228+
"test-ad-1st-party", "test-ad-3rd-party", "test-ad-3rd-party-sig-text", "test-ad-simple",
229+
]
228230
let nestedIds = [
229231
"test-ad-primary-standard-1st-party", "test-ad-primary-standard-3rd-party",
230232
"test-ad-primary-aggressive-1st-party", "test-ad-primary-aggressive-3rd-party",
@@ -378,7 +380,10 @@ final class ScriptExecutionTests: XCTestCase {
378380
)
379381
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-1st-party"), true)
380382
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-aggressive"), true)
383+
// hidden because of 3rd party src
381384
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-3rd-party"), true)
385+
// unhidden because it contains significant amount of text
386+
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-3rd-party-sig-text"), true)
382387
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-simple"), true)
383388
XCTAssertEqual(
384389
resultsAfterPump?.hiddenIds.contains("test-ad-primary-aggressive-1st-party"),

0 commit comments

Comments
 (0)