| 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 flash_slash_navigation_handle_ = |
| 27 NavigationHandle::CreateNavigationHandleForTesting( |
| 28 GURL("https://get.adobe.com/flashplayer/"), main_rfh()); |
| 29 example_navigation_handle_ = |
| 30 NavigationHandle::CreateNavigationHandleForTesting( |
| 31 GURL("https://www.example.com"), main_rfh()); |
| 32 |
| 33 // Changes the status of the navigation handles. This is needed because |
| 34 // the NavigationHandle's status needs to be different from INITIAL so that |
| 35 // the HasUserGesture method can be used. |
| 36 flash_navigation_handle_->CallWillProcessResponseForTesting(main_rfh()); |
| 37 flash_slash_navigation_handle_->CallWillProcessResponseForTesting( |
| 38 main_rfh()); |
| 39 example_navigation_handle_->CallWillProcessResponseForTesting(main_rfh()); |
| 40 } |
| 41 |
| 42 void TearDown() override { |
| 43 flash_navigation_handle_.reset(); |
| 44 flash_slash_navigation_handle_.reset(); |
| 45 example_navigation_handle_.reset(); |
| 46 ChromeRenderViewHostTestHarness::TearDown(); |
| 47 } |
| 48 |
| 49 protected: |
| 50 std::unique_ptr<NavigationHandle> flash_navigation_handle_; |
| 51 std::unique_ptr<NavigationHandle> flash_slash_navigation_handle_; |
| 52 std::unique_ptr<NavigationHandle> example_navigation_handle_; |
| 53 }; |
| 54 |
| 55 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOff) { |
| 56 base::test::ScopedFeatureList feature_list; |
| 57 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); |
| 58 |
| 59 flash_navigation_handle_->SetHasUserGestureForTesting(true); |
| 60 std::unique_ptr<NavigationThrottle> throttle = |
| 61 FlashDownloadInterception::MaybeCreateThrottleFor( |
| 62 flash_navigation_handle_.get()); |
| 63 EXPECT_EQ(nullptr, throttle); |
| 64 } |
| 65 |
| 66 TEST_F(FlashDownloadInterceptionTest, PreferHtmlOverPluginsOn) { |
| 67 std::unique_ptr<NavigationThrottle> throttle; |
| 68 base::test::ScopedFeatureList feature_list; |
| 69 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 70 |
| 71 flash_navigation_handle_->SetHasUserGestureForTesting(false); |
| 72 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 73 flash_navigation_handle_.get()); |
| 74 EXPECT_EQ(nullptr, throttle); |
| 75 |
| 76 flash_navigation_handle_->SetHasUserGestureForTesting(true); |
| 77 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 78 flash_navigation_handle_.get()); |
| 79 EXPECT_NE(nullptr, throttle); |
| 80 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, |
| 81 throttle->WillStartRequest()); |
| 82 |
| 83 flash_slash_navigation_handle_->SetHasUserGestureForTesting(true); |
| 84 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 85 flash_navigation_handle_.get()); |
| 86 EXPECT_NE(nullptr, throttle); |
| 87 ASSERT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, |
| 88 throttle->WillStartRequest()); |
| 89 |
| 90 example_navigation_handle_->SetHasUserGestureForTesting(true); |
| 91 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( |
| 92 example_navigation_handle_.get()); |
| 93 EXPECT_EQ(nullptr, throttle); |
| 94 } |
| OLD | NEW |