Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/path_service.h" |
| 6 | #include "content/browser/web_contents/web_contents_impl.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 7 | #include "content/public/test/browser_test.h" |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 8 | #include "content/public/test/content_browser_test.h" |
| 9 | #include "content/public/test/content_browser_test_utils.h" |
| 10 | #include "content/shell/browser/shell.h" |
| 11 | #include "content/test/content_browser_test_utils_internal.h" |
| 12 | |
| 13 | namespace content { |
| 14 | |
| 15 | // This browser test is aimed towards exercising the FileAPI bindings and |
| 16 | // the actual implementation that lives in the browser side. |
Lei Zhang | 65ab6da0 | 2025-07-24 23:24:09 | [diff] [blame] | 17 | using FileAPIBrowserTest = ContentBrowserTest; |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 18 | |
| 19 | IN_PROC_BROWSER_TEST_F(FileAPIBrowserTest, FileInputChooserParams) { |
| 20 | base::FilePath file; |
Avi Drissman | 1cb5e9f | 2018-05-01 15:53:28 | [diff] [blame] | 21 | EXPECT_TRUE(base::PathService::Get(base::DIR_TEMP, &file)); |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 22 | file = file.AppendASCII("bar"); |
| 23 | |
Alex Moshchuk | aeb20fe3 | 2019-09-25 17:40:01 | [diff] [blame] | 24 | EXPECT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "file_input.html"))); |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 25 | |
| 26 | // Click on the <input type=file> element to launch the file upload picker. |
| 27 | { |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 28 | base::RunLoop run_loop; |
Lei Zhang | 65ab6da0 | 2025-07-24 23:24:09 | [diff] [blame] | 29 | FileChooserDelegate delegate(file, run_loop.QuitClosure()); |
| 30 | shell()->web_contents()->SetDelegate(&delegate); |
Avi Drissman | c91bd8e | 2021-04-19 23:58:44 | [diff] [blame] | 31 | EXPECT_TRUE( |
| 32 | ExecJs(shell(), "document.getElementById('fileinput').click();")); |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 33 | run_loop.Run(); |
Lei Zhang | 65ab6da0 | 2025-07-24 23:24:09 | [diff] [blame] | 34 | EXPECT_TRUE(delegate.params().default_file_name.empty()); |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // Click again, to verify what state was maintained and what was not. |
| 38 | // The renderer is expected not to specify a default file name; it's up to |
| 39 | // the browser to remember the last selected directory in the profile. |
| 40 | { |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 41 | base::RunLoop run_loop; |
Lei Zhang | 65ab6da0 | 2025-07-24 23:24:09 | [diff] [blame] | 42 | FileChooserDelegate delegate(file, run_loop.QuitClosure()); |
| 43 | shell()->web_contents()->SetDelegate(&delegate); |
Avi Drissman | c91bd8e | 2021-04-19 23:58:44 | [diff] [blame] | 44 | EXPECT_TRUE( |
| 45 | ExecJs(shell(), "document.getElementById('fileinput').click();")); |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 46 | run_loop.Run(); |
Lei Zhang | 65ab6da0 | 2025-07-24 23:24:09 | [diff] [blame] | 47 | EXPECT_TRUE(delegate.params().default_file_name.empty()); |
jsbell | 14785d90 | 2016-10-26 21:37:26 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | } // namespace content |