| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/select_file_dialog_extension.h" | 5 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 class SelectFileDialogExtensionTest : public testing::Test { | 10 class SelectFileDialogExtensionTest : public testing::Test { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 explicit SelfDeletingClient(int32 tab_id) { | 28 explicit SelfDeletingClient(int32 tab_id) { |
| 29 dialog_ = SelectFileDialogExtensionTest::CreateDialog(this, tab_id); | 29 dialog_ = SelectFileDialogExtensionTest::CreateDialog(this, tab_id); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual ~SelfDeletingClient() { | 32 virtual ~SelfDeletingClient() { |
| 33 if (dialog_.get()) | 33 if (dialog_.get()) |
| 34 dialog_->ListenerDestroyed(); | 34 dialog_->ListenerDestroyed(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 SelectFileDialogExtension* dialog() const { return dialog_.get(); } |
| 38 |
| 37 // SelectFileDialog::Listener implementation | 39 // SelectFileDialog::Listener implementation |
| 38 virtual void FileSelected(const FilePath& path, | 40 virtual void FileSelected(const FilePath& path, |
| 39 int index, void* params) OVERRIDE { | 41 int index, void* params) OVERRIDE { |
| 40 delete this; | 42 delete this; |
| 41 } | 43 } |
| 42 | 44 |
| 43 private: | 45 private: |
| 44 scoped_refptr<SelectFileDialogExtension> dialog_; | 46 scoped_refptr<SelectFileDialogExtension> dialog_; |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 TEST_F(SelectFileDialogExtensionTest, SelfDeleting) { | 49 TEST_F(SelectFileDialogExtensionTest, SelfDeleting) { |
| 48 const int32 kTabId = 123; | 50 const int32 kTabId = 123; |
| 49 // Registers itself with an internal map, so we don't need the pointer, | 51 SelfDeletingClient* client = new SelfDeletingClient(kTabId); |
| 50 // and it would be unused anyway. | |
| 51 new SelfDeletingClient(kTabId); | |
| 52 // Ensure we don't crash or trip an Address Sanitizer warning about | 52 // Ensure we don't crash or trip an Address Sanitizer warning about |
| 53 // use-after-free. | 53 // use-after-free. |
| 54 SelectFileDialogExtension::OnFileSelected(kTabId, FilePath(), 0); | 54 SelectFileDialogExtension::OnFileSelected(kTabId, FilePath(), 0); |
| 55 // Simulate closing the dialog so the listener gets invoked. |
| 56 client->dialog()->ExtensionDialogClosing(NULL); |
| 55 } | 57 } |
| OLD | NEW |