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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
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 "chrome/browser/ui/views/select_file_dialog_extension_views.h"
6
7 #include "base/file_path.h"
8 #include "ui/base/dialogs/selected_file_info.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 class SelectFileDialogExtensionTest : public testing::Test {
12 public:
13 static SelectFileDialogExtension* CreateDialog(
14 SelectFileDialog::Listener* listener,
15 int32 tab_id) {
16 SelectFileDialogExtension* dialog = new SelectFileDialogExtension(listener,
17 NULL);
18 // Simulate the dialog opening.
19 EXPECT_FALSE(SelectFileDialogExtensionViews::PendingExists(tab_id));
20 dialog->AddPending(tab_id);
21 EXPECT_TRUE(SelectFileDialogExtensionViews::PendingExists(tab_id));
22 return dialog;
23 }
24 };
25
26 // Client of a FileManagerDialog that deletes itself whenever the dialog
27 // is closed.
28 class SelfDeletingClient : public SelectFileDialog::Listener {
29 public:
30 explicit SelfDeletingClient(int32 tab_id) {
31 dialog_ = SelectFileDialogExtensionTest::CreateDialog(this, tab_id);
32 }
33
34 virtual ~SelfDeletingClient() {
35 if (dialog_.get())
36 dialog_->ListenerDestroyed();
37 }
38
39 SelectFileDialogExtension* dialog() const { return dialog_.get(); }
40
41 // SelectFileDialog::Listener implementation
42 virtual void FileSelected(const FilePath& path,
43 int index, void* params) OVERRIDE {
44 delete this;
45 }
46
47 private:
48 scoped_refptr<SelectFileDialogExtension> dialog_;
49 };
50
51 TEST_F(SelectFileDialogExtensionTest, SelfDeleting) {
52 const int32 kTabId = 123;
53 SelfDeletingClient* client = new SelfDeletingClient(kTabId);
54 // Ensure we don't crash or trip an Address Sanitizer warning about
55 // use-after-free.
56 ui::SelectedFileInfo file_info;
57 SelectFileDialogExtensionViews::OnFileSelected(kTabId, file_info, 0);
58 // Simulate closing the dialog so the listener gets invoked.
59 client->dialog()->ExtensionDialogClosing(NULL);
60 }
OLDNEW
« 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