From b59425b85cb7ea77e0bfbd59be5576d4a03d6804 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Wed, 4 Apr 2018 00:34:52 -0700 Subject: [PATCH 1/3] Implement third party fingerprinting protection --- BUILD.gn | 1 + .../content_settings/core/browser/BUILD.gn | 12 ++++++ .../brave_host_content_settings_map.cc | 29 ++++++++++++++ .../browser/brave_host_content_settings_map.h | 21 ++++++++++ ...host_content_settings_map_factory.cc.patch | 21 ++++++++++ ...enderer-content_settings_observer.cc.patch | 27 ------------- ...renderer-content_settings_observer.h.patch | 15 +------ ...-browser-host_content_settings_map.h.patch | 12 ++++++ renderer/brave_content_settings_observer.cc | 40 +++++++++++++++++++ renderer/brave_content_settings_observer.h | 13 ++++++ 10 files changed, 150 insertions(+), 41 deletions(-) create mode 100644 components/content_settings/core/browser/BUILD.gn create mode 100644 components/content_settings/core/browser/brave_host_content_settings_map.cc create mode 100644 components/content_settings/core/browser/brave_host_content_settings_map.h create mode 100644 patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch delete mode 100644 patches/chrome-renderer-content_settings_observer.cc.patch create mode 100644 patches/components-content_settings-core-browser-host_content_settings_map.h.patch diff --git a/BUILD.gn b/BUILD.gn index 02cbf64b0cf7..39274428f984 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,6 +17,7 @@ group("child_dependencies") { group("browser_dependencies") { public_deps = [ "//brave/browser", + "//brave/components/content_settings/core/browser", "//brave/extensions", "common", ":brave_framework_resources", diff --git a/components/content_settings/core/browser/BUILD.gn b/components/content_settings/core/browser/BUILD.gn new file mode 100644 index 000000000000..fb41e5dfd869 --- /dev/null +++ b/components/content_settings/core/browser/BUILD.gn @@ -0,0 +1,12 @@ +source_set("browser") { + sources = [ + "brave_host_content_settings_map.cc", + "brave_host_content_settings_map.h", + ] + + deps = [ + ] + + public_deps = [ + ] +} diff --git a/components/content_settings/core/browser/brave_host_content_settings_map.cc b/components/content_settings/core/browser/brave_host_content_settings_map.cc new file mode 100644 index 000000000000..ab50eaac09b8 --- /dev/null +++ b/components/content_settings/core/browser/brave_host_content_settings_map.cc @@ -0,0 +1,29 @@ +/* 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/. */ + +#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" + +#include "components/content_settings/core/common/content_settings_pattern.h" + +BraveHostContentSettingsMap::BraveHostContentSettingsMap( + PrefService* prefs, + bool is_incognito_profile, + bool is_guest_profile, + bool store_last_modified) + : HostContentSettingsMap(prefs, is_incognito_profile, is_guest_profile, + store_last_modified) { + InitializeFingerprintingContentSetting(); +} + +BraveHostContentSettingsMap::~BraveHostContentSettingsMap() { +} + +void BraveHostContentSettingsMap::InitializeFingerprintingContentSetting() { + SetContentSettingCustomScope( + ContentSettingsPattern::Wildcard(), + ContentSettingsPattern::FromString("https://firstParty/*"), + CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", + CONTENT_SETTING_ALLOW); +} diff --git a/components/content_settings/core/browser/brave_host_content_settings_map.h b/components/content_settings/core/browser/brave_host_content_settings_map.h new file mode 100644 index 000000000000..c39136f703d0 --- /dev/null +++ b/components/content_settings/core/browser/brave_host_content_settings_map.h @@ -0,0 +1,21 @@ +/* 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/. */ + +#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ +#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ + +#include "components/content_settings/core/browser/host_content_settings_map.h" + +class BraveHostContentSettingsMap : public HostContentSettingsMap { + public: + BraveHostContentSettingsMap(PrefService* prefs, + bool is_incognito_profile, + bool is_guest_profile, + bool store_last_modified); + private: + void InitializeFingerprintingContentSetting(); + ~BraveHostContentSettingsMap() override; +}; + +#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_ diff --git a/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch b/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch new file mode 100644 index 000000000000..7c1d5bcb5ea0 --- /dev/null +++ b/patches/chrome-browser-content_settings-host_content_settings_map_factory.cc.patch @@ -0,0 +1,21 @@ +diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc +index 7bb265a57ba4c03489743add26adaeea40a9fb06..3f6b1af25a0118ac2b6d388948f0dee49d32f78a 100644 +--- a/chrome/browser/content_settings/host_content_settings_map_factory.cc ++++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc +@@ -7,6 +7,7 @@ + #include + + #include "base/feature_list.h" ++#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h" + #include "chrome/browser/profiles/off_the_record_profile_impl.h" + #include "chrome/browser/profiles/profile.h" + #include "chrome/common/chrome_features.h" +@@ -81,7 +82,7 @@ scoped_refptr + + bool store_last_modified = base::FeatureList::IsEnabled(features::kTabsInCbd); + +- scoped_refptr settings_map(new HostContentSettingsMap( ++ scoped_refptr settings_map(new BraveHostContentSettingsMap( + profile->GetPrefs(), + profile->GetProfileType() == Profile::INCOGNITO_PROFILE, + profile->GetProfileType() == Profile::GUEST_PROFILE, diff --git a/patches/chrome-renderer-content_settings_observer.cc.patch b/patches/chrome-renderer-content_settings_observer.cc.patch deleted file mode 100644 index 571a919361f0..000000000000 --- a/patches/chrome-renderer-content_settings_observer.cc.patch +++ /dev/null @@ -1,27 +0,0 @@ -diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc -index f3947e48b3a67f534772366ce3ff45bdcc13eb39..c4b62d9087eb65a31085c61306de13eb70ecdce2 100644 ---- a/chrome/renderer/content_settings_observer.cc -+++ b/chrome/renderer/content_settings_observer.cc -@@ -71,10 +71,12 @@ GURL GetOriginOrURL(const WebFrame* frame) { - return top_origin.GetURL(); - } - -+} // namespace -+ - // Allow passing both WebURL and GURL here, so that we can early return without - // allocating a new backing string if only the default rule matches. - template --ContentSetting GetContentSettingFromRules( -+ContentSetting ContentSettingsObserver::GetContentSettingFromRules( - const ContentSettingsForOneType& rules, - const WebFrame* frame, - const URL& secondary_url) { -@@ -97,6 +99,8 @@ ContentSetting GetContentSettingFromRules( - return CONTENT_SETTING_DEFAULT; - } - -+namespace { -+ - bool IsScriptDisabledForPreview(const content::RenderFrame* render_frame) { - return render_frame->GetPreviewsState() & content::NOSCRIPT_ON; - } diff --git a/patches/chrome-renderer-content_settings_observer.h.patch b/patches/chrome-renderer-content_settings_observer.h.patch index 5704174b00ad..d9aff0365764 100644 --- a/patches/chrome-renderer-content_settings_observer.h.patch +++ b/patches/chrome-renderer-content_settings_observer.h.patch @@ -1,5 +1,5 @@ diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h -index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..6532c1de6fc3fbd0f88d6fdcd4ed3bfcd7528b6d 100644 +index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..249155b16e5faa0ef70d81c08377a4d3e0036fc2 100644 --- a/chrome/renderer/content_settings_observer.h +++ b/chrome/renderer/content_settings_observer.h @@ -103,6 +103,7 @@ class ContentSettingsObserver @@ -10,16 +10,3 @@ index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..6532c1de6fc3fbd0f88d6fdcd4ed3bfc FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverBrowserTest, ContentSettingsInterstitialPages); -@@ -149,6 +150,12 @@ class ContentSettingsObserver - const blink::WebSecurityOrigin& origin, - const blink::WebURL& document_url); - -+ template -+ ContentSetting GetContentSettingFromRules( -+ const ContentSettingsForOneType& rules, -+ const blink::WebFrame* frame, -+ const URL& secondary_url); -+ - #if BUILDFLAG(ENABLE_EXTENSIONS) - // Owned by ChromeContentRendererClient and outlive us. - extensions::Dispatcher* const extension_dispatcher_; diff --git a/patches/components-content_settings-core-browser-host_content_settings_map.h.patch b/patches/components-content_settings-core-browser-host_content_settings_map.h.patch new file mode 100644 index 000000000000..81f46869e774 --- /dev/null +++ b/patches/components-content_settings-core-browser-host_content_settings_map.h.patch @@ -0,0 +1,12 @@ +diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h +index 890e8959ae155618b78661dc8e97a81332d654f8..2a1f562e3b37ce85c3de48ea3f753c34c8586bbd 100644 +--- a/components/content_settings/core/browser/host_content_settings_map.h ++++ b/components/content_settings/core/browser/host_content_settings_map.h +@@ -303,6 +303,7 @@ class HostContentSettingsMap : public content_settings::Observer, + } + + private: ++ friend class BraveHostContentSettingsMap; + friend class base::RefCountedThreadSafe; + friend class content_settings::TestUtils; + diff --git a/renderer/brave_content_settings_observer.cc b/renderer/brave_content_settings_observer.cc index c1e41872157e..9cb820b94a22 100644 --- a/renderer/brave_content_settings_observer.cc +++ b/renderer/brave_content_settings_observer.cc @@ -6,6 +6,7 @@ #include "base/strings/utf_string_conversions.h" #include "brave/common/render_messages.h" +#include "components/content_settings/core/common/content_settings_pattern.h" #include "content/public/renderer/render_frame.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/WebKit/public/platform/WebURL.h" @@ -46,6 +47,45 @@ void BraveContentSettingsObserver::DidBlockFingerprinting( Send(new BraveViewHostMsg_FingerprintingBlocked(routing_id(), details)); } +GURL BraveContentSettingsObserver::GetOriginOrURL(const blink::WebFrame* frame) { + url::Origin top_origin = url::Origin(frame->Top()->GetSecurityOrigin()); + // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the + // document URL as the primary URL in those cases. + // TODO(alexmos): This is broken for --site-per-process, since top() can be a + // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's + // URL is not replicated. See https://crbug.com/628759. + if (top_origin.unique() && frame->Top()->IsWebLocalFrame()) + return frame->Top()->ToWebLocalFrame()->GetDocument().Url(); + return top_origin.GetURL(); +} + +ContentSetting BraveContentSettingsObserver::GetContentSettingFromRules( + const ContentSettingsForOneType& rules, + const blink::WebLocalFrame* frame, + const GURL& secondary_url) { + + const GURL& primary_url = GetOriginOrURL(frame); + + for (const auto& rule : rules) { + ContentSettingsPattern secondary_pattern = rule.secondary_pattern; + if (rule.secondary_pattern == + ContentSettingsPattern::FromString("https://firstParty/*")) { + secondary_pattern = ContentSettingsPattern::FromString( + "[*.]" + GetOriginOrURL(frame).HostNoBrackets()); + } + + if (rule.primary_pattern.Matches(primary_url) && + (secondary_pattern == ContentSettingsPattern::Wildcard() || + secondary_pattern.Matches(secondary_url))) { + return rule.GetContentSetting(); + } + } + + // for cases which are third party resources and doesn't match any existing + // rules, block them by default + return CONTENT_SETTING_BLOCK; +} + bool BraveContentSettingsObserver::AllowFingerprinting( bool enabled_per_settings) { if (!enabled_per_settings) diff --git a/renderer/brave_content_settings_observer.h b/renderer/brave_content_settings_observer.h index a17469ae8d66..88a362c717ad 100644 --- a/renderer/brave_content_settings_observer.h +++ b/renderer/brave_content_settings_observer.h @@ -7,8 +7,13 @@ #include "base/strings/string16.h" #include "chrome/renderer/content_settings_observer.h" +#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" +namespace blink { +class WebLocalFrame; +} + // Handles blocking content per content settings for each RenderFrame. class BraveContentSettingsObserver : public ContentSettingsObserver { @@ -31,6 +36,14 @@ class BraveContentSettingsObserver void DidBlockFingerprinting( const base::string16& details); + private: + GURL GetOriginOrURL(const blink::WebFrame* frame); + + ContentSetting GetContentSettingFromRules( + const ContentSettingsForOneType& rules, + const blink::WebLocalFrame* frame, + const GURL& secondary_url); + DISALLOW_COPY_AND_ASSIGN(BraveContentSettingsObserver); }; From fb4fdca51b4dbe155c134f62b7c28d4270d07000 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Thu, 29 Mar 2018 20:25:15 -0700 Subject: [PATCH 2/3] Add a browser test for 3rd party fingerprinting --- ...e_content_settings_observer_browsertest.cc | 208 ++++++++++++++++++ test/BUILD.gn | 1 + test/data/iframe.html | 4 + test/data/simple.html | 4 + 4 files changed, 217 insertions(+) create mode 100644 renderer/brave_content_settings_observer_browsertest.cc create mode 100644 test/data/iframe.html create mode 100644 test/data/simple.html diff --git a/renderer/brave_content_settings_observer_browsertest.cc b/renderer/brave_content_settings_observer_browsertest.cc new file mode 100644 index 000000000000..65a8477817ce --- /dev/null +++ b/renderer/brave_content_settings_observer_browsertest.cc @@ -0,0 +1,208 @@ +/* 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/. */ + +#include "base/path_service.h" +#include "brave/common/brave_paths.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/browser/render_frame_host.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/content_settings/core/common/content_settings.h" +#include "components/content_settings/core/common/content_settings_types.h" +#include "net/dns/mock_host_resolver.h" + +const char kIframeID[] = "test"; +const char kScript[] = + "var canvas = document.createElement('canvas');" + "var ctx = canvas.getContext('2d');" + "ctx.rect(10, 10, 100, 100);" + "ctx.stroke();" + "domAutomationController.send(ctx.isPointInPath(10, 10));"; + +class BraveContentSettingsObserverBrowserTest : public InProcessBrowserTest { + public: + void SetUpOnMainThread() override { + InProcessBrowserTest::SetUpOnMainThread(); + host_resolver()->AddRule("*", "127.0.0.1"); + content::SetupCrossSiteRedirector(embedded_test_server()); + + brave::RegisterPathProvider(); + base::FilePath test_data_dir; + PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); + embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + + ASSERT_TRUE(embedded_test_server()->Start()); + + url_ = embedded_test_server()->GetURL("a.com", "/iframe.html"); + iframe_url_ = embedded_test_server()->GetURL("b.com", "/simple.html"); + primary_pattern_ = ContentSettingsPattern::FromString("http://a.com/*"); + first_party_pattern_ = ContentSettingsPattern::FromString("https://firstParty/*"); + } + + const GURL& url() { return url_; } + const GURL& iframe_url() { return iframe_url_; } + + const ContentSettingsPattern& primary_pattern() { + return primary_pattern_; + } + + const ContentSettingsPattern& first_party_pattern() { + return first_party_pattern_; + } + private: + GURL url_; + GURL iframe_url_; + ContentSettingsPattern primary_pattern_; + ContentSettingsPattern first_party_pattern_; +}; + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsObserverBrowserTest, BlockThirdPartyFPByDefault) { + HostContentSettingsMap* content_settings = + HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + ContentSettingsForOneType fp_settings; + content_settings->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_PLUGINS, "fingerprinting", &fp_settings); + EXPECT_EQ(fp_settings.size(), 1u) << + "There should be one default fingerprinting rule."; + EXPECT_EQ(fp_settings[0].primary_pattern, ContentSettingsPattern::Wildcard()) << + "Primary pattern of default fingerprinting rule should be wildcard."; + EXPECT_EQ(fp_settings[0].secondary_pattern, first_party_pattern()) << + "Secondary pattern of default fingerprinting rule should be the special " + "first party pattern we defined."; + + ui_test_utils::NavigateToURL(browser(), url()); + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ASSERT_EQ(contents->GetAllFrames().size(), 2u) << + "Two frames (main + iframe) should be created."; + + content::RenderFrameHost* main_frame = contents->GetMainFrame(); + content::RenderFrameHost* child_frame = + ChildFrameAt(contents->GetMainFrame(), 0); + EXPECT_EQ(main_frame->GetLastCommittedURL(), url()); + + bool isPointInPath; + EXPECT_TRUE(ExecuteScriptAndExtractBool(contents, kScript, &isPointInPath)); + EXPECT_TRUE(isPointInPath); + + EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url())); + EXPECT_EQ(child_frame->GetLastCommittedURL(), iframe_url()); + EXPECT_TRUE(ExecuteScriptAndExtractBool( + child_frame, kScript, &isPointInPath)); + EXPECT_FALSE(isPointInPath); +} + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsObserverBrowserTest, BlockFP) { + HostContentSettingsMap* content_settings = + HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + content_settings->SetContentSettingCustomScope(primary_pattern(), + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_BLOCK); + content_settings->SetContentSettingCustomScope(primary_pattern(), + first_party_pattern(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_BLOCK); + + ContentSettingsForOneType fp_settings; + content_settings->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_PLUGINS, "fingerprinting", &fp_settings); + EXPECT_EQ(fp_settings.size(), 3u); + + ui_test_utils::NavigateToURL(browser(), url()); + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ASSERT_EQ(contents->GetAllFrames().size(), 2u) << + "Two frames (main + iframe) should be created."; + + content::RenderFrameHost* main_frame = contents->GetMainFrame(); + content::RenderFrameHost* child_frame = + ChildFrameAt(contents->GetMainFrame(), 0); + EXPECT_EQ(main_frame->GetLastCommittedURL(), url()); + + bool isPointInPath; + EXPECT_TRUE(ExecuteScriptAndExtractBool(contents, kScript, &isPointInPath)); + EXPECT_FALSE(isPointInPath); + + EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url())); + EXPECT_EQ(child_frame->GetLastCommittedURL(), iframe_url()); + EXPECT_TRUE(ExecuteScriptAndExtractBool( + child_frame, kScript, &isPointInPath)); + EXPECT_FALSE(isPointInPath); +} + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsObserverBrowserTest, AllowFP) { + HostContentSettingsMap* content_settings = + HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + content_settings->SetContentSettingCustomScope(primary_pattern(), + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_ALLOW); + content_settings->SetContentSettingCustomScope(primary_pattern(), + first_party_pattern(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_ALLOW); + + ContentSettingsForOneType fp_settings; + content_settings->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_PLUGINS, "fingerprinting", &fp_settings); + EXPECT_EQ(fp_settings.size(), 3u); + + ui_test_utils::NavigateToURL(browser(), url()); + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ASSERT_EQ(contents->GetAllFrames().size(), 2u) << + "Two frames (main + iframe) should be created."; + + content::RenderFrameHost* main_frame = contents->GetMainFrame(); + content::RenderFrameHost* child_frame = + ChildFrameAt(contents->GetMainFrame(), 0); + EXPECT_EQ(main_frame->GetLastCommittedURL(), url()); + + bool isPointInPath; + EXPECT_TRUE(ExecuteScriptAndExtractBool(contents, kScript, &isPointInPath)); + EXPECT_TRUE(isPointInPath); + + EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url())); + EXPECT_EQ(child_frame->GetLastCommittedURL(), iframe_url()); + EXPECT_TRUE(ExecuteScriptAndExtractBool( + child_frame, kScript, &isPointInPath)); + EXPECT_TRUE(isPointInPath); +} + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsObserverBrowserTest, BlockThirdPartyFP) { + HostContentSettingsMap* content_settings = + HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + content_settings->SetContentSettingCustomScope(primary_pattern(), + ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_BLOCK); + content_settings->SetContentSettingCustomScope(primary_pattern(), + first_party_pattern(), CONTENT_SETTINGS_TYPE_PLUGINS, + "fingerprinting", CONTENT_SETTING_ALLOW); + + ContentSettingsForOneType fp_settings; + content_settings->GetSettingsForOneType( + CONTENT_SETTINGS_TYPE_PLUGINS, "fingerprinting", &fp_settings); + EXPECT_EQ(fp_settings.size(), 3u); + + ui_test_utils::NavigateToURL(browser(), url()); + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ASSERT_EQ(contents->GetAllFrames().size(), 2u) << + "Two frames (main + iframe) should be created."; + + content::RenderFrameHost* main_frame = contents->GetMainFrame(); + content::RenderFrameHost* child_frame = + ChildFrameAt(contents->GetMainFrame(), 0); + EXPECT_EQ(main_frame->GetLastCommittedURL(), url()); + + bool isPointInPath; + EXPECT_TRUE(ExecuteScriptAndExtractBool(contents, kScript, &isPointInPath)); + EXPECT_TRUE(isPointInPath); + + EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url())); + EXPECT_EQ(child_frame->GetLastCommittedURL(), iframe_url()); + EXPECT_TRUE(ExecuteScriptAndExtractBool( + child_frame, kScript, &isPointInPath)); + EXPECT_FALSE(isPointInPath); +} diff --git a/test/BUILD.gn b/test/BUILD.gn index dd09c4ae3ee4..2437cb424197 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -67,6 +67,7 @@ test("brave_browser_tests") { sources = [ "//brave/components/brave_shields/browser/ad_block_service_browsertest.cc", "//brave/components/brave_shields/browser/https_everywhere_service_browsertest.cc", + "//brave/renderer/brave_content_settings_observer_browsertest.cc", ] defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] deps = [ diff --git a/test/data/iframe.html b/test/data/iframe.html new file mode 100644 index 000000000000..7b5a1e082264 --- /dev/null +++ b/test/data/iframe.html @@ -0,0 +1,4 @@ +iframe test + + + diff --git a/test/data/simple.html b/test/data/simple.html new file mode 100644 index 000000000000..70db0f23c52f --- /dev/null +++ b/test/data/simple.html @@ -0,0 +1,4 @@ + +OK + + From 1fda5a030dffbe924eeff0fa98bd33b0e899c940 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Thu, 5 Apr 2018 12:02:58 -0700 Subject: [PATCH 3/3] Update brave-extension DEPS --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index e6e8e50b6e6a..394002c60a33 100644 --- a/DEPS +++ b/DEPS @@ -5,7 +5,7 @@ deps = { "vendor/tracking-protection": "https://github.com/brave/tracking-protection.git@051177425a14121a22087d754ad8eb1c0ce8fb24", "vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@67ffffa69b56e330bab9d08f050727f891c916a1", "vendor/bloom-filter-cpp": "https://github.com/brave/bloom-filter-cpp.git@d511cf872ea1d650ab8dc4662f6036dac012d197", - "vendor/brave-extension": "https://github.com/brave/brave-extension.git@fd3d4a7b9fc206649d504b8616f095ff9376d03a", + "vendor/brave-extension": "https://github.com/brave/brave-extension.git@6b9e384a74e8be2b1cea8c88e3c25e41e5d8a194", "vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458", "vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b", "vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",