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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 10 #include "content/browser/frame_host/cross_process_frame_connector.h" |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 | 1480 |
1481 // Check that the window.name seen by the frame matches the name attribute | 1481 // Check that the window.name seen by the frame matches the name attribute |
1482 // specified by its parent in the iframe tag. | 1482 // specified by its parent in the iframe tag. |
1483 std::string result; | 1483 std::string result; |
1484 EXPECT_TRUE(ExecuteScriptAndExtractString( | 1484 EXPECT_TRUE(ExecuteScriptAndExtractString( |
1485 root->child_at(0)->current_frame_host(), | 1485 root->child_at(0)->current_frame_host(), |
1486 "window.domAutomationController.send(window.name);", &result)); | 1486 "window.domAutomationController.send(window.name);", &result)); |
1487 EXPECT_EQ("3-1-name", result); | 1487 EXPECT_EQ("3-1-name", result); |
1488 } | 1488 } |
1489 | 1489 |
| 1490 // Verify that dynamic updates to a frame's window.name propagate to the |
| 1491 // frame's proxies, so that the latest frame names can be used in navigations. |
| 1492 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DynamicWindowName) { |
| 1493 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); |
| 1494 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 1495 |
| 1496 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1497 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1498 ->GetFrameTree() |
| 1499 ->root(); |
| 1500 TestNavigationObserver observer(shell()->web_contents()); |
| 1501 |
| 1502 // Load cross-site page into iframe. |
| 1503 GURL frame_url = |
| 1504 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); |
| 1505 NavigateFrameToURL(root->child_at(0), frame_url); |
| 1506 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1507 EXPECT_EQ(frame_url, observer.last_navigation_url()); |
| 1508 |
| 1509 // Browser process should know the child frame's original window.name |
| 1510 // specified in the iframe element. |
| 1511 EXPECT_EQ(root->child_at(0)->frame_name(), "3-1-name"); |
| 1512 |
| 1513 // Update the child frame's window.name. |
| 1514 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), |
| 1515 "window.domAutomationController.send(" |
| 1516 "window.name = 'updated-name');")); |
| 1517 |
| 1518 // The change should propagate to the browser process. |
| 1519 EXPECT_EQ(root->child_at(0)->frame_name(), "updated-name"); |
| 1520 |
| 1521 // The proxy in the parent process should also receive the updated name. |
| 1522 // Check that it can reference the child frame by its new name. |
| 1523 bool success = false; |
| 1524 EXPECT_TRUE( |
| 1525 ExecuteScriptAndExtractBool(shell()->web_contents(), |
| 1526 "window.domAutomationController.send(" |
| 1527 "frames['updated-name'] == frames[0]);", |
| 1528 &success)); |
| 1529 EXPECT_TRUE(success); |
| 1530 |
| 1531 // Issue a renderer-initiated navigation from the root frame to the child |
| 1532 // frame using the frame's name. Make sure correct frame is navigated. |
| 1533 // |
| 1534 // TODO(alexmos): When blink::createWindow is refactored to handle |
| 1535 // RemoteFrames, this should also be tested via window.open(url, frame_name) |
| 1536 // and a more complicated frame hierarchy (https://crbug.com/463742) |
| 1537 TestFrameNavigationObserver frame_observer(root->child_at(0)); |
| 1538 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1539 std::string script = base::StringPrintf( |
| 1540 "window.domAutomationController.send(" |
| 1541 "frames['updated-name'].location.href = '%s');", |
| 1542 foo_url.spec().c_str()); |
| 1543 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 1544 frame_observer.Wait(); |
| 1545 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
| 1546 } |
| 1547 |
1490 // Ensure that navigating subframes in --site-per-process mode properly fires | 1548 // Ensure that navigating subframes in --site-per-process mode properly fires |
1491 // the DidStopLoading event on WebContentsObserver. | 1549 // the DidStopLoading event on WebContentsObserver. |
1492 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { | 1550 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { |
1493 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1551 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
1494 NavigateToURL(shell(), main_url); | 1552 NavigateToURL(shell(), main_url); |
1495 | 1553 |
1496 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1554 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1497 FrameTreeNode* root = | 1555 FrameTreeNode* root = |
1498 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1556 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
1499 GetFrameTree()->root(); | 1557 GetFrameTree()->root(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1642 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
1585 TestNavigationObserver observer(shell()->web_contents()); | 1643 TestNavigationObserver observer(shell()->web_contents()); |
1586 NavigateFrameToURL(root->child_at(0), foo_url); | 1644 NavigateFrameToURL(root->child_at(0), foo_url); |
1587 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1645 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1588 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 1646 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
1589 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); | 1647 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); |
1590 } | 1648 } |
1591 } | 1649 } |
1592 | 1650 |
1593 } // namespace content | 1651 } // namespace content |
OLD | NEW |