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 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 " B = http://b.com/", | 2309 " B = http://b.com/", |
2310 DepictFrameTree(root)); | 2310 DepictFrameTree(root)); |
2311 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 2311 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
2312 child->current_frame_host()->GetSiteInstance()); | 2312 child->current_frame_host()->GetSiteInstance()); |
2313 } | 2313 } |
2314 | 2314 |
2315 // The FrameTreeNode should update its URL (so that we don't affect other uses | 2315 // The FrameTreeNode should update its URL (so that we don't affect other uses |
2316 // of the API), but the frame's last_successful_url shouldn't change and the | 2316 // of the API), but the frame's last_successful_url shouldn't change and the |
2317 // origin should be empty. | 2317 // origin should be empty. |
2318 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the | 2318 // PlzNavigate: We have switched RenderFrameHosts for the subframe, so the |
2319 // last succesful url should be empty (since the frame only loaded an error | 2319 // last successful url should be empty (since the frame only loaded an error |
2320 // page). | 2320 // page). |
2321 if (IsBrowserSideNavigationEnabled()) | 2321 if (IsBrowserSideNavigationEnabled()) |
2322 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); | 2322 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); |
2323 else | 2323 else |
2324 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); | 2324 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); |
2325 EXPECT_EQ(url_b, child->current_url()); | 2325 EXPECT_EQ(url_b, child->current_url()); |
2326 EXPECT_EQ("null", child->current_origin().Serialize()); | 2326 EXPECT_EQ("null", child->current_origin().Serialize()); |
2327 | 2327 |
2328 // Try again after re-enabling host resolution. | 2328 // Try again after re-enabling host resolution. |
2329 host_resolver()->AddRule("*", "127.0.0.1"); | 2329 host_resolver()->AddRule("*", "127.0.0.1"); |
(...skipping 4831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7161 | 7161 |
7162 // The blocked frame should still fire a load event in its parent's process. | 7162 // The blocked frame should still fire a load event in its parent's process. |
7163 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7163 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7164 | 7164 |
7165 // Check that the current RenderFrameHost has stopped loading. | 7165 // Check that the current RenderFrameHost has stopped loading. |
7166 if (root->child_at(0)->current_frame_host()->is_loading()) { | 7166 if (root->child_at(0)->current_frame_host()->is_loading()) { |
7167 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7167 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7168 load_observer.Wait(); | 7168 load_observer.Wait(); |
7169 } | 7169 } |
7170 | 7170 |
7171 // The blocked frame should stay at the old location. | 7171 if (IsBrowserSideNavigationEnabled()) { |
7172 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 7172 // We have switched RenderFrameHosts for the subframe, so the last |
| 7173 // successful url should be empty (since the frame only loaded an error |
| 7174 // page). |
| 7175 EXPECT_EQ(GURL(), |
| 7176 root->child_at(0)->current_frame_host()->last_successful_url()); |
7173 | 7177 |
7174 // The blocked frame should keep the old title. | 7178 // The blocked frame should go to an error page. Errors currently commit |
7175 std::string frame_title; | 7179 // with the URL of the blocked page. |
7176 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7180 EXPECT_EQ(blocked_url, root->child_at(0)->current_url()); |
7177 root->child_at(0), "domAutomationController.send(document.title)", | 7181 |
7178 &frame_title)); | 7182 // The page should get the title of an error page (i.e "") and not the |
7179 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7183 // title of the blocked page. |
| 7184 std::string frame_title; |
| 7185 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7186 root->child_at(0), "domAutomationController.send(document.title)", |
| 7187 &frame_title)); |
| 7188 EXPECT_EQ("", frame_title); |
| 7189 } else { |
| 7190 // The last successful url shouldn't be the blocked url. |
| 7191 EXPECT_EQ(old_subframe_url, |
| 7192 root->child_at(0)->current_frame_host()->last_successful_url()); |
| 7193 |
| 7194 // The blocked frame should stay at the old location. |
| 7195 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 7196 |
| 7197 // The blocked frame should keep the old title. |
| 7198 std::string frame_title; |
| 7199 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7200 root->child_at(0), "domAutomationController.send(document.title)", |
| 7201 &frame_title)); |
| 7202 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7203 } |
7180 | 7204 |
7181 // Navigate to a URL without CSP. | 7205 // Navigate to a URL without CSP. |
7182 EXPECT_TRUE(NavigateToURL( | 7206 EXPECT_TRUE(NavigateToURL( |
7183 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 7207 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
7184 | 7208 |
7185 // Verify that the frame's CSP got correctly reset to an empty set. | 7209 // Verify that the frame's CSP got correctly reset to an empty set. |
7186 EXPECT_EQ(0u, | 7210 EXPECT_EQ(0u, |
7187 root->current_replication_state().accumulated_csp_headers.size()); | 7211 root->current_replication_state().accumulated_csp_headers.size()); |
7188 } | 7212 } |
7189 | 7213 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7236 | 7260 |
7237 // The blocked frame should still fire a load event in its parent's process. | 7261 // The blocked frame should still fire a load event in its parent's process. |
7238 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7262 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7239 | 7263 |
7240 // Check that the current RenderFrameHost has stopped loading. | 7264 // Check that the current RenderFrameHost has stopped loading. |
7241 if (root->child_at(0)->current_frame_host()->is_loading()) { | 7265 if (root->child_at(0)->current_frame_host()->is_loading()) { |
7242 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7266 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7243 load_observer2.Wait(); | 7267 load_observer2.Wait(); |
7244 } | 7268 } |
7245 | 7269 |
7246 // The blocked frame should stay at the old location. | 7270 if (IsBrowserSideNavigationEnabled()) { |
7247 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 7271 // We have switched RenderFrameHosts for the subframe, so the last |
| 7272 // successful url should be empty (since the frame only loaded an error |
| 7273 // page). |
| 7274 EXPECT_EQ(GURL(), |
| 7275 root->child_at(0)->current_frame_host()->last_successful_url()); |
7248 | 7276 |
7249 // The blocked frame should keep the old title. | 7277 // The blocked frame should go to an error page. Errors currently commit |
7250 std::string frame_title; | 7278 // with the URL of the blocked page. |
7251 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7279 EXPECT_EQ(blocked_url, root->child_at(0)->current_url()); |
7252 root->child_at(0), "domAutomationController.send(document.title)", | 7280 |
7253 &frame_title)); | 7281 // The page should get the title of an error page (i.e "") and not the |
7254 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7282 // title of the blocked page. |
| 7283 std::string frame_title; |
| 7284 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7285 root->child_at(0), "domAutomationController.send(document.title)", |
| 7286 &frame_title)); |
| 7287 EXPECT_EQ("", frame_title); |
| 7288 } else { |
| 7289 // The last successful url shouldn't be the blocked url. |
| 7290 EXPECT_EQ(old_subframe_url, |
| 7291 root->child_at(0)->current_frame_host()->last_successful_url()); |
| 7292 |
| 7293 // The blocked frame should stay at the old location. |
| 7294 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 7295 |
| 7296 // The blocked frame should keep the old title. |
| 7297 std::string frame_title; |
| 7298 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7299 root->child_at(0), "domAutomationController.send(document.title)", |
| 7300 &frame_title)); |
| 7301 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7302 } |
7255 } | 7303 } |
7256 | 7304 |
7257 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. | 7305 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. |
7258 // In this version of a test, CSP is inherited by srcdoc iframe from a parent | 7306 // In this version of a test, CSP is inherited by srcdoc iframe from a parent |
7259 // that declared CSP via HTTP headers. Cross-origin frame navigating to a | 7307 // that declared CSP via HTTP headers. Cross-origin frame navigating to a |
7260 // blocked location is a child of the srcdoc iframe. | 7308 // blocked location is a child of the srcdoc iframe. |
7261 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 7309 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
7262 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { | 7310 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { |
7263 GURL main_url( | 7311 GURL main_url( |
7264 embedded_test_server()->GetURL("a.com", "/frame-src-self-and-b.html")); | 7312 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... |
7305 | 7353 |
7306 // The blocked frame should still fire a load event in its parent's process. | 7354 // The blocked frame should still fire a load event in its parent's process. |
7307 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 7355 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
7308 | 7356 |
7309 // Check that the current RenderFrameHost has stopped loading. | 7357 // Check that the current RenderFrameHost has stopped loading. |
7310 if (navigating_frame->current_frame_host()->is_loading()) { | 7358 if (navigating_frame->current_frame_host()->is_loading()) { |
7311 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 7359 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
7312 load_observer2.Wait(); | 7360 load_observer2.Wait(); |
7313 } | 7361 } |
7314 | 7362 |
7315 // The blocked frame should stay at the old location. | 7363 if (IsBrowserSideNavigationEnabled()) { |
7316 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); | 7364 // We have switched RenderFrameHosts for the subframe, so the last |
| 7365 // successful url should be empty (since the frame only loaded an error |
| 7366 // page). |
| 7367 EXPECT_EQ(GURL(), |
| 7368 navigating_frame->current_frame_host()->last_successful_url()); |
7317 | 7369 |
7318 // The blocked frame should keep the old title. | 7370 // The blocked frame should go to an error page. Errors currently commit |
7319 std::string frame_title; | 7371 // with the URL of the blocked page. |
7320 EXPECT_TRUE(ExecuteScriptAndExtractString( | 7372 EXPECT_EQ(blocked_url, navigating_frame->current_url()); |
7321 navigating_frame, "domAutomationController.send(document.title)", | 7373 |
7322 &frame_title)); | 7374 // The page should get the title of an error page (i.e "") and not the |
7323 EXPECT_EQ("Title Of Awesomeness", frame_title); | 7375 // title of the blocked page. |
| 7376 std::string frame_title; |
| 7377 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7378 navigating_frame, "domAutomationController.send(document.title)", |
| 7379 &frame_title)); |
| 7380 EXPECT_EQ("", frame_title); |
| 7381 } else { |
| 7382 // The last successful url shouldn't be the blocked url. |
| 7383 EXPECT_EQ(old_subframe_url, |
| 7384 navigating_frame->current_frame_host()->last_successful_url()); |
| 7385 |
| 7386 // The blocked frame should stay at the old location. |
| 7387 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); |
| 7388 |
| 7389 // The blocked frame should keep the old title. |
| 7390 std::string frame_title; |
| 7391 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 7392 navigating_frame, "domAutomationController.send(document.title)", |
| 7393 &frame_title)); |
| 7394 EXPECT_EQ("Title Of Awesomeness", frame_title); |
| 7395 } |
7324 | 7396 |
7325 // Navigate the subframe to a URL without CSP. | 7397 // Navigate the subframe to a URL without CSP. |
7326 NavigateFrameToURL(srcdoc_frame, | 7398 NavigateFrameToURL(srcdoc_frame, |
7327 embedded_test_server()->GetURL("a.com", "/title1.html")); | 7399 embedded_test_server()->GetURL("a.com", "/title1.html")); |
7328 | 7400 |
7329 // Verify that the frame's CSP got correctly reset to an empty set. | 7401 // Verify that the frame's CSP got correctly reset to an empty set. |
7330 EXPECT_EQ( | 7402 EXPECT_EQ( |
7331 0u, | 7403 0u, |
7332 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); | 7404 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); |
7333 } | 7405 } |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9543 for (size_t index = 0; index < frames_.size(); ++index) { | 9615 for (size_t index = 0; index < frames_.size(); ++index) { |
9544 std::string text = base::StringPrintf("text%zu", index); | 9616 std::string text = base::StringPrintf("text%zu", index); |
9545 FocusInputInFrame(frames_[index]); | 9617 FocusInputInFrame(frames_[index]); |
9546 CommitText(text.c_str()); | 9618 CommitText(text.c_str()); |
9547 selection_observer.WaitForSelectedText(text); | 9619 selection_observer.WaitForSelectedText(text); |
9548 } | 9620 } |
9549 } | 9621 } |
9550 #endif // OS_ANDROID | 9622 #endif // OS_ANDROID |
9551 | 9623 |
9552 } // namespace content | 9624 } // namespace content |
OLD | NEW |