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