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

Unified Diff: chrome/browser/ui/views/select_file_dialog_extension_views_unittest.cc

Issue 10798011: views: Add a cross-platform SelectFileDialogExtension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/select_file_dialog_extension_views_unittest.cc
diff --git a/chrome/browser/ui/views/select_file_dialog_extension_views_unittest.cc b/chrome/browser/ui/views/select_file_dialog_extension_views_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d9ea3ca6a2ddd20fc915d8f9fd87e51a8904867b
--- /dev/null
+++ b/chrome/browser/ui/views/select_file_dialog_extension_views_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 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 "chrome/browser/ui/views/select_file_dialog_extension_views.h"
+
+#include "base/file_path.h"
+#include "ui/base/dialogs/selected_file_info.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class SelectFileDialogExtensionTest : public testing::Test {
+ public:
+ static SelectFileDialogExtension* CreateDialog(
+ SelectFileDialog::Listener* listener,
+ int32 tab_id) {
+ SelectFileDialogExtension* dialog = new SelectFileDialogExtension(listener,
+ NULL);
+ // Simulate the dialog opening.
+ EXPECT_FALSE(SelectFileDialogExtensionViews::PendingExists(tab_id));
+ dialog->AddPending(tab_id);
+ EXPECT_TRUE(SelectFileDialogExtensionViews::PendingExists(tab_id));
+ return dialog;
+ }
+};
+
+// Client of a FileManagerDialog that deletes itself whenever the dialog
+// is closed.
+class SelfDeletingClient : public SelectFileDialog::Listener {
+ public:
+ explicit SelfDeletingClient(int32 tab_id) {
+ dialog_ = SelectFileDialogExtensionTest::CreateDialog(this, tab_id);
+ }
+
+ virtual ~SelfDeletingClient() {
+ if (dialog_.get())
+ dialog_->ListenerDestroyed();
+ }
+
+ SelectFileDialogExtension* dialog() const { return dialog_.get(); }
+
+ // SelectFileDialog::Listener implementation
+ virtual void FileSelected(const FilePath& path,
+ int index, void* params) OVERRIDE {
+ delete this;
+ }
+
+ private:
+ scoped_refptr<SelectFileDialogExtension> dialog_;
+};
+
+TEST_F(SelectFileDialogExtensionTest, SelfDeleting) {
+ const int32 kTabId = 123;
+ SelfDeletingClient* client = new SelfDeletingClient(kTabId);
+ // Ensure we don't crash or trip an Address Sanitizer warning about
+ // use-after-free.
+ ui::SelectedFileInfo file_info;
+ SelectFileDialogExtensionViews::OnFileSelected(kTabId, file_info, 0);
+ // Simulate closing the dialog so the listener gets invoked.
+ client->dialog()->ExtensionDialogClosing(NULL);
+}
« no previous file with comments | « chrome/browser/ui/views/select_file_dialog_extension_views_browsertest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698