Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 805563003: Track referenced files of subframes in PageState. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change file_path to file Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/common/page_state_serialization.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 1536
1537 private: 1537 private:
1538 base::FilePath file_; 1538 base::FilePath file_;
1539 bool file_chosen_; 1539 bool file_chosen_;
1540 }; 1540 };
1541 1541
1542 // Test for http://crbug.com/262948. 1542 // Test for http://crbug.com/262948.
1543 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, 1543 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
1544 RestoreFileAccessForHistoryNavigation) { 1544 RestoreFileAccessForHistoryNavigation) {
1545 StartServer(); 1545 StartServer();
1546 base::FilePath file_path; 1546 base::FilePath file;
1547 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); 1547 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file));
1548 file_path = file_path.AppendASCII("bar"); 1548 file = file.AppendASCII("bar");
1549 1549
1550 // Navigate to url and get it to reference a file in its PageState. 1550 // Navigate to url and get it to reference a file in its PageState.
1551 GURL url1(test_server()->GetURL("files/file_input.html")); 1551 GURL url1(test_server()->GetURL("files/file_input.html"));
1552 NavigateToURL(shell(), url1); 1552 NavigateToURL(shell(), url1);
1553 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); 1553 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
1554 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file_path)); 1554 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file));
1555 shell()->web_contents()->SetDelegate(delegate.get()); 1555 shell()->web_contents()->SetDelegate(delegate.get());
1556 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 1556 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
1557 "document.getElementById('fileinput').click();")); 1557 "document.getElementById('fileinput').click();"));
1558 EXPECT_TRUE(delegate->file_chosen()); 1558 EXPECT_TRUE(delegate->file_chosen());
1559 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 1559 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1560 process_id, file_path)); 1560 process_id, file));
1561 1561
1562 // Navigate to a different process without access to the file, and wait for 1562 // Navigate to a different process without access to the file, and wait for
1563 // the old process to exit. 1563 // the old process to exit.
1564 RenderProcessHostWatcher exit_observer( 1564 RenderProcessHostWatcher exit_observer(
1565 shell()->web_contents()->GetRenderProcessHost(), 1565 shell()->web_contents()->GetRenderProcessHost(),
1566 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); 1566 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
1567 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); 1567 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html"));
1568 exit_observer.Wait(); 1568 exit_observer.Wait();
1569 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 1569 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1570 shell()->web_contents()->GetRenderProcessHost()->GetID(), file_path)); 1570 shell()->web_contents()->GetRenderProcessHost()->GetID(), file));
1571 1571
1572 // Ensure that the file ended up in the PageState of the previous entry. 1572 // Ensure that the file ended up in the PageState of the previous entry.
1573 NavigationEntry* prev_entry = 1573 NavigationEntry* prev_entry =
1574 shell()->web_contents()->GetController().GetEntryAtIndex(0); 1574 shell()->web_contents()->GetController().GetEntryAtIndex(0);
1575 EXPECT_EQ(url1, prev_entry->GetURL()); 1575 EXPECT_EQ(url1, prev_entry->GetURL());
1576 const std::vector<base::FilePath>& file_paths = 1576 const std::vector<base::FilePath>& files =
1577 prev_entry->GetPageState().GetReferencedFiles(); 1577 prev_entry->GetPageState().GetReferencedFiles();
1578 ASSERT_EQ(1U, file_paths.size()); 1578 ASSERT_EQ(1U, files.size());
1579 EXPECT_EQ(file_path, file_paths.at(0)); 1579 EXPECT_EQ(file, files.at(0));
1580 1580
1581 // Go back, ending up in a different RenderProcessHost than before. 1581 // Go back, ending up in a different RenderProcessHost than before.
1582 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); 1582 TestNavigationObserver back_nav_load_observer(shell()->web_contents());
1583 shell()->web_contents()->GetController().GoBack(); 1583 shell()->web_contents()->GetController().GoBack();
1584 back_nav_load_observer.Wait(); 1584 back_nav_load_observer.Wait();
1585 EXPECT_NE(process_id, 1585 EXPECT_NE(process_id,
1586 shell()->web_contents()->GetRenderProcessHost()->GetID()); 1586 shell()->web_contents()->GetRenderProcessHost()->GetID());
1587 1587
1588 // Ensure that the file access still exists in the new process ID. 1588 // Ensure that the file access still exists in the new process ID.
1589 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 1589 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1590 shell()->web_contents()->GetRenderProcessHost()->GetID(), file_path)); 1590 shell()->web_contents()->GetRenderProcessHost()->GetID(), file));
1591 1591
1592 // Navigate to a same site page to trigger a PageState update and ensure the 1592 // Navigate to a same site page to trigger a PageState update and ensure the
1593 // renderer is not killed. 1593 // renderer is not killed.
1594 EXPECT_TRUE( 1594 EXPECT_TRUE(
1595 NavigateToURL(shell(), test_server()->GetURL("files/title2.html"))); 1595 NavigateToURL(shell(), test_server()->GetURL("files/title2.html")));
1596 } 1596 }
1597 1597
1598 // Test for http://crbug.com/441966.
1599 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
1600 RestoreSubframeFileAccessForHistoryNavigation) {
1601 StartServer();
1602 base::FilePath file;
1603 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file));
1604 file = file.AppendASCII("bar");
1605
1606 // Navigate to url and get it to reference a file in its PageState.
1607 GURL url1(test_server()->GetURL("files/file_input_subframe.html"));
1608 NavigateToURL(shell(), url1);
1609 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents());
1610 FrameTreeNode* root = wc->GetFrameTree()->root();
1611 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
1612 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file));
1613 shell()->web_contents()->SetDelegate(delegate.get());
1614 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(),
1615 "document.getElementById('fileinput').click();"));
1616 EXPECT_TRUE(delegate->file_chosen());
1617 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1618 process_id, file));
1619
1620 // Navigate to a different process without access to the file, and wait for
1621 // the old process to exit.
1622 RenderProcessHostWatcher exit_observer(
1623 shell()->web_contents()->GetRenderProcessHost(),
1624 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
1625 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html"));
1626 exit_observer.Wait();
1627 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1628 shell()->web_contents()->GetRenderProcessHost()->GetID(), file));
1629
1630 // Ensure that the file ended up in the PageState of the previous entry.
1631 NavigationEntry* prev_entry =
1632 shell()->web_contents()->GetController().GetEntryAtIndex(0);
1633 EXPECT_EQ(url1, prev_entry->GetURL());
1634 const std::vector<base::FilePath>& files =
1635 prev_entry->GetPageState().GetReferencedFiles();
1636 ASSERT_EQ(1U, files.size());
1637 EXPECT_EQ(file, files.at(0));
1638
1639 // Go back, ending up in a different RenderProcessHost than before.
1640 TestNavigationObserver back_nav_load_observer(shell()->web_contents());
1641 shell()->web_contents()->GetController().GoBack();
1642 back_nav_load_observer.Wait();
1643 EXPECT_NE(process_id,
1644 shell()->web_contents()->GetRenderProcessHost()->GetID());
1645
1646 // Ensure that the file access still exists in the new process ID.
1647 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1648 shell()->web_contents()->GetRenderProcessHost()->GetID(), file));
1649 }
1650
1598 } // namespace content 1651 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/page_state_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698