| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/plugins/flash_download_interception.h" |
| 6 |
| 7 #include "base/test/scoped_feature_list.h" |
| 8 #include "chrome/common/chrome_features.h" |
| 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 10 #include "content/public/browser/navigation_handle.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 using content::NavigationHandle; |
| 15 using content::NavigationThrottle; |
| 16 |
| 17 class FlashDownloadInterceptionTest : public ChromeRenderViewHostTestHarness { |
| 18 public: |
| 19 FlashDownloadInterceptionTest() {} |
| 20 |
| 21 void SetUp() override { |
| 22 ChromeRenderViewHostTestHarness::SetUp(); |
| 23 flash_navigation_handle_ = |
| 24 NavigationHandle::CreateNavigationHandleForTesting( |
| 25 GURL("https://get.adobe.com/flashplayer"), main_rfh()); |
| 26 } |
| 27 |
| 28 void TearDown() override { |
| 29 flash_navigation_handle_.reset(); |
| 30 ChromeRenderViewHostTestHarness::TearDown(); |
| 31 } |
| 32 |
| 33 protected: |
| 34 std::unique_ptr<NavigationHandle> flash_navigation_handle_; |
| 35 }; |
| 36 |
| 37 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) { |
| 38 base::test::ScopedFeatureList feature_list; |
| 39 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); |
| 40 |
| 41 flash_navigation_handle_->CallWillStartRequestForTesting( |
| 42 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 43 std::unique_ptr<NavigationThrottle> throttle = |
| 44 FlashDownloadInterception::MaybeCreateThrottleFor( |
| 45 flash_navigation_handle_.get()); |
| 46 EXPECT_EQ(nullptr, throttle); |
| 47 } |
| 48 |
| 49 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOn) { |
| 50 std::unique_ptr<NavigationThrottle> throttle; |
| 51 std::unique_ptr<NavigationHandle> flash_slash_navigation_handle = |
| 52 NavigationHandle::CreateNavigationHandleForTesting( |
| 53 GURL("https://get.adobe.com/flashplayer/"), main_rfh()); |
| 54 std::unique_ptr<NavigationHandle> example_navigation_handle = |
| 55 NavigationHandle::CreateNavigationHandleForTesting( |
| 56 GURL("https://www.example.com"), main_rfh()); |
| 57 std::unique_ptr<NavigationHandle> flash_http_navigation_handle = |
| 58 NavigationHandle::CreateNavigationHandleForTesting( |
| 59 GURL("http://get.adobe.com/flashplayer"), main_rfh()); |
| 60 std::unique_ptr<NavigationHandle> example_flash_navigation_handle = |
| 61 NavigationHandle::CreateNavigationHandleForTesting( |
| 62 GURL("http://example.com/get.adobe.com/flashplayer"), main_rfh()); |
| 63 |
| 64 base::test::ScopedFeatureList feature_list; |
| 65 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 66 |
| 67 flash_navigation_handle_->CallWillStartRequestForTesting( |
| 68 true, content::Referrer(), false, ui::PAGE_TRANSITION_LINK, false); |
| 69 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 70 flash_navigation_handle_.get()); |
| 71 EXPECT_EQ(nullptr, throttle); |
| 72 |
| 73 flash_navigation_handle_->CallWillStartRequestForTesting( |
| 74 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 75 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 76 flash_navigation_handle_.get()); |
| 77 EXPECT_NE(nullptr, throttle); |
| 78 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, |
| 79 throttle->WillStartRequest()); |
| 80 |
| 81 flash_slash_navigation_handle->CallWillStartRequestForTesting( |
| 82 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 83 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 84 flash_slash_navigation_handle.get()); |
| 85 EXPECT_NE(nullptr, throttle); |
| 86 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, |
| 87 throttle->WillStartRequest()); |
| 88 |
| 89 example_navigation_handle->CallWillStartRequestForTesting( |
| 90 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 91 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 92 example_navigation_handle.get()); |
| 93 EXPECT_EQ(nullptr, throttle); |
| 94 |
| 95 flash_http_navigation_handle->CallWillStartRequestForTesting( |
| 96 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 97 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 98 flash_http_navigation_handle.get()); |
| 99 EXPECT_NE(nullptr, throttle); |
| 100 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, |
| 101 throttle->WillStartRequest()); |
| 102 |
| 103 example_flash_navigation_handle->CallWillStartRequestForTesting( |
| 104 true, content::Referrer(), true, ui::PAGE_TRANSITION_LINK, false); |
| 105 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 106 example_flash_navigation_handle.get()); |
| 107 EXPECT_EQ(nullptr, throttle); |
| 108 } |
| OLD | NEW |