Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match exact host in autoplay whitelist before matching eTLD+1 (uplift to 1.6.x) #4786

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions browser/autoplay/autoplay_permission_context_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ class AutoplayWhitelistServiceTest : public BaseLocalDataFilesBrowserTest {

void SetUpOnMainThread() override {
BaseLocalDataFilesBrowserTest::SetUpOnMainThread();
whitelist_autoplay_url_ =
embedded_test_server()->GetURL("example.com", "/autoplay_by_attr.html");
// exact host match
whitelist_autoplay_urls_.push_back(embedded_test_server()->GetURL(
"example.com", "/autoplay_by_attr.html"));
// eTLD+1 match
whitelist_autoplay_urls_.push_back(embedded_test_server()->GetURL(
"sub.example.com", "/autoplay_by_attr.html"));
// exact host match with subdomain
whitelist_autoplay_urls_.push_back(embedded_test_server()->GetURL(
"sandbox.uphold.com", "/autoplay_by_attr.html"));
}

// BaseLocalDataFilesBrowserTest overrides
Expand Down Expand Up @@ -179,10 +186,12 @@ class AutoplayWhitelistServiceTest : public BaseLocalDataFilesBrowserTest {
ASSERT_EQ("PLAYING", msg_from_renderer);
}

const GURL& whitelist_autoplay_url() { return whitelist_autoplay_url_; }
const GURL& whitelist_autoplay_url(int index) {
return whitelist_autoplay_urls_[index];
}

private:
GURL whitelist_autoplay_url_;
std::vector<GURL> whitelist_autoplay_urls_;
};

// Autoplay blocks by default, no bubble is shown
Expand Down Expand Up @@ -553,16 +562,58 @@ IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, FileAutoplay) {
EXPECT_EQ(result, kVideoPlaying);
}

// Default allow autoplay on URLs in whitelist
IN_PROC_BROWSER_TEST_F(AutoplayWhitelistServiceTest, Allow) {
// Default allow autoplay on URLs in whitelist if host matches exactly
IN_PROC_BROWSER_TEST_F(AutoplayWhitelistServiceTest, AllowIfExactHostMatch) {
ASSERT_TRUE(InstallMockExtension());
std::string result;
PermissionRequestManager* manager =
PermissionRequestManager::FromWebContents(contents());
auto popup_prompt_factory =
std::make_unique<MockPermissionPromptFactory>(manager);

NavigateToURLUntilLoadStop(whitelist_autoplay_url(0));
EXPECT_FALSE(popup_prompt_factory->is_visible());
EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen(
PermissionRequestType::PERMISSION_AUTOPLAY));
EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount());
WaitForPlaying();
EXPECT_TRUE(
ExecuteScriptAndExtractString(contents(), kVideoPlayingDetect, &result));
EXPECT_EQ(result, kVideoPlaying);
}

// Default allow autoplay on URLs in whitelist if eTLD+1 matches
IN_PROC_BROWSER_TEST_F(AutoplayWhitelistServiceTest, AllowIfETLDPlusOneMatch) {
ASSERT_TRUE(InstallMockExtension());
std::string result;
PermissionRequestManager* manager =
PermissionRequestManager::FromWebContents(contents());
auto popup_prompt_factory =
std::make_unique<MockPermissionPromptFactory>(manager);

NavigateToURLUntilLoadStop(whitelist_autoplay_url(1));
EXPECT_FALSE(popup_prompt_factory->is_visible());
EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen(
PermissionRequestType::PERMISSION_AUTOPLAY));
EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount());
WaitForPlaying();
EXPECT_TRUE(
ExecuteScriptAndExtractString(contents(), kVideoPlayingDetect, &result));
EXPECT_EQ(result, kVideoPlaying);
}

// Default allow autoplay on URLs in whitelist if multi-domain host matches
// exactly
IN_PROC_BROWSER_TEST_F(AutoplayWhitelistServiceTest,
AllowIfExactSubdomainAndHostMatch) {
ASSERT_TRUE(InstallMockExtension());
std::string result;
PermissionRequestManager* manager =
PermissionRequestManager::FromWebContents(contents());
auto popup_prompt_factory =
std::make_unique<MockPermissionPromptFactory>(manager);

NavigateToURLUntilLoadStop(whitelist_autoplay_url());
NavigateToURLUntilLoadStop(whitelist_autoplay_url(2));
EXPECT_FALSE(popup_prompt_factory->is_visible());
EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen(
PermissionRequestType::PERMISSION_AUTOPLAY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ AutoplayWhitelistService::~AutoplayWhitelistService() {

bool AutoplayWhitelistService::ShouldAllowAutoplay(const GURL& url) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// look for exact host match (this is the only way that subdomains
// listed in the autoplay whitelist will match)
if (url.has_host() &&
autoplay_whitelist_client_->matchesHost(url.host().c_str()))
return true;
// look for match of eTLD+1
std::string etld_plus_one =
net::registry_controlled_domains::GetDomainAndRegistry(
url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
Expand Down
Binary file modified test/data/autoplay-whitelist-data/1/AutoplayWhitelist.dat
Binary file not shown.