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

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

Issue 2832313002: Exclude files from FileSelectChooser if they can't convert to WebStrings. (Closed)
Patch Set: Created 3 years, 8 months 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 // the SwapOut ACK or a timeout. 1932 // the SwapOut ACK or a timeout.
1933 ASSERT_TRUE(rfh->IsRenderFrameLive()); 1933 ASSERT_TRUE(rfh->IsRenderFrameLive());
1934 ASSERT_FALSE(rfh->is_active()); 1934 ASSERT_FALSE(rfh->is_active());
1935 1935
1936 // We specifically want verify behavior between swap-out and RFH destruction. 1936 // We specifically want verify behavior between swap-out and RFH destruction.
1937 ASSERT_FALSE(rfh_observer.deleted()); 1937 ASSERT_FALSE(rfh_observer.deleted());
1938 1938
1939 EXPECT_FALSE(handler->IsJavascriptAllowed()); 1939 EXPECT_FALSE(handler->IsJavascriptAllowed());
1940 } 1940 }
1941 1941
1942 // Test for http://crbug.com/703303. Ensures that the renderer process does not
1943 // try to select files whose paths cannot be converted to WebStrings. This
1944 // check is done in the renderer because it is hard to predict which paths will
1945 // turn into empty WebStrings, and the behavior varies by platform.
1946 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, DontSelectInvalidFiles) {
1947 StartServer();
1948
1949 // Use a file path with an invalid encoding, such that it can't be converted
1950 // to a WebString (on all platforms but Windows).
1951 base::FilePath file;
1952 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file));
1953 file = file.Append(FILE_PATH_LITERAL("foo\337bar"));
1954
1955 // Navigate and try to get page to reference this file in its PageState.
1956 GURL url1(embedded_test_server()->GetURL("/file_input.html"));
1957 NavigateToURL(shell(), url1);
1958 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
1959 std::unique_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file));
1960 shell()->web_contents()->SetDelegate(delegate.get());
1961 EXPECT_TRUE(
1962 ExecuteScript(shell(), "document.getElementById('fileinput').click();"));
1963 EXPECT_TRUE(delegate->file_chosen());
1964
1965 // The browser process grants access to the file whether or not the renderer
1966 // process realizes that it can't use it. This is ok, since the user actually
1967 // did select the file from the chooser.
1968 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1969 process_id, file));
1970
1971 // Disable the swap out timer so we wait for the UpdateState message.
1972 static_cast<WebContentsImpl*>(shell()->web_contents())
1973 ->GetMainFrame()
1974 ->DisableSwapOutTimerForTesting();
1975
1976 // Navigate to a different process and wait for the old process to exit.
1977 RenderProcessHostWatcher exit_observer(
1978 shell()->web_contents()->GetRenderProcessHost(),
1979 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
1980 NavigateToURL(shell(), GetCrossSiteURL("/title1.html"));
1981 exit_observer.Wait();
1982 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
1983 shell()->web_contents()->GetRenderProcessHost()->GetID(), file));
1984
1985 // The renderer process should not have been killed. This is the important
1986 // part of the test. If this fails, then we didn't get a PageState to check
1987 // below, so use an assert (since the test can't meaningfully proceed).
1988 ASSERT_TRUE(exit_observer.did_exit_normally());
1989
1990 // Ensure that the file did not end up in the PageState of the previous entry,
1991 // except on Windows where the path is valid and WebString can handle it.
1992 NavigationEntry* prev_entry =
1993 shell()->web_contents()->GetController().GetEntryAtIndex(0);
1994 EXPECT_EQ(url1, prev_entry->GetURL());
1995 const std::vector<base::FilePath>& files =
1996 prev_entry->GetPageState().GetReferencedFiles();
1997 #if defined(OS_WIN)
1998 EXPECT_EQ(1U, files.size());
1999 #else
2000 EXPECT_EQ(0U, files.size());
2001 #endif
2002 }
2003
1942 // Test for http://crbug.com/262948. 2004 // Test for http://crbug.com/262948.
1943 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, 2005 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
1944 RestoreFileAccessForHistoryNavigation) { 2006 RestoreFileAccessForHistoryNavigation) {
1945 StartServer(); 2007 StartServer();
1946 base::FilePath file; 2008 base::FilePath file;
1947 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); 2009 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file));
1948 file = file.AppendASCII("bar"); 2010 file = file.AppendASCII("bar");
1949 2011
1950 // Navigate to url and get it to reference a file in its PageState. 2012 // Navigate to url and get it to reference a file in its PageState.
1951 GURL url1(embedded_test_server()->GetURL("/file_input.html")); 2013 GURL url1(embedded_test_server()->GetURL("/file_input.html"));
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 EXPECT_TRUE(ExecuteScript(grandchild, script)); 3385 EXPECT_TRUE(ExecuteScript(grandchild, script));
3324 observer.Wait(); 3386 observer.Wait();
3325 } 3387 }
3326 3388
3327 EXPECT_EQ(url, grandchild->current_url()); 3389 EXPECT_EQ(url, grandchild->current_url());
3328 ASSERT_EQ(1U, grandchild->child_count()); 3390 ASSERT_EQ(1U, grandchild->child_count());
3329 EXPECT_EQ(child_url, grandchild->child_at(0)->current_url()); 3391 EXPECT_EQ(child_url, grandchild->child_at(0)->current_url());
3330 } 3392 }
3331 3393
3332 } // namespace content 3394 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698