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

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

Issue 2350913002: [HBD] Improve Flash Interception unit tests (Closed)
Patch Set: Merge branch 'refs/heads/276-hbd-intercept-creating-new-windows' into 278-hbd-update-intercept-tests Created 4 years, 3 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
« no previous file with comments | « chrome/browser/plugins/flash_download_interception.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h" 12 #include "components/content_settings/core/browser/host_content_settings_map.h"
13 #include "content/public/browser/navigation_handle.h" 13 #include "content/public/browser/navigation_handle.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 using content::NavigationHandle; 17 using content::NavigationHandle;
18 using content::NavigationThrottle; 18 using content::NavigationThrottle;
19 19
20 class FlashDownloadInterceptionTest : public ChromeRenderViewHostTestHarness { 20 class FlashDownloadInterceptionTest : public ChromeRenderViewHostTestHarness {
21 public: 21 public:
22 FlashDownloadInterceptionTest() {} 22 HostContentSettingsMap* host_content_settings_map() {
23 23 return HostContentSettingsMapFactory::GetForProfile(profile());
24 void SetUp() override {
25 ChromeRenderViewHostTestHarness::SetUp();
26 flash_navigation_handle_ =
27 NavigationHandle::CreateNavigationHandleForTesting(
28 GURL("https://get.adobe.com/flashplayer"), main_rfh());
29 } 24 }
30
31 void TearDown() override {
32 flash_navigation_handle_.reset();
33 ChromeRenderViewHostTestHarness::TearDown();
34 }
35
36 protected:
37 std::unique_ptr<NavigationHandle> flash_navigation_handle_;
38 }; 25 };
39 26
40 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) { 27 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) {
41 base::test::ScopedFeatureList feature_list; 28 base::test::ScopedFeatureList feature_list;
42 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); 29 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins);
43 30
44 flash_navigation_handle_->CallWillStartRequestForTesting( 31 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
45 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); 32 host_content_settings_map(), GURL(),
46 std::unique_ptr<NavigationThrottle> throttle = 33 GURL("https://get.adobe.com/flashplayer/"), true));
47 FlashDownloadInterception::MaybeCreateThrottleFor(
48 flash_navigation_handle_.get());
49 EXPECT_EQ(nullptr, throttle);
50 } 34 }
51 35
52 TEST_F(FlashDownloadInterceptionTest, DownloadUrlVariations) { 36 TEST_F(FlashDownloadInterceptionTest, DownloadUrlVariations) {
53 std::unique_ptr<NavigationThrottle> throttle;
54 std::unique_ptr<NavigationHandle> flash_slash_navigation_handle =
55 NavigationHandle::CreateNavigationHandleForTesting(
56 GURL("https://get.adobe.com/flashplayer/"), main_rfh());
57 std::unique_ptr<NavigationHandle> example_navigation_handle =
58 NavigationHandle::CreateNavigationHandleForTesting(
59 GURL("https://www.example.com"), main_rfh());
60 std::unique_ptr<NavigationHandle> flash_http_navigation_handle =
61 NavigationHandle::CreateNavigationHandleForTesting(
62 GURL("http://get.adobe.com/flashplayer"), main_rfh());
63 std::unique_ptr<NavigationHandle> example_flash_navigation_handle =
64 NavigationHandle::CreateNavigationHandleForTesting(
65 GURL("http://example.com/get.adobe.com/flashplayer"), main_rfh());
66
67 base::test::ScopedFeatureList feature_list; 37 base::test::ScopedFeatureList feature_list;
68 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 38 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
69 39
70 flash_navigation_handle_->CallWillStartRequestForTesting( 40 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
71 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); 41 host_content_settings_map(), GURL(),
72 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( 42 GURL("https://get.adobe.com/flashplayer/"), true));
73 flash_navigation_handle_.get());
74 EXPECT_EQ(nullptr, throttle);
75 43
76 flash_navigation_handle_->CallWillStartRequestForTesting( 44 // HTTP and path variant.
77 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); 45 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
78 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( 46 host_content_settings_map(), GURL(), GURL("http://get.adobe.com/flash"),
79 flash_navigation_handle_.get()); 47 true));
48
49 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
50 host_content_settings_map(), GURL(), GURL("https://www.example.com"),
51 true));
52
53 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
54 host_content_settings_map(), GURL(),
55 GURL("http://example.com/get.adobe.com/flashplayer"), true));
56 }
57
58 TEST_F(FlashDownloadInterceptionTest, NavigationThrottleCancelsNavigation) {
59 base::test::ScopedFeatureList feature_list;
60 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
61
62 std::unique_ptr<NavigationHandle> handle =
63 NavigationHandle::CreateNavigationHandleForTesting(
64 GURL("https://get.adobe.com/flashplayer"), main_rfh());
65
66 handle->CallWillStartRequestForTesting(true, content::Referrer(), true,
67 ui::PAGE_TRANSITION_LINK, false);
68 std::unique_ptr<NavigationThrottle> throttle =
69 FlashDownloadInterception::MaybeCreateThrottleFor(handle.get());
80 EXPECT_NE(nullptr, throttle); 70 EXPECT_NE(nullptr, throttle);
81 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, 71 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
82 throttle->WillStartRequest()); 72 throttle->WillStartRequest());
83
84 flash_slash_navigation_handle->CallWillStartRequestForTesting(
85 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
86 throttle = FlashDownloadInterception::MaybeCreateThrottleFor(
87 flash_slash_navigation_handle.get());
88 EXPECT_NE(nullptr, throttle);
89 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
90 throttle->WillStartRequest());
91
92 example_navigation_handle->CallWillStartRequestForTesting(
93 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
94 throttle = FlashDownloadInterception::MaybeCreateThrottleFor(
95 example_navigation_handle.get());
96 EXPECT_EQ(nullptr, throttle);
97
98 flash_http_navigation_handle->CallWillStartRequestForTesting(
99 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
100 throttle = FlashDownloadInterception::MaybeCreateThrottleFor(
101 flash_http_navigation_handle.get());
102 EXPECT_NE(nullptr, throttle);
103 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
104 throttle->WillStartRequest());
105
106 example_flash_navigation_handle->CallWillStartRequestForTesting(
107 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
108 throttle = FlashDownloadInterception::MaybeCreateThrottleFor(
109 example_flash_navigation_handle.get());
110 EXPECT_EQ(nullptr, throttle);
111 } 73 }
112 74
113 TEST_F(FlashDownloadInterceptionTest, OnlyInterceptOnDetectContentSetting) { 75 TEST_F(FlashDownloadInterceptionTest, OnlyInterceptOnDetectContentSetting) {
114 base::test::ScopedFeatureList feature_list; 76 base::test::ScopedFeatureList feature_list;
115 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 77 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
116 78
117 flash_navigation_handle_->CallWillStartRequestForTesting(
118 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false);
119
120 // Default Setting (which is DETECT) 79 // Default Setting (which is DETECT)
121 std::unique_ptr<NavigationThrottle> throttle = 80 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
122 FlashDownloadInterception::MaybeCreateThrottleFor( 81 host_content_settings_map(), GURL(),
123 flash_navigation_handle_.get()); 82 GURL("https://get.adobe.com/flashplayer/"), true));
124 EXPECT_NE(nullptr, throttle);
125 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
126 throttle->WillStartRequest());
127 83
128 // ALLOW and BLOCK Settings 84 // ALLOW and BLOCK Settings
129 HostContentSettingsMap* map = 85 HostContentSettingsMap* map =
130 HostContentSettingsMapFactory::GetForProfile(profile()); 86 HostContentSettingsMapFactory::GetForProfile(profile());
131 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 87 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
132 CONTENT_SETTING_ALLOW); 88 CONTENT_SETTING_ALLOW);
133 EXPECT_EQ(nullptr, FlashDownloadInterception::MaybeCreateThrottleFor( 89 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
134 flash_navigation_handle_.get())); 90 host_content_settings_map(), GURL(),
91 GURL("https://get.adobe.com/flashplayer/"), true));
135 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 92 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
136 CONTENT_SETTING_BLOCK); 93 CONTENT_SETTING_BLOCK);
137 EXPECT_EQ(nullptr, FlashDownloadInterception::MaybeCreateThrottleFor( 94 EXPECT_FALSE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
138 flash_navigation_handle_.get())); 95 host_content_settings_map(), GURL(),
96 GURL("https://get.adobe.com/flashplayer/"), true));
139 97
140 // Explicit DETECT 98 // Explicit DETECT
141 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 99 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
142 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 100 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
143 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( 101 EXPECT_TRUE(FlashDownloadInterception::ShouldStopFlashDownloadAction(
144 flash_navigation_handle_.get()); 102 host_content_settings_map(), GURL(),
145 EXPECT_NE(nullptr, throttle); 103 GURL("https://get.adobe.com/flashplayer/"), true));
146 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE,
147 throttle->WillStartRequest());
148 } 104 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/flash_download_interception.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698