OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 EXPECT_EQ( | 1541 EXPECT_EQ( |
1542 " Site A ------------ proxies for B\n" | 1542 " Site A ------------ proxies for B\n" |
1543 " |--Site A ------- proxies for B\n" | 1543 " |--Site A ------- proxies for B\n" |
1544 " +--Site B ------- proxies for A\n" | 1544 " +--Site B ------- proxies for A\n" |
1545 "Where A = http://127.0.0.1/\n" | 1545 "Where A = http://127.0.0.1/\n" |
1546 " B = http://baz.com/", | 1546 " B = http://baz.com/", |
1547 visualizer.DepictFrameTree(root)); | 1547 visualizer.DepictFrameTree(root)); |
1548 } | 1548 } |
1549 } | 1549 } |
1550 | 1550 |
| 1551 // Verifies that item sequence numbers and document sequence numbers update |
| 1552 // properly for main frames and subframes. |
| 1553 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1554 FrameNavigationEntry_SequenceNumbers) { |
| 1555 const NavigationControllerImpl& controller = |
| 1556 static_cast<const NavigationControllerImpl&>( |
| 1557 shell()->web_contents()->GetController()); |
| 1558 |
| 1559 // 1. Navigate the main frame. |
| 1560 GURL url(embedded_test_server()->GetURL( |
| 1561 "/navigation_controller/page_with_links.html")); |
| 1562 NavigateToURL(shell(), url); |
| 1563 FrameTreeNode* root = |
| 1564 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1565 GetFrameTree()->root(); |
| 1566 |
| 1567 FrameNavigationEntry* frame_entry = |
| 1568 controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 1569 int64 isn_1 = frame_entry->item_sequence_number(); |
| 1570 int64 dsn_1 = frame_entry->document_sequence_number(); |
| 1571 EXPECT_NE(-1, isn_1); |
| 1572 EXPECT_NE(-1, dsn_1); |
| 1573 |
| 1574 // 2. Do an in-page fragment navigation. |
| 1575 std::string script = "document.getElementById('fraglink').click()"; |
| 1576 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1577 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1578 |
| 1579 frame_entry = |
| 1580 controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 1581 int64 isn_2 = frame_entry->item_sequence_number(); |
| 1582 int64 dsn_2 = frame_entry->document_sequence_number(); |
| 1583 EXPECT_NE(-1, isn_2); |
| 1584 EXPECT_NE(isn_1, isn_2); |
| 1585 EXPECT_EQ(dsn_1, dsn_2); |
| 1586 |
| 1587 // Also test subframe sequence numbers, but only in --site-per-proces mode. |
| 1588 // (We do not create subframe FrameNavigationEntries in default mode yet.) |
| 1589 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1590 switches::kSitePerProcess)) |
| 1591 return; |
| 1592 |
| 1593 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. |
| 1594 { |
| 1595 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1596 std::string script = "var iframe = document.createElement('iframe');" |
| 1597 "iframe.src = '" + url.spec() + "';" |
| 1598 "document.body.appendChild(iframe);"; |
| 1599 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1600 capturer.Wait(); |
| 1601 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1602 } |
| 1603 |
| 1604 // The root FrameNavigationEntry hasn't changed. |
| 1605 EXPECT_EQ(frame_entry, |
| 1606 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| 1607 |
| 1608 // We should have a unique ISN and DSN for the subframe entry. |
| 1609 FrameTreeNode* subframe = root->child_at(0); |
| 1610 FrameNavigationEntry* subframe_entry = |
| 1611 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 1612 int64 isn_3 = subframe_entry->item_sequence_number(); |
| 1613 int64 dsn_3 = subframe_entry->document_sequence_number(); |
| 1614 EXPECT_NE(-1, isn_2); |
| 1615 EXPECT_NE(isn_2, isn_3); |
| 1616 EXPECT_NE(dsn_2, dsn_3); |
| 1617 |
| 1618 // 4. Do an in-page fragment navigation in the subframe. |
| 1619 EXPECT_TRUE(content::ExecuteScript(subframe->current_frame_host(), script)); |
| 1620 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1621 |
| 1622 subframe_entry = |
| 1623 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 1624 int64 isn_4 = subframe_entry->item_sequence_number(); |
| 1625 int64 dsn_4 = subframe_entry->document_sequence_number(); |
| 1626 EXPECT_NE(-1, isn_4); |
| 1627 EXPECT_NE(isn_3, isn_4); |
| 1628 EXPECT_EQ(dsn_3, dsn_4); |
| 1629 } |
| 1630 |
1551 namespace { | 1631 namespace { |
1552 | 1632 |
1553 class HttpThrottle : public ResourceThrottle { | 1633 class HttpThrottle : public ResourceThrottle { |
1554 public: | 1634 public: |
1555 // ResourceThrottle | 1635 // ResourceThrottle |
1556 void WillStartRequest(bool* defer) override { | 1636 void WillStartRequest(bool* defer) override { |
1557 *defer = true; | 1637 *defer = true; |
1558 } | 1638 } |
1559 | 1639 |
1560 const char* GetNameForLogging() const override { | 1640 const char* GetNameForLogging() const override { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 // tricky. | 1975 // tricky. |
1896 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 1976 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
1897 shell()->web_contents()->Stop(); | 1977 shell()->web_contents()->Stop(); |
1898 watcher.Wait(); | 1978 watcher.Wait(); |
1899 } | 1979 } |
1900 | 1980 |
1901 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1981 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
1902 } | 1982 } |
1903 | 1983 |
1904 } // namespace content | 1984 } // namespace content |
OLD | NEW |