OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 " B = http://b.com/", | 2299 " B = http://b.com/", |
2300 DepictFrameTree(root)); | 2300 DepictFrameTree(root)); |
2301 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 2301 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
2302 child->current_frame_host()->GetSiteInstance()); | 2302 child->current_frame_host()->GetSiteInstance()); |
2303 } | 2303 } |
2304 | 2304 |
2305 // The FrameTreeNode should update its URL (so that we don't affect other uses | 2305 // The FrameTreeNode should update its URL (so that we don't affect other uses |
2306 // of the API), but the frame's last_successful_url shouldn't change and the | 2306 // of the API), but the frame's last_successful_url shouldn't change and the |
2307 // origin should be empty. | 2307 // origin should be empty. |
2308 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the | 2308 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the |
2309 // last succesful url should be empty (since the frame only loaded an error | 2309 // last successful url should be empty (since the frame only loaded an error |
2310 // page). | 2310 // page). |
2311 if (IsBrowserSideNavigationEnabled()) | 2311 if (IsBrowserSideNavigationEnabled()) |
2312 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); | 2312 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); |
2313 else | 2313 else |
2314 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); | 2314 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); |
2315 EXPECT_EQ(url_b, child->current_url()); | 2315 EXPECT_EQ(url_b, child->current_url()); |
2316 EXPECT_EQ("null", child->current_origin().Serialize()); | 2316 EXPECT_EQ("null", child->current_origin().Serialize()); |
2317 | 2317 |
2318 // Try again after re-enabling host resolution. | 2318 // Try again after re-enabling host resolution. |
2319 host_resolver()->AddRule("*", "127.0.0.1"); | 2319 host_resolver()->AddRule("*", "127.0.0.1"); |
(...skipping 4830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7150 | 7150 |
7151 // The blocked frame should still fire a load event in its parent's process. | 7151 // The blocked frame should still fire a load event in its parent's process. |
7152 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7152 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7153 | 7153 |
7154 // Check that the current RenderFrameHost has stopped loading. | 7154 // Check that the current RenderFrameHost has stopped loading. |
7155 if (root->child_at(0)->current_frame_host()->is_loading()) { | 7155 if (root->child_at(0)->current_frame_host()->is_loading()) { |
7156 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7156 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7157 load_observer.Wait(); | 7157 load_observer.Wait(); |
7158 } | 7158 } |
7159 | 7159 |
7160 // The blocked frame should stay at the old location. | 7160 if (IsBrowserSideNavigationEnabled()) { |
7161 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 7161 // We have switched RenderFrameHosts for the subframe, so the last |
| 7162 // successful url should be empty (since the frame only loaded an error |
| 7163 // page). |
| 7164 EXPECT_EQ(GURL(), |
| 7165 root->child_at(0)->current_frame_host()->last_successful_url()); |
7162 | 7166 |
7163 // The blocked frame should keep the old title. | 7167 // The blocked frame should go to an error page. Errors currently commit |
7164 std::string frame_title; | 7168 // with the URL of the blocked page. |
7165 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7169 EXPECT_EQ(blocked_url, root->child_at(0)->current_url()); |
7166 root->child_at(0), "domAutomationController.send(document.title)", | 7170 |
7167 &frame_title)); | 7171 // The page should get the title of an error page (i.e "") and not the |
7168 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7172 // title of the blocked page. |
| 7173 std::string frame_title; |
| 7174 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7175 root->child_at(0), "domAutomationController.send(document.title)", |
| 7176 &frame_title)); |
| 7177 EXPECT_EQ("", frame_title); |
| 7178 } else { |
| 7179 // The last successful url shouldn't be the blocked url. |
| 7180 EXPECT_EQ(old_subframe_url, |
| 7181 root->child_at(0)->current_frame_host()->last_successful_url()); |
| 7182 |
| 7183 // The blocked frame should stay at the old location. |
| 7184 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 7185 |
| 7186 // The blocked frame should keep the old title. |
| 7187 std::string frame_title; |
| 7188 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7189 root->child_at(0), "domAutomationController.send(document.title)", |
| 7190 &frame_title)); |
| 7191 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7192 } |
7169 | 7193 |
7170 // Navigate to a URL without CSP. | 7194 // Navigate to a URL without CSP. |
7171 EXPECT_TRUE(NavigateToURL( | 7195 EXPECT_TRUE(NavigateToURL( |
7172 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 7196 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
7173 | 7197 |
7174 // Verify that the frame's CSP got correctly reset to an empty set. | 7198 // Verify that the frame's CSP got correctly reset to an empty set. |
7175 EXPECT_EQ(0u, | 7199 EXPECT_EQ(0u, |
7176 root->current_replication_state().accumulated_csp_headers.size()); | 7200 root->current_replication_state().accumulated_csp_headers.size()); |
7177 } | 7201 } |
7178 | 7202 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7225 | 7249 |
7226 // The blocked frame should still fire a load event in its parent's process. | 7250 // The blocked frame should still fire a load event in its parent's process. |
7227 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7251 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7228 | 7252 |
7229 // Check that the current RenderFrameHost has stopped loading. | 7253 // Check that the current RenderFrameHost has stopped loading. |
7230 if (root->child_at(0)->current_frame_host()->is_loading()) { | 7254 if (root->child_at(0)->current_frame_host()->is_loading()) { |
7231 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7255 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7232 load_observer2.Wait(); | 7256 load_observer2.Wait(); |
7233 } | 7257 } |
7234 | 7258 |
7235 // The blocked frame should stay at the old location. | 7259 if (IsBrowserSideNavigationEnabled()) { |
7236 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 7260 // We have switched RenderFrameHosts for the subframe, so the last |
| 7261 // successful url should be empty (since the frame only loaded an error |
| 7262 // page). |
| 7263 EXPECT_EQ(GURL(), |
| 7264 root->child_at(0)->current_frame_host()->last_successful_url()); |
7237 | 7265 |
7238 // The blocked frame should keep the old title. | 7266 // The blocked frame should go to an error page. Errors currently commit |
7239 std::string frame_title; | 7267 // with the URL of the blocked page. |
7240 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7268 EXPECT_EQ(blocked_url, root->child_at(0)->current_url()); |
7241 root->child_at(0), "domAutomationController.send(document.title)", | 7269 |
7242 &frame_title)); | 7270 // The page should get the title of an error page (i.e "") and not the |
7243 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7271 // title of the blocked page. |
| 7272 std::string frame_title; |
| 7273 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7274 root->child_at(0), "domAutomationController.send(document.title)", |
| 7275 &frame_title)); |
| 7276 EXPECT_EQ("", frame_title); |
| 7277 } else { |
| 7278 // The last successful url shouldn't be the blocked url. |
| 7279 EXPECT_EQ(old_subframe_url, |
| 7280 root->child_at(0)->current_frame_host()->last_successful_url()); |
| 7281 |
| 7282 // The blocked frame should stay at the old location. |
| 7283 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 7284 |
| 7285 // The blocked frame should keep the old title. |
| 7286 std::string frame_title; |
| 7287 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7288 root->child_at(0), "domAutomationController.send(document.title)", |
| 7289 &frame_title)); |
| 7290 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7291 } |
7244 } | 7292 } |
7245 | 7293 |
7246 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. | 7294 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. |
7247 // In this version of a test, CSP is inherited by srcdoc iframe from a parent | 7295 // In this version of a test, CSP is inherited by srcdoc iframe from a parent |
7248 // that declared CSP via HTTP headers. Cross-origin frame navigating to a | 7296 // that declared CSP via HTTP headers. Cross-origin frame navigating to a |
7249 // blocked location is a child of the srcdoc iframe. | 7297 // blocked location is a child of the srcdoc iframe. |
7250 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 7298 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
7251 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { | 7299 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { |
7252 GURL main_url( | 7300 GURL main_url( |
7253 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); | 7301 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7294 | 7342 |
7295 // The blocked frame should still fire a load event in its parent's process. | 7343 // The blocked frame should still fire a load event in its parent's process. |
7296 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7344 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7297 | 7345 |
7298 // Check that the current RenderFrameHost has stopped loading. | 7346 // Check that the current RenderFrameHost has stopped loading. |
7299 if (navigating_frame->current_frame_host()->is_loading()) { | 7347 if (navigating_frame->current_frame_host()->is_loading()) { |
7300 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7348 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7301 load_observer2.Wait(); | 7349 load_observer2.Wait(); |
7302 } | 7350 } |
7303 | 7351 |
7304 // The blocked frame should stay at the old location. | 7352 if (IsBrowserSideNavigationEnabled()) { |
7305 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); | 7353 // We have switched RenderFrameHosts for the subframe, so the last |
| 7354 // successful url should be empty (since the frame only loaded an error |
| 7355 // page). |
| 7356 EXPECT_EQ(GURL(), |
| 7357 navigating_frame->current_frame_host()->last_successful_url()); |
7306 | 7358 |
7307 // The blocked frame should keep the old title. | 7359 // The blocked frame should go to an error page. Errors currently commit |
7308 std::string frame_title; | 7360 // with the URL of the blocked page. |
7309 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7361 EXPECT_EQ(blocked_url, navigating_frame->current_url()); |
7310 navigating_frame, "domAutomationController.send(document.title)", | 7362 |
7311 &frame_title)); | 7363 // The page should get the title of an error page (i.e "") and not the |
7312 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7364 // title of the blocked page. |
| 7365 std::string frame_title; |
| 7366 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7367 navigating_frame, "domAutomationController.send(document.title)", |
| 7368 &frame_title)); |
| 7369 EXPECT_EQ("", frame_title); |
| 7370 } else { |
| 7371 // The last successful url shouldn't be the blocked url. |
| 7372 EXPECT_EQ(old_subframe_url, |
| 7373 navigating_frame->current_frame_host()->last_successful_url()); |
| 7374 |
| 7375 // The blocked frame should stay at the old location. |
| 7376 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); |
| 7377 |
| 7378 // The blocked frame should keep the old title. |
| 7379 std::string frame_title; |
| 7380 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7381 navigating_frame, "domAutomationController.send(document.title)", |
| 7382 &frame_title)); |
| 7383 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7384 } |
7313 | 7385 |
7314 // Navigate the subframe to a URL without CSP. | 7386 // Navigate the subframe to a URL without CSP. |
7315 NavigateFrameToURL(srcdoc_frame, | 7387 NavigateFrameToURL(srcdoc_frame, |
7316 embedded_test_server()->GetURL("a.com", "/title1.html")); | 7388 embedded_test_server()->GetURL("a.com", "/title1.html")); |
7317 | 7389 |
7318 // Verify that the frame's CSP got correctly reset to an empty set. | 7390 // Verify that the frame's CSP got correctly reset to an empty set. |
7319 EXPECT_EQ( | 7391 EXPECT_EQ( |
7320 0u, | 7392 0u, |
7321 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); | 7393 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); |
7322 } | 7394 } |
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9333 "subframes_with_resources.html?urls=%s,%s&" | 9405 "subframes_with_resources.html?urls=%s,%s&" |
9334 "numSubresources=3", | 9406 "numSubresources=3", |
9335 path0.c_str(), path1.c_str()))); | 9407 path0.c_str(), path1.c_str()))); |
9336 EXPECT_TRUE(NavigateToURL(shell(), url)); | 9408 EXPECT_TRUE(NavigateToURL(shell(), url)); |
9337 bool result; | 9409 bool result; |
9338 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); | 9410 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); |
9339 EXPECT_TRUE(result); | 9411 EXPECT_TRUE(result); |
9340 } | 9412 } |
9341 | 9413 |
9342 } // namespace content | 9414 } // namespace content |
OLD | NEW |