Chromium Code Reviews| 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 | |
| 22 TEST_F(FlashDownloadInterceptionTest, MaybeCreateThrottleFor) { | |
| 23 std::unique_ptr<NavigationThrottle> throttle; | |
|
tommycli
2016/09/01 01:08:20
If you split up the two cases below, these common
trizzofo
2016/09/01 01:56:14
Done.
| |
| 24 std::unique_ptr<NavigationHandle> flash_navigation_handle_ = | |
| 25 NavigationHandle::CreateNavigationHandleForTesting( | |
| 26 GURL("https://get.adobe.com/flashplayer"), main_rfh()); | |
| 27 std::unique_ptr<NavigationHandle> flash_slash_navigation_handle_ = | |
| 28 NavigationHandle::CreateNavigationHandleForTesting( | |
| 29 GURL("https://get.adobe.com/flashplayer/"), main_rfh()); | |
| 30 std::unique_ptr<NavigationHandle> example_navigation_handle_ = | |
| 31 NavigationHandle::CreateNavigationHandleForTesting( | |
| 32 GURL("https://www.example.com"), main_rfh()); | |
| 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(main_rfh()); | |
| 38 example_navigation_handle_->CallWillProcessResponseForTesting(main_rfh()); | |
| 39 | |
| 40 { | |
|
tommycli
2016/09/01 01:08:20
These scoped portions suggest to me it should be d
trizzofo
2016/09/01 01:56:14
Done.
| |
| 41 base::test::ScopedFeatureList feature_list; | |
| 42 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); | |
| 43 | |
| 44 flash_navigation_handle_->SetHasUserGestureForTesting(true); | |
| 45 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( | |
| 46 flash_navigation_handle_.get()); | |
| 47 EXPECT_EQ(nullptr, throttle); | |
| 48 } | |
| 49 | |
| 50 { | |
| 51 base::test::ScopedFeatureList feature_list; | |
| 52 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | |
| 53 | |
| 54 flash_navigation_handle_->SetHasUserGestureForTesting(false); | |
| 55 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( | |
| 56 flash_navigation_handle_.get()); | |
| 57 EXPECT_EQ(nullptr, throttle); | |
| 58 | |
| 59 flash_navigation_handle_->SetHasUserGestureForTesting(true); | |
| 60 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( | |
| 61 flash_navigation_handle_.get()); | |
| 62 EXPECT_NE(nullptr, throttle); | |
|
tommycli
2016/09/01 01:08:20
To give this test a bit more teeth in the non-null
trizzofo
2016/09/01 17:58:56
Done.
| |
| 63 | |
| 64 flash_slash_navigation_handle_->SetHasUserGestureForTesting(true); | |
| 65 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( | |
| 66 flash_navigation_handle_.get()); | |
| 67 EXPECT_NE(nullptr, throttle); | |
| 68 | |
| 69 example_navigation_handle_->SetHasUserGestureForTesting(true); | |
| 70 throttle = FlashDownloadInterception::MaybeCreateThrottleFor( | |
| 71 example_navigation_handle_.get()); | |
| 72 EXPECT_EQ(nullptr, throttle); | |
| 73 } | |
| 74 } | |
| OLD | NEW |