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 = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1564 ->GetFrameTree() |
| 1565 ->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 = controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 1580 int64 isn_2 = frame_entry->item_sequence_number(); |
| 1581 int64 dsn_2 = frame_entry->document_sequence_number(); |
| 1582 EXPECT_NE(-1, isn_2); |
| 1583 EXPECT_NE(isn_1, isn_2); |
| 1584 EXPECT_EQ(dsn_1, dsn_2); |
| 1585 |
| 1586 // Also test subframe sequence numbers, but only in --site-per-proces mode. |
| 1587 // (We do not create subframe FrameNavigationEntries in default mode yet.) |
| 1588 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1589 switches::kSitePerProcess)) |
| 1590 return; |
| 1591 |
| 1592 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. |
| 1593 { |
| 1594 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1595 std::string script = "var iframe = document.createElement('iframe');" |
| 1596 "iframe.src = '" + url.spec() + "';" |
| 1597 "document.body.appendChild(iframe);"; |
| 1598 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1599 capturer.Wait(); |
| 1600 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1601 } |
| 1602 |
| 1603 // The root FrameNavigationEntry hasn't changed. |
| 1604 EXPECT_EQ(frame_entry, |
| 1605 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| 1606 |
| 1607 // We should have a unique ISN and DSN for the subframe entry. |
| 1608 FrameTreeNode* subframe = root->child_at(0); |
| 1609 FrameNavigationEntry* subframe_entry = |
| 1610 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 1611 int64 isn_3 = subframe_entry->item_sequence_number(); |
| 1612 int64 dsn_3 = subframe_entry->document_sequence_number(); |
| 1613 EXPECT_NE(-1, isn_2); |
| 1614 EXPECT_NE(isn_2, isn_3); |
| 1615 EXPECT_NE(dsn_2, dsn_3); |
| 1616 |
| 1617 // 4. Do an in-page fragment navigation in the subframe. |
| 1618 EXPECT_TRUE(content::ExecuteScript(subframe->current_frame_host(), script)); |
| 1619 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1620 |
| 1621 subframe_entry = controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 1622 int64 isn_4 = subframe_entry->item_sequence_number(); |
| 1623 int64 dsn_4 = subframe_entry->document_sequence_number(); |
| 1624 EXPECT_NE(-1, isn_4); |
| 1625 EXPECT_NE(isn_3, isn_4); |
| 1626 EXPECT_EQ(dsn_3, dsn_4); |
| 1627 } |
| 1628 |
1551 namespace { | 1629 namespace { |
1552 | 1630 |
1553 class HttpThrottle : public ResourceThrottle { | 1631 class HttpThrottle : public ResourceThrottle { |
1554 public: | 1632 public: |
1555 // ResourceThrottle | 1633 // ResourceThrottle |
1556 void WillStartRequest(bool* defer) override { | 1634 void WillStartRequest(bool* defer) override { |
1557 *defer = true; | 1635 *defer = true; |
1558 } | 1636 } |
1559 | 1637 |
1560 const char* GetNameForLogging() const override { | 1638 const char* GetNameForLogging() const override { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 // tricky. | 1973 // tricky. |
1896 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 1974 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
1897 shell()->web_contents()->Stop(); | 1975 shell()->web_contents()->Stop(); |
1898 watcher.Wait(); | 1976 watcher.Wait(); |
1899 } | 1977 } |
1900 | 1978 |
1901 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1979 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
1902 } | 1980 } |
1903 | 1981 |
1904 } // namespace content | 1982 } // namespace content |
OLD | NEW |