Skip to content

Commit

Permalink
Uplift of #25499 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-builds committed Sep 10, 2024
1 parent 6d9d9dd commit 2569305
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ window.__firefox__.execute(function($) {
return false
} else if (queryResults.foundFirstPartyResource) {
return true
} else if (showsSignificantText(element)) {
// If the subtree HAS a significant amount of text (e.g., it doesn't just says "Advertisement")
// it should be unhidden.
return true
} else if (queryResults.foundThirdPartyResource || queryResults.pendingSrcAttributes.size > 0) {
if (pendingSrcAttributes !== undefined) {
queryResults.pendingSrcAttributes.forEach((src) => {
Expand All @@ -572,12 +576,8 @@ window.__firefox__.execute(function($) {
}

return false
} else {
// If the subtree doesn't have a significant amount of text (e.g., it
// just says "Advertisement"), then no need to change anything; it should
// stay hidden.
return showsSignificantText(element)
}
return false
}

const shouldUnhideElementAsync = async (element) => {
Expand Down
7 changes: 6 additions & 1 deletion ios/brave-ios/Tests/ClientTests/Resources/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ <h1>Test Ads</h1>

<div id="test-ad-3rd-party">
<img src="http://3rd_party.localhost/image.gif">
This element should be always hidden (standard or aggressive mode) because it's a 3rd party ad.
</div>

<div id="test-ad-3rd-party-sig-text">
<img src="http://3rd_party.localhost/image.gif">
This element should be not be hidden in standard mode because it contains significant amount of text.
It should still be hidden in aggressive mode.
</div>

<div id="test-ad-simple">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ final class ScriptExecutionTests: XCTestCase {
let initialStandardSelectors = Set([".test-ads-primary-standard div"])
let initialAggressiveSelectors = Set([".test-ads-primary-aggressive div"])
let polledAggressiveIds = ["test-ad-aggressive"]
let polledStandardIds = ["test-ad-1st-party", "test-ad-3rd-party", "test-ad-simple"]
let polledStandardIds = [
"test-ad-1st-party", "test-ad-3rd-party", "test-ad-3rd-party-sig-text", "test-ad-simple",
]
let nestedIds = [
"test-ad-primary-standard-1st-party", "test-ad-primary-standard-3rd-party",
"test-ad-primary-aggressive-1st-party", "test-ad-primary-aggressive-3rd-party",
Expand Down Expand Up @@ -378,7 +380,10 @@ final class ScriptExecutionTests: XCTestCase {
)
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-1st-party"), true)
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-aggressive"), true)
// hidden because of 3rd party src
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-3rd-party"), true)
// unhidden because it contains significant amount of text
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-3rd-party-sig-text"), true)
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-simple"), true)
XCTAssertEqual(
resultsAfterPump?.hiddenIds.contains("test-ad-primary-aggressive-1st-party"),
Expand Down

0 comments on commit 2569305

Please sign in to comment.