summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 21:19:27 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 21:19:27 +0000
commit3ca335b4eb7ecbe1fb2de5ecec2742e85d87d096 (patch)
tree4a53b7a92b5f1418c23195336e96e11be4b8a588
parenta91afcbaed24615861a2c2ddb61ce51827c17e6e (diff)
downloadchromium_src-3ca335b4eb7ecbe1fb2de5ecec2742e85d87d096.zip
chromium_src-3ca335b4eb7ecbe1fb2de5ecec2742e85d87d096.tar.gz
chromium_src-3ca335b4eb7ecbe1fb2de5ecec2742e85d87d096.tar.bz2
Add a basic FileBrowseUI browser test to verify <input type=file..> would bring up FileBrowseUI.
<http://crosbugs.com/2056> BUG=none TEST=none Review URL: http://codereview.chromium.org/1315003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42672 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/file_browse_browsertest.cc151
-rw-r--r--chrome/chrome_tests.gypi4
-rw-r--r--chrome/test/data/input_file.html6
3 files changed, 160 insertions, 1 deletions
diff --git a/chrome/browser/dom_ui/file_browse_browsertest.cc b/chrome/browser/dom_ui/file_browse_browsertest.cc
new file mode 100644
index 0000000..20ff287
--- /dev/null
+++ b/chrome/browser/dom_ui/file_browse_browsertest.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/task.h"
+#include "base/values.h"
+#include "base/path_service.h"
+#include "chrome/browser/dom_ui/dom_ui.h"
+#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/views/html_dialog_view.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+
+class FileBrowseBrowserTest : public InProcessBrowserTest {
+ public:
+ FileBrowseBrowserTest() {
+ EnableDOMAutomation();
+ }
+};
+
+class FileBrowseUiObserver : public NotificationObserver {
+ public:
+ FileBrowseUiObserver() : file_browse_tab_(NULL), is_waiting_(false) {
+ registrar_.Add(this, NotificationType::LOAD_STOP,
+ NotificationService::AllSources());
+ }
+
+ void WaitForFileBrowseLoad() {
+ if (file_browse_tab_ == NULL) {
+ is_waiting_ = true;
+ ui_test_utils::RunMessageLoop();
+ }
+ }
+
+ // File browse tab deletion is a non-nestable task and BrowserTest would
+ // not get related notification because test body runs in a task already.
+ // Uses a periodical check of the dialog window to implement the wait.
+ void WaitForFileBrowseClose() {
+ CheckFileBrowseClosed();
+
+ if (file_browse_tab_ != NULL) {
+ is_waiting_ = true;
+ ui_test_utils::RunMessageLoop();
+ }
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::LOAD_STOP) {
+ NavigationController* controller =
+ Source<NavigationController>(source).ptr();
+
+ if (controller) {
+ TabContents* tab_contents = controller->tab_contents();
+ if (tab_contents &&
+ tab_contents->GetURL().SchemeIs(chrome::kChromeUIScheme) &&
+ tab_contents->GetURL().host() == chrome::kChromeUIFileBrowseHost) {
+ file_browse_tab_ = tab_contents;
+
+ if (is_waiting_) {
+ is_waiting_ = false;
+ MessageLoopForUI::current()->Quit();
+ }
+ }
+ }
+ }
+ }
+
+ TabContents* file_browse_tab() {
+ return file_browse_tab_;
+ }
+
+ DOMUI* file_browse_ui() {
+ return file_browse_tab_ ? file_browse_tab_->render_manager()->dom_ui() :
+ NULL;
+ }
+
+ private:
+ class CheckFileBrowseClosedTask : public Task {
+ public:
+ explicit CheckFileBrowseClosedTask(FileBrowseUiObserver* owner)
+ : owner_(owner) {
+ }
+
+ virtual void Run() {
+ owner_->CheckFileBrowseClosed();
+ }
+
+ private:
+ FileBrowseUiObserver* owner_;
+ };
+
+ void CheckFileBrowseClosed() {
+ HtmlDialogView* dialog_view =
+ static_cast<HtmlDialogView*>(file_browse_tab_->delegate());
+
+ if (dialog_view->native_view()) {
+ MessageLoopForUI::current()->PostDelayedTask(
+ FROM_HERE, new CheckFileBrowseClosedTask(this), 100);
+ } else {
+ file_browse_tab_ = NULL;
+
+ if (is_waiting_) {
+ is_waiting_ = false;
+ MessageLoopForUI::current()->Quit();
+ }
+ }
+ }
+
+ NotificationRegistrar registrar_;
+ TabContents* file_browse_tab_;
+ bool is_waiting_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileBrowseUiObserver);
+};
+
+IN_PROC_BROWSER_TEST_F(FileBrowseBrowserTest, InputFileTriggerFileBrowse) {
+ HTTPTestServer* server = StartHTTPServer();
+ ui_test_utils::NavigateToURL(browser(),
+ server->TestServerPage("files/input_file.html"));
+
+ DOMElementProxyRef doc = ui_test_utils::GetActiveDOMDocument(browser());
+
+ DOMElementProxyRef input_file = doc->FindBySelectors(".single");
+ ASSERT_TRUE(input_file);
+
+ // Creates FileBrowseUiObserver before we click.
+ FileBrowseUiObserver observer;
+
+ // Click on the input control. This should bring up the FileBrowseUI.
+ input_file->Click();
+
+ observer.WaitForFileBrowseLoad();
+ DOMUI* file_browser_ui = observer.file_browse_ui();
+ ASSERT_TRUE(file_browser_ui);
+
+ file_browser_ui->CallJavascriptFunction(L"dialogCancelClick");
+
+ observer.WaitForFileBrowseClose();
+}
+
+} // namespace
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index b8db1cb..33cf940 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1218,6 +1218,7 @@
'browser/chromeos/notifications/notification_browsertest.cc',
'browser/chromeos/login/wizard_controller_browsertest.cc',
'browser/crash_recovery_browsertest.cc',
+ 'browser/dom_ui/file_browse_browsertest.cc',
'browser/dom_ui/mediaplayer_browsertest.cc',
'browser/download/save_page_browsertest.cc',
'browser/extensions/autoupdate_interceptor.cc',
@@ -1279,7 +1280,8 @@
['chromeos==0', {
'sources/': [
['exclude', '^browser/chromeos'],
- ['exclude', 'browser/dom_ui/mediaplayer_browsertest.cc'],
+ ['exclude', '^browser/dom_ui/mediaplayer_browsertest.cc'],
+ ['exclude', '^browser/dom_ui/file_browse_browsertest.cc'],
],
}],
['OS=="win"', {
diff --git a/chrome/test/data/input_file.html b/chrome/test/data/input_file.html
new file mode 100644
index 0000000..bd1d86b
--- /dev/null
+++ b/chrome/test/data/input_file.html
@@ -0,0 +1,6 @@
+<html>
+ <body>
+ <input class=single type=file>
+ <input class=multi type=file multiple>
+ </body>
+</html>