Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/plugins/flash_download_interception_unittest.cc

Issue 2378573005: [HBD] Blanket BLOCK on all non-HTTP(s) and non-FILE URLs for Flash. (Closed)
Patch Set: fix dat merge Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/plugins/flash_download_interception.h" 5 #include "chrome/browser/plugins/flash_download_interception.h"
6 6
7 #include "base/test/scoped_feature_list.h" 7 #include "base/test/scoped_feature_list.h"
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/common/chrome_features.h" 9 #include "chrome/common/chrome_features.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
(...skipping 11 matching lines...) Expand all
22 HostContentSettingsMap* host_content_settings_map() { 22 HostContentSettingsMap* host_content_settings_map() {
23 return HostContentSettingsMapFactory::GetForProfile(profile()); 23 return HostContentSettingsMapFactory::GetForProfile(profile());
24 } 24 }
25 }; 25 };
26 26
27 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) { 27 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) {
28 base::test::ScopedFeatureList feature_list; 28 base::test::ScopedFeatureList feature_list;
29 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); 29 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins);
30 30
31 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 31 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
32 host_content_settings_map(), GURL(), 32 host_content_settings_map(), GURL("http://source-page.com"),
33 GURL("https://get.adobe.com/flashplayer/"), true)); 33 GURL("https://get.adobe.com/flashplayer/"), true));
34 } 34 }
35 35
36 TEST_F(FlashDownloadInterceptionTest, DownloadUrlVariations) { 36 TEST_F(FlashDownloadInterceptionTest, DownloadUrlVariations) {
37 base::test::ScopedFeatureList feature_list; 37 base::test::ScopedFeatureList feature_list;
38 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 38 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
39 39
40 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 40 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
41 host_content_settings_map(), GURL(), 41 host_content_settings_map(), GURL("http://source-page.com"),
42 GURL("https://get.adobe.com/flashplayer/"), true)); 42 GURL("https://get.adobe.com/flashplayer/"), true));
43 43
44 // HTTP and path variant. 44 // HTTP and path variant.
45 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 45 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
46 host_content_settings_map(), GURL(), GURL("http://get.adobe.com/flash"), 46 host_content_settings_map(), GURL("http://source-page.com"),
47 true)); 47 GURL("http://get.adobe.com/flash"), true));
48 48
49 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 49 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
50 host_content_settings_map(), GURL(), GURL("https://www.example.com"), 50 host_content_settings_map(), GURL("http://source-page.com"),
51 true)); 51 GURL("https://www.example.com"), true));
52 52
53 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 53 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
54 host_content_settings_map(), GURL(), 54 host_content_settings_map(), GURL("http://source-page.com"),
55 GURL("http://example.com/get.adobe.com/flashplayer"), true)); 55 GURL("http://example.com/get.adobe.com/flashplayer"), true));
56 } 56 }
57 57
58 TEST_F(FlashDownloadInterceptionTest, NavigationThrottleCancelsNavigation) { 58 TEST_F(FlashDownloadInterceptionTest, NavigationThrottleCancelsNavigation) {
59 base::test::ScopedFeatureList feature_list; 59 base::test::ScopedFeatureList feature_list;
60 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 60 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
61 61
62 // Set the source URL to an HTTP source.
63 NavigateAndCommit(GURL("http://example.com"));
64
62 std::unique_ptr<NavigationHandle> handle = 65 std::unique_ptr<NavigationHandle> handle =
63 NavigationHandle::CreateNavigationHandleForTesting( 66 NavigationHandle::CreateNavigationHandleForTesting(
64 GURL("https://get.adobe.com/flashplayer"), main_rfh()); 67 GURL("https://get.adobe.com/flashplayer"), main_rfh());
65 68
66 handle->CallWillStartRequestForTesting(true, content::Referrer(), true, 69 handle->CallWillStartRequestForTesting(true, content::Referrer(), true,
67 ui::PAGE_TRANSITION_LINK, false); 70 ui::PAGE_TRANSITION_LINK, false);
68 std::unique_ptr<NavigationThrottle> throttle = 71 std::unique_ptr<NavigationThrottle> throttle =
69 FlashDownloadInterception::MaybeCreateThrottleFor(handle.get()); 72 FlashDownloadInterception::MaybeCreateThrottleFor(handle.get());
70 EXPECT_NE(nullptr, throttle); 73 EXPECT_NE(nullptr, throttle);
71 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, 74 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
72 throttle->WillStartRequest()); 75 throttle->WillStartRequest());
73 } 76 }
74 77
75 TEST_F(FlashDownloadInterceptionTest, OnlyInterceptOnDetectContentSetting) { 78 TEST_F(FlashDownloadInterceptionTest, OnlyInterceptOnDetectContentSetting) {
76 base::test::ScopedFeatureList feature_list; 79 base::test::ScopedFeatureList feature_list;
77 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 80 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
78 81
79 // Default Setting (which is DETECT) 82 // Default Setting (which is DETECT)
80 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 83 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
81 host_content_settings_map(), GURL(), 84 host_content_settings_map(), GURL("http://source-page.com"),
82 GURL("https://get.adobe.com/flashplayer/"), true)); 85 GURL("https://get.adobe.com/flashplayer/"), true));
83 86
84 // No intercept on ALLOW. 87 // No intercept on ALLOW.
85 HostContentSettingsMap* map = 88 HostContentSettingsMap* map =
86 HostContentSettingsMapFactory::GetForProfile(profile()); 89 HostContentSettingsMapFactory::GetForProfile(profile());
87 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 90 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
88 CONTENT_SETTING_ALLOW); 91 CONTENT_SETTING_ALLOW);
89 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 92 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
90 host_content_settings_map(), GURL(), 93 host_content_settings_map(), GURL("http://source-page.com"),
91 GURL("https://get.adobe.com/flashplayer/"), true)); 94 GURL("https://get.adobe.com/flashplayer/"), true));
92 95
93 // Intercept on both explicit DETECT and BLOCK. 96 // Intercept on both explicit DETECT and BLOCK.
94 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 97 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
95 CONTENT_SETTING_BLOCK); 98 CONTENT_SETTING_BLOCK);
96 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 99 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
97 host_content_settings_map(), GURL(), 100 host_content_settings_map(), GURL("http://source-page.com"),
98 GURL("https://get.adobe.com/flashplayer/"), true)); 101 GURL("https://get.adobe.com/flashplayer/"), true));
99 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 102 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
100 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 103 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
101 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction( 104 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
102 host_content_settings_map(), GURL(), 105 host_content_settings_map(), GURL("http://source-page.com"),
103 GURL("https://get.adobe.com/flashplayer/"), true)); 106 GURL("https://get.adobe.com/flashplayer/"), true));
104 } 107 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/flash_download_interception.cc ('k') | chrome/browser/plugins/flash_permission_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698