Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Jul 7, 2023
1 parent a65907e commit 7995de2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ using brave_shields::features::kBraveAdblockCollapseBlockedElements;
using brave_shields::features::kBraveAdblockCookieListDefault;
using brave_shields::features::kBraveAdblockCosmeticFiltering;
using brave_shields::features::kBraveAdblockDefault1pBlocking;
using brave_shields::features::kBraveAdblockScriptletDebugLogs;
using brave_shields::features::kCosmeticFilteringJsPerformance;

AdBlockServiceTest::AdBlockServiceTest()
Expand Down Expand Up @@ -2255,6 +2256,47 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringWindowScriptlet) {
EXPECT_EQ(base::Value(true), result.value);
}

class ScriptletDebugLogsFlagEnabledTest : public AdBlockServiceTest {
public:
ScriptletDebugLogsFlagEnabledTest() {
feature_list_.InitAndEnableFeature(kBraveAdblockScriptletDebugLogs);
}

private:
base::test::ScopedFeatureList feature_list_;
};

// Test that scriptlet injection has access to `canDebug` inside of
// `scriptletGlobals`, and that it is set to `true`.
IN_PROC_BROWSER_TEST_F(ScriptletDebugLogsFlagEnabledTest, CanDebugSetToTrue) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
std::string scriptlet =
"(function() {"
" if (scriptletGlobals.get('canDebug')) {"
" window.success = true;"
" }"
"})();";
std::string scriptlet_base64;
base::Base64Encode(scriptlet, &scriptlet_base64);
UpdateAdBlockInstanceWithRules(
"b.com##+js(debuggable)",
"[{"
"\"name\": \"debuggable\","
"\"aliases\": [],"
"\"kind\": {\"mime\": \"application/javascript\"},"
"\"content\": \"" +
scriptlet_base64 + "\"}]");

GURL tab_url =
embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), tab_url));

content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();

EXPECT_EQ(true, EvalJs(contents, R"(window.success)"));
}

// Test scriptlet injection with DeAMP enabled
IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CheckForDeAmpPref) {
std::string scriptlet =
Expand Down

0 comments on commit 7995de2

Please sign in to comment.