blob: 17c05835a67b1122630690bbd4f9c3211a261e6c [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2016 The Chromium Authors
jsbell14785d902016-10-26 21:37:262// 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 Kasting919ce652020-05-07 10:22:367#include "content/public/test/browser_test.h"
jsbell14785d902016-10-26 21:37:268#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
13namespace 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 Zhang65ab6da02025-07-24 23:24:0917using FileAPIBrowserTest = ContentBrowserTest;
jsbell14785d902016-10-26 21:37:2618
19IN_PROC_BROWSER_TEST_F(FileAPIBrowserTest, FileInputChooserParams) {
20 base::FilePath file;
Avi Drissman1cb5e9f2018-05-01 15:53:2821 EXPECT_TRUE(base::PathService::Get(base::DIR_TEMP, &file));
jsbell14785d902016-10-26 21:37:2622 file = file.AppendASCII("bar");
23
Alex Moshchukaeb20fe32019-09-25 17:40:0124 EXPECT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "file_input.html")));
jsbell14785d902016-10-26 21:37:2625
26 // Click on the <input type=file> element to launch the file upload picker.
27 {
Kent Tamura8c9e0562018-11-06 07:02:1928 base::RunLoop run_loop;
Lei Zhang65ab6da02025-07-24 23:24:0929 FileChooserDelegate delegate(file, run_loop.QuitClosure());
30 shell()->web_contents()->SetDelegate(&delegate);
Avi Drissmanc91bd8e2021-04-19 23:58:4431 EXPECT_TRUE(
32 ExecJs(shell(), "document.getElementById('fileinput').click();"));
Kent Tamura8c9e0562018-11-06 07:02:1933 run_loop.Run();
Lei Zhang65ab6da02025-07-24 23:24:0934 EXPECT_TRUE(delegate.params().default_file_name.empty());
jsbell14785d902016-10-26 21:37:2635 }
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 Tamura8c9e0562018-11-06 07:02:1941 base::RunLoop run_loop;
Lei Zhang65ab6da02025-07-24 23:24:0942 FileChooserDelegate delegate(file, run_loop.QuitClosure());
43 shell()->web_contents()->SetDelegate(&delegate);
Avi Drissmanc91bd8e2021-04-19 23:58:4444 EXPECT_TRUE(
45 ExecJs(shell(), "document.getElementById('fileinput').click();"));
Kent Tamura8c9e0562018-11-06 07:02:1946 run_loop.Run();
Lei Zhang65ab6da02025-07-24 23:24:0947 EXPECT_TRUE(delegate.params().default_file_name.empty());
jsbell14785d902016-10-26 21:37:2648 }
49}
50
51} // namespace content