OLD | NEW |
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 Loading... |
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_will_start_result|, and also that navigating to |
67 void CheckTestCase(content::RenderFrameHost* host, | 67 // |extension_url| via http redirect will cancel the request unless |
68 const GURL& url, | 68 // |expected_will_start_result| is PROCEED. |
69 NavigationThrottle::ThrottleCheckResult expected_result) { | 69 void CheckTestCase( |
| 70 content::RenderFrameHost* host, |
| 71 const GURL& extension_url, |
| 72 NavigationThrottle::ThrottleCheckResult expected_will_start_result) { |
| 73 // First subtest: direct navigation to |extension_url|. |
70 std::unique_ptr<content::NavigationHandle> handle = | 74 std::unique_ptr<content::NavigationHandle> handle = |
71 content::NavigationHandle::CreateNavigationHandleForTesting(url, host); | 75 content::NavigationHandle::CreateNavigationHandleForTesting( |
72 EXPECT_EQ(expected_result, | 76 extension_url, host); |
| 77 EXPECT_EQ(expected_will_start_result, |
73 handle->CallWillStartRequestForTesting( | 78 handle->CallWillStartRequestForTesting( |
74 /*is_post=*/false, content::Referrer(), | 79 /*is_post=*/false, content::Referrer(), |
75 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK, | 80 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK, |
76 /*is_external_protocol=*/false)) | 81 /*is_external_protocol=*/false)) |
77 << url; | 82 << extension_url; |
| 83 |
| 84 // Reset the handle for a second subtest: server redirect to |
| 85 // |extension_url|. |
| 86 GURL http_url("https://example.com"); |
| 87 handle = content::NavigationHandle::CreateNavigationHandleForTesting( |
| 88 http_url, host); |
| 89 |
| 90 // TODO(nick): https://crbug.com/695421 Once PlzNavigate is enabled 100%, it |
| 91 // should be possible to support return values other than PROCEED and CANCEL |
| 92 // from ExtensionNavigationThrottle::WillRedirectRequest. |
| 93 NavigationThrottle::ThrottleCheckResult expected_will_redirect_result = |
| 94 (expected_will_start_result == NavigationThrottle::PROCEED) |
| 95 ? NavigationThrottle::PROCEED |
| 96 : NavigationThrottle::CANCEL; |
| 97 EXPECT_EQ(NavigationThrottle::PROCEED, |
| 98 handle->CallWillStartRequestForTesting( |
| 99 /*is_post=*/false, content::Referrer(), |
| 100 /*has_user_gesture=*/false, ui::PAGE_TRANSITION_LINK, |
| 101 /*is_external_protocol=*/false)) |
| 102 << http_url; |
| 103 EXPECT_EQ(expected_will_redirect_result, |
| 104 handle->CallWillRedirectRequestForTesting( |
| 105 extension_url, |
| 106 /*new_method_is_post=*/false, http_url, |
| 107 /*new_is_external_protocol=*/false)) |
| 108 << extension_url; |
78 } | 109 } |
79 | 110 |
80 const Extension* extension() { return extension_.get(); } | 111 const Extension* extension() { return extension_.get(); } |
81 content::WebContentsTester* web_contents_tester() { | 112 content::WebContentsTester* web_contents_tester() { |
82 return content::WebContentsTester::For(web_contents()); | 113 return content::WebContentsTester::For(web_contents()); |
83 } | 114 } |
84 content::RenderFrameHostTester* render_frame_host_tester( | 115 content::RenderFrameHostTester* render_frame_host_tester( |
85 content::RenderFrameHost* host) { | 116 content::RenderFrameHost* host) { |
86 return content::RenderFrameHostTester::For(host); | 117 return content::RenderFrameHostTester::For(host); |
87 } | 118 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 GURL unknown_filesystem( | 276 GURL unknown_filesystem( |
246 base::StringPrintf("filesystem:chrome-extension://%s/temporary/foo.html", | 277 base::StringPrintf("filesystem:chrome-extension://%s/temporary/foo.html", |
247 second_id.c_str())); | 278 second_id.c_str())); |
248 CheckTestCase(main_rfh(), disabled_filesystem, | 279 CheckTestCase(main_rfh(), disabled_filesystem, |
249 NavigationThrottle::BLOCK_REQUEST); | 280 NavigationThrottle::BLOCK_REQUEST); |
250 CheckTestCase(main_rfh(), unknown_filesystem, | 281 CheckTestCase(main_rfh(), unknown_filesystem, |
251 NavigationThrottle::BLOCK_REQUEST); | 282 NavigationThrottle::BLOCK_REQUEST); |
252 } | 283 } |
253 | 284 |
254 } // namespace extensions | 285 } // namespace extensions |
OLD | NEW |