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

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

Issue 2811533002: Exclude files from FileSelectChooser if they can't convert to WebStrings. (Closed)
Patch Set: Update comment. 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).
asanka 2017/04/20 03:05:11 Interesting. WebString allows invalid UTF-16? It'
Charlie Reis 2017/04/20 19:00:38 I was pretty surprised myself that WebString sent
asanka 2017/04/20 20:24:06 ------snip----- #include<windows.h> int main() {
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 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
3274 // than one ancestor has the same URL (excluding fragments), and the 3336 // than one ancestor has the same URL (excluding fragments), and the
3275 // navigating frame's current URL shouldn't count toward that. 3337 // navigating frame's current URL shouldn't count toward that.
3276 EXPECT_TRUE( 3338 EXPECT_TRUE(
3277 ExecuteScript(child, "location.href = '" + first_url.spec() + "';")); 3339 ExecuteScript(child, "location.href = '" + first_url.spec() + "';"));
3278 observer2.Wait(); 3340 observer2.Wait();
3279 3341
3280 EXPECT_EQ(child->current_url(), first_url); 3342 EXPECT_EQ(child->current_url(), first_url);
3281 } 3343 }
3282 3344
3283 } // namespace content 3345 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698