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

Unified Diff: chrome/browser/extensions/extension_navigation_throttle_unittest.cc

Issue 2881733006: ExtensionNavigationThrottle: Enforce the same rules on redirect as we (Closed)
Patch Set: Fix compile. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_resource_request_policy_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_navigation_throttle_unittest.cc
diff --git a/chrome/browser/extensions/extension_navigation_throttle_unittest.cc b/chrome/browser/extensions/extension_navigation_throttle_unittest.cc
index 35a546bc2a0bef1734d17c771b2f89279e7c6c50..ac2fcee7374df40d27d350c96c75cf96c38ffcb7 100644
--- a/chrome/browser/extensions/extension_navigation_throttle_unittest.cc
+++ b/chrome/browser/extensions/extension_navigation_throttle_unittest.cc
@@ -62,19 +62,50 @@ class ExtensionNavigationThrottleUnitTest
ChromeRenderViewHostTestHarness::TearDown();
}
- // Checks that trying to navigate the given |host| to |url| results in the
- // |expected_result|.
- void CheckTestCase(content::RenderFrameHost* host,
- const GURL& url,
- NavigationThrottle::ThrottleCheckResult expected_result) {
+ // Checks that trying to navigate the given |host| to |extension_url| results
+ // in the |expected_will_start_result|, and also that navigating to
+ // |extension_url| via http redirect will cancel the request unless
+ // |expected_will_start_result| is PROCEED.
+ void CheckTestCase(
+ content::RenderFrameHost* host,
+ const GURL& extension_url,
+ NavigationThrottle::ThrottleCheckResult expected_will_start_result) {
+ // First subtest: direct navigation to |extension_url|.
std::unique_ptr<content::NavigationHandle> handle =
- content::NavigationHandle::CreateNavigationHandleForTesting(url, host);
- EXPECT_EQ(expected_result,
+ content::NavigationHandle::CreateNavigationHandleForTesting(
+ extension_url, host);
+ EXPECT_EQ(expected_will_start_result,
handle->CallWillStartRequestForTesting(
/*is_post=*/false, content::Referrer(),
/*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK,
/*is_external_protocol=*/false))
- << url;
+ << extension_url;
+
+ // Reset the handle for a second subtest: server redirect to
+ // |extension_url|.
+ GURL http_url("https://example.com");
+ handle = content::NavigationHandle::CreateNavigationHandleForTesting(
+ http_url, host);
+
+ // TODO(nick): https://crbug.com/695421 Once PlzNavigate is enabled 100%, it
+ // should be possible to support return values other than PROCEED and CANCEL
+ // from ExtensionNavigationThrottle::WillRedirectRequest.
+ NavigationThrottle::ThrottleCheckResult expected_will_redirect_result =
+ (expected_will_start_result == NavigationThrottle::PROCEED)
+ ? NavigationThrottle::PROCEED
+ : NavigationThrottle::CANCEL;
+ EXPECT_EQ(NavigationThrottle::PROCEED,
+ handle->CallWillStartRequestForTesting(
+ /*is_post=*/false, content::Referrer(),
+ /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK,
+ /*is_external_protocol=*/false))
+ << http_url;
+ EXPECT_EQ(expected_will_redirect_result,
+ handle->CallWillRedirectRequestForTesting(
+ extension_url,
+ /*new_method_is_post=*/false, http_url,
+ /*new_is_external_protocol=*/false))
+ << extension_url;
}
const Extension* extension() { return extension_.get(); }
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_resource_request_policy_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698