Skip to content

Commit

Permalink
Merge pull request #2484 from brave/android-component-updater
Browse files Browse the repository at this point in the history
Android component updater
  • Loading branch information
bridiver authored May 24, 2019
2 parents e67c8ea + 662850b commit e22053f
Show file tree
Hide file tree
Showing 64 changed files with 1,336 additions and 1,162 deletions.
7 changes: 3 additions & 4 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ source_set("browser_process") {
"component_updater/brave_component_installer.h",
"component_updater/brave_component_updater_configurator.cc",
"component_updater/brave_component_updater_configurator.h",
"component_updater/brave_component_updater_delegate.cc",
"component_updater/brave_component_updater_delegate.h",
"component_updater/brave_crx_update_service.cc",
"component_updater/brave_crx_update_service.h",
"content_settings/brave_cookie_settings_factory.cc",
"content_settings/brave_cookie_settings_factory.h",
# TODO(bridiver) - move this from extensions -> component_updater
# and rename to BraveComponent
"extensions/brave_component_extension.cc",
"extensions/brave_component_extension.h",
"geolocation/brave_geolocation_permission_context.cc",
"geolocation/brave_geolocation_permission_context.h",
"mac/sparkle_glue.mm",
Expand Down Expand Up @@ -91,6 +89,7 @@ source_set("browser_process") {
"//brave/browser/tor",
"//brave/common",
"//brave/components/brave_ads/browser",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_referrals/browser",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser:brave_shields",
Expand Down
259 changes: 131 additions & 128 deletions browser/autoplay/autoplay_permission_context_browsertest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

Expand All @@ -10,7 +11,7 @@
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_paths.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/local_data_files_service.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/autoplay_whitelist_service.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/extension_browsertest.h"
Expand All @@ -36,10 +37,10 @@ const char kVideoPlayingDetect[] =

using extensions::ExtensionBrowserTest;

const std::string kLocalDataFilesComponentTestId(
"eclbkhjphkhalklhipiicaldjbnhdfkc");
const char kLocalDataFilesComponentTestId[] =
"eclbkhjphkhalklhipiicaldjbnhdfkc";

const std::string kLocalDataFilesComponentTestBase64PublicKey =
const char kLocalDataFilesComponentTestBase64PublicKey[] =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsleoSxQ3DN+6xym2P1uX"
"mN6ArIWd9Oru5CSjS0SRE5upM2EnAl/C20TP8JdIlPi/3tk/SN6Y92K3xIhAby5F"
"0rbPDSTXEWGy72tv2qb/WySGwDdvYQu9/J5sEDneVcMrSHcC0VWgcZR0eof4BfOy"
Expand All @@ -49,123 +50,124 @@ const std::string kLocalDataFilesComponentTestBase64PublicKey =
"qwIDAQAB";

class AutoplayPermissionContextBrowserTest : public InProcessBrowserTest {
public:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

content_client_.reset(new ChromeContentClient);
content::SetContentClient(content_client_.get());
browser_content_client_.reset(new BraveContentBrowserClient());
content::SetBrowserClientForTesting(browser_content_client_.get());

host_resolver()->AddRule("*", "127.0.0.1");
content::SetupCrossSiteRedirector(embedded_test_server());

brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
test_data_dir = test_data_dir.AppendASCII("autoplay");
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);

ASSERT_TRUE(embedded_test_server()->Start());

autoplay_method_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_method.html");
autoplay_attr_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_attr.html");
autoplay_method_muted_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_method_muted.html");
autoplay_attr_muted_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_attr_muted.html");
file_autoplay_method_url_ =
GURL("file://" + test_data_dir.AsUTF8Unsafe() +
"/autoplay_by_method.html");
file_autoplay_attr_url_ =
GURL("file://" + test_data_dir.AsUTF8Unsafe() +
"/autoplay_by_attr.html");

GURL pattern_url = embedded_test_server()->GetURL("a.com", "/index.html");
top_level_page_pattern_ =
ContentSettingsPattern::FromString(pattern_url.spec());
}

void TearDown() override {
browser_content_client_.reset();
content_client_.reset();
}

const GURL& autoplay_method_url() { return autoplay_method_url_; }
const GURL& autoplay_attr_url() { return autoplay_attr_url_; }
const GURL& autoplay_method_muted_url() { return autoplay_method_muted_url_; }
const GURL& autoplay_attr_muted_url() { return autoplay_attr_muted_url_; }
const GURL& file_autoplay_method_url() { return file_autoplay_method_url_; }
const GURL& file_autoplay_attr_url() { return file_autoplay_attr_url_; }

const ContentSettingsPattern& top_level_page_pattern() {
return top_level_page_pattern_;
}

HostContentSettingsMap * content_settings() {
return HostContentSettingsMapFactory::GetForProfile(browser()->profile());
}

void AllowAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_ALLOW);
}

void AskAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_ASK);
}

void BlockAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_BLOCK);
}

content::WebContents* contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}

bool NavigateToURLUntilLoadStop(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url);
return WaitForLoadStop(contents());
}

void WaitForPlaying() {
std::string msg_from_renderer;
ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), "notifyWhenPlaying();",
&msg_from_renderer));
ASSERT_EQ("PLAYING", msg_from_renderer);
}

private:
GURL autoplay_method_url_;
GURL autoplay_attr_url_;
GURL autoplay_method_muted_url_;
GURL autoplay_attr_muted_url_;
GURL file_autoplay_method_url_;
GURL file_autoplay_attr_url_;
ContentSettingsPattern top_level_page_pattern_;
std::unique_ptr<ChromeContentClient> content_client_;
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
public:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

content_client_.reset(new ChromeContentClient);
content::SetContentClient(content_client_.get());
browser_content_client_.reset(new BraveContentBrowserClient());
content::SetBrowserClientForTesting(browser_content_client_.get());

host_resolver()->AddRule("*", "127.0.0.1");
content::SetupCrossSiteRedirector(embedded_test_server());

brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
test_data_dir = test_data_dir.AppendASCII("autoplay");
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);

ASSERT_TRUE(embedded_test_server()->Start());

autoplay_method_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_method.html");
autoplay_attr_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_attr.html");
autoplay_method_muted_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_method_muted.html");
autoplay_attr_muted_url_ =
embedded_test_server()->GetURL("a.com", "/autoplay_by_attr_muted.html");
file_autoplay_method_url_ =
GURL("file://" + test_data_dir.AsUTF8Unsafe() +
"/autoplay_by_method.html");
file_autoplay_attr_url_ =
GURL("file://" + test_data_dir.AsUTF8Unsafe() +
"/autoplay_by_attr.html");

GURL pattern_url = embedded_test_server()->GetURL("a.com", "/index.html");
top_level_page_pattern_ =
ContentSettingsPattern::FromString(pattern_url.spec());
}

void TearDown() override {
browser_content_client_.reset();
content_client_.reset();
}

const GURL& autoplay_method_url() { return autoplay_method_url_; }
const GURL& autoplay_attr_url() { return autoplay_attr_url_; }
const GURL& autoplay_method_muted_url() { return autoplay_method_muted_url_; }
const GURL& autoplay_attr_muted_url() { return autoplay_attr_muted_url_; }
const GURL& file_autoplay_method_url() { return file_autoplay_method_url_; }
const GURL& file_autoplay_attr_url() { return file_autoplay_attr_url_; }

const ContentSettingsPattern& top_level_page_pattern() {
return top_level_page_pattern_;
}

HostContentSettingsMap * content_settings() {
return HostContentSettingsMapFactory::GetForProfile(browser()->profile());
}

void AllowAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_ALLOW);
}

void AskAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_ASK);
}

void BlockAutoplay() {
content_settings()->SetContentSettingCustomScope(
top_level_page_pattern_,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_AUTOPLAY,
std::string(),
CONTENT_SETTING_BLOCK);
}

content::WebContents* contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}

bool NavigateToURLUntilLoadStop(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url);
return WaitForLoadStop(contents());
}

void WaitForPlaying() {
std::string msg_from_renderer;
ASSERT_TRUE(ExecuteScriptAndExtractString(contents(),
"notifyWhenPlaying();",
&msg_from_renderer));
ASSERT_EQ("PLAYING", msg_from_renderer);
}

private:
GURL autoplay_method_url_;
GURL autoplay_attr_url_;
GURL autoplay_method_muted_url_;
GURL autoplay_attr_muted_url_;
GURL file_autoplay_method_url_;
GURL file_autoplay_attr_url_;
ContentSettingsPattern top_level_page_pattern_;
std::unique_ptr<ChromeContentClient> content_client_;
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
};

class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {
public:
public:
AutoplayWhitelistServiceTest() {}

void SetUp() override {
Expand All @@ -185,7 +187,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {
void PreRunTestOnMainThread() override {
ExtensionBrowserTest::PreRunTestOnMainThread();
WaitForAutoplayWhitelistServiceThread();
ASSERT_TRUE(g_brave_browser_process->local_data_files_service()->IsInitialized());
ASSERT_TRUE(
g_brave_browser_process->local_data_files_service()->IsInitialized());
}

void InitEmbeddedTestServer() {
Expand All @@ -198,7 +201,7 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {
}

void InitService() {
brave_shields::LocalDataFilesService::
brave_component_updater::LocalDataFilesService::
SetComponentIdAndBase64PublicKeyForTest(
kLocalDataFilesComponentTestId,
kLocalDataFilesComponentTestBase64PublicKey);
Expand All @@ -212,8 +215,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {
bool InstallAutoplayWhitelistExtension() {
base::FilePath test_data_dir;
GetTestDataDir(&test_data_dir);
const extensions::Extension* mock_extension =
InstallExtension(test_data_dir.AppendASCII("autoplay-whitelist-data"), 1);
const extensions::Extension* mock_extension = InstallExtension(
test_data_dir.AppendASCII("autoplay-whitelist-data"), 1);
if (!mock_extension)
return false;

Expand All @@ -225,9 +228,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {
}

void WaitForAutoplayWhitelistServiceThread() {
scoped_refptr<base::ThreadTestHelper> io_helper(
new base::ThreadTestHelper(
g_brave_browser_process->autoplay_whitelist_service()->GetTaskRunner()));
scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper(
g_brave_browser_process->local_data_files_service()->GetTaskRunner()));
ASSERT_TRUE(io_helper->Run());
}

Expand All @@ -242,14 +244,15 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest {

void WaitForPlaying() {
std::string msg_from_renderer;
ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), "notifyWhenPlaying();",
ASSERT_TRUE(ExecuteScriptAndExtractString(contents(),
"notifyWhenPlaying();",
&msg_from_renderer));
ASSERT_EQ("PLAYING", msg_from_renderer);
}

const GURL& whitelist_autoplay_url() { return whitelist_autoplay_url_; }

private:
private:
GURL whitelist_autoplay_url_;
};

Expand Down
Loading

0 comments on commit e22053f

Please sign in to comment.