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

Side by Side Diff: chrome/browser/extensions/extension_navigation_throttle_unittest.cc

Issue 2881733006: ExtensionNavigationThrottle: Enforce the same rules on redirect as we (Closed)
Patch Set: Merge branch 'kill_107_reboot2' into kill_107_reboot2_s 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 unified diff | Download patch
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 "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
8 #include "components/crx_file/id_util.h" 8 #include "components/crx_file/id_util.h"
9 #include "content/public/browser/content_browser_client.h" 9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/browser/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ChromeRenderViewHostTestHarness::SetUp(); 55 ChromeRenderViewHostTestHarness::SetUp();
56 original_client_ = content::SetBrowserClientForTesting(&client_); 56 original_client_ = content::SetBrowserClientForTesting(&client_);
57 AddExtension(); 57 AddExtension();
58 } 58 }
59 59
60 void TearDown() override { 60 void TearDown() override {
61 content::SetBrowserClientForTesting(original_client_); 61 content::SetBrowserClientForTesting(original_client_);
62 ChromeRenderViewHostTestHarness::TearDown(); 62 ChromeRenderViewHostTestHarness::TearDown();
63 } 63 }
64 64
65 // Checks that trying to navigate the given |host| to |url| results in the 65 // Checks that trying to navigate the given |host| to |extension_url| results
66 // |expected_result|. 66 // in the |expected_result|.
67 void CheckTestCase(content::RenderFrameHost* host, 67 void CheckTestCase(content::RenderFrameHost* host,
68 const GURL& url, 68 const GURL& extension_url,
69 NavigationThrottle::ThrottleCheckResult expected_result) { 69 NavigationThrottle::ThrottleCheckResult expected_result) {
70 // First subtest: direct navigation to |extension_url|.
70 std::unique_ptr<content::NavigationHandle> handle = 71 std::unique_ptr<content::NavigationHandle> handle =
71 content::NavigationHandle::CreateNavigationHandleForTesting(url, host); 72 content::NavigationHandle::CreateNavigationHandleForTesting(
73 extension_url, host);
72 EXPECT_EQ(expected_result, 74 EXPECT_EQ(expected_result,
73 handle->CallWillStartRequestForTesting( 75 handle->CallWillStartRequestForTesting(
74 /*is_post=*/false, content::Referrer(), 76 /*is_post=*/false, content::Referrer(),
75 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK, 77 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK,
76 /*is_external_protocol=*/false)) 78 /*is_external_protocol=*/false))
77 << url; 79 << extension_url;
80
81 // Reset the handle for a second subtest: server redirect to
82 // |extension_url|. Currently, the same rules apply, but we cancel rather
83 // than block such requests.
84 GURL http_url("https://example.com");
85 handle = content::NavigationHandle::CreateNavigationHandleForTesting(
86 http_url, host);
87 NavigationThrottle::ThrottleCheckResult expected_redirect_result =
Devlin 2017/05/18 15:22:44 This is a bit strange, because now |expected_resul
ncarter (slow) 2017/05/22 22:55:59 Really, it's just a limitation of the throttle sys
88 (expected_result == NavigationThrottle::PROCEED)
89 ? NavigationThrottle::PROCEED
90 : NavigationThrottle::CANCEL;
91 EXPECT_EQ(NavigationThrottle::PROCEED,
92 handle->CallWillStartRequestForTesting(
93 /*is_post=*/false, content::Referrer(),
94 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK,
95 /*is_external_protocol=*/false))
96 << http_url;
97 EXPECT_EQ(expected_redirect_result,
98 handle->CallWillRedirectRequestForTesting(
99 extension_url,
100 /*new_method_is_post=*/false, http_url,
101 /*new_is_external_protocol=*/false))
102 << extension_url;
78 } 103 }
79 104
80 const Extension* extension() { return extension_.get(); } 105 const Extension* extension() { return extension_.get(); }
81 content::WebContentsTester* web_contents_tester() { 106 content::WebContentsTester* web_contents_tester() {
82 return content::WebContentsTester::For(web_contents()); 107 return content::WebContentsTester::For(web_contents());
83 } 108 }
84 content::RenderFrameHostTester* render_frame_host_tester( 109 content::RenderFrameHostTester* render_frame_host_tester(
85 content::RenderFrameHost* host) { 110 content::RenderFrameHost* host) {
86 return content::RenderFrameHostTester::For(host); 111 return content::RenderFrameHostTester::For(host);
87 } 112 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 GURL unknown_filesystem( 270 GURL unknown_filesystem(
246 base::StringPrintf("filesystem:chrome-extension://%s/temporary/foo.html", 271 base::StringPrintf("filesystem:chrome-extension://%s/temporary/foo.html",
247 second_id.c_str())); 272 second_id.c_str()));
248 CheckTestCase(main_rfh(), disabled_filesystem, 273 CheckTestCase(main_rfh(), disabled_filesystem,
249 NavigationThrottle::BLOCK_REQUEST); 274 NavigationThrottle::BLOCK_REQUEST);
250 CheckTestCase(main_rfh(), unknown_filesystem, 275 CheckTestCase(main_rfh(), unknown_filesystem,
251 NavigationThrottle::BLOCK_REQUEST); 276 NavigationThrottle::BLOCK_REQUEST);
252 } 277 }
253 278
254 } // namespace extensions 279 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698