Commit 84188d7c authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Test opening the extension dialog from web page file <input> element

FilesApp provides the innards of the extension file dialog. Add a test
to open the file dialog by clicking on an <input type=file> element in
a web page.

Bug: 895703
Change-Id: Id6f56e2df4034af66a57f888195bc841a55da2b4
Reviewed-on: https://chromium-review.googlesource.com/c/1331099
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607470}
parent c3a9ed64
......@@ -30,6 +30,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
......@@ -37,6 +38,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/keyboard/public/keyboard_switches.h"
#include "ui/shell_dialogs/select_file_dialog.h"
......@@ -365,10 +367,6 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
ASSERT_FALSE(OpenDialogIsResizable());
}
// TODO(jamescook): Add a test for selecting a file for an <input type='file'/>
// page element, as that uses different memory management pathways.
// crbug.com/98791
IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
SelectFileAndCancel) {
gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow();
......@@ -514,3 +512,36 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, OpenTwoDialogs) {
ASSERT_TRUE(listener_->canceled());
ASSERT_EQ(this, listener_->params());
}
IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, FileInputElement) {
gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow();
ASSERT_NE(nullptr, owning_window);
// Start the embedded test server.
base::FilePath source_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &source_dir));
auto test_data_dir = source_dir.AppendASCII("chrome")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII("chromeos")
.AppendASCII("file_manager");
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
ASSERT_TRUE(embedded_test_server()->Start());
// Navigate the browser to the file input element test page.
const GURL url = embedded_test_server()->GetURL("/file_input/element.html");
ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_EQ(url, web_contents->GetLastCommittedURL());
// Create a listener for the file dialog's "ready" message.
ExtensionTestMessageListener listener("ready", false);
// Click the file <input> element to open the file dialog.
constexpr auto kButton = blink::WebMouseEvent::Button::kLeft;
content::SimulateMouseClickAt(web_contents, 0, kButton, gfx::Point(0, 0));
// Wait for file dialog's "ready" message.
EXPECT_TRUE(listener.WaitUntilSatisfied());
}
<!doctype html>
<html>
<head>
<style>
html, body, input { margin: 0px; padding: 0px }
</style>
</head>
<body>
<input type="file" name="file-input-element">
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment