| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/shell_dialogs/selected_file_info.h" | 10 #include "ui/shell_dialogs/selected_file_info.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void* params) override { | 82 void* params) override { |
| 83 delete this; | 83 delete this; |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 scoped_refptr<SelectFileDialogExtension> dialog_; | 87 scoped_refptr<SelectFileDialogExtension> dialog_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 TEST_F(SelectFileDialogExtensionTest, FileSelected) { | 90 TEST_F(SelectFileDialogExtensionTest, FileSelected) { |
| 91 const int kFileIndex = 5; | 91 const int kFileIndex = 5; |
| 92 scoped_ptr<TestListener> listener(new TestListener); | 92 std::unique_ptr<TestListener> listener(new TestListener); |
| 93 scoped_refptr<SelectFileDialogExtension> dialog = | 93 scoped_refptr<SelectFileDialogExtension> dialog = |
| 94 CreateDialog(listener.get()); | 94 CreateDialog(listener.get()); |
| 95 // Simulate selecting a file. | 95 // Simulate selecting a file. |
| 96 ui::SelectedFileInfo info; | 96 ui::SelectedFileInfo info; |
| 97 SelectFileDialogExtension::OnFileSelected(kDefaultRoutingID, info, | 97 SelectFileDialogExtension::OnFileSelected(kDefaultRoutingID, info, |
| 98 kFileIndex); | 98 kFileIndex); |
| 99 // Simulate closing the dialog so the listener gets invoked. | 99 // Simulate closing the dialog so the listener gets invoked. |
| 100 dialog->ExtensionDialogClosing(NULL); | 100 dialog->ExtensionDialogClosing(NULL); |
| 101 EXPECT_TRUE(listener->selected()); | 101 EXPECT_TRUE(listener->selected()); |
| 102 EXPECT_EQ(kFileIndex, listener->file_index()); | 102 EXPECT_EQ(kFileIndex, listener->file_index()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(SelectFileDialogExtensionTest, FileSelectionCanceled) { | 105 TEST_F(SelectFileDialogExtensionTest, FileSelectionCanceled) { |
| 106 scoped_ptr<TestListener> listener(new TestListener); | 106 std::unique_ptr<TestListener> listener(new TestListener); |
| 107 scoped_refptr<SelectFileDialogExtension> dialog = | 107 scoped_refptr<SelectFileDialogExtension> dialog = |
| 108 CreateDialog(listener.get()); | 108 CreateDialog(listener.get()); |
| 109 // Simulate cancelling the dialog. | 109 // Simulate cancelling the dialog. |
| 110 SelectFileDialogExtension::OnFileSelectionCanceled(kDefaultRoutingID); | 110 SelectFileDialogExtension::OnFileSelectionCanceled(kDefaultRoutingID); |
| 111 // Simulate closing the dialog so the listener gets invoked. | 111 // Simulate closing the dialog so the listener gets invoked. |
| 112 dialog->ExtensionDialogClosing(NULL); | 112 dialog->ExtensionDialogClosing(NULL); |
| 113 EXPECT_FALSE(listener->selected()); | 113 EXPECT_FALSE(listener->selected()); |
| 114 EXPECT_EQ(-1, listener->file_index()); | 114 EXPECT_EQ(-1, listener->file_index()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST_F(SelectFileDialogExtensionTest, SelfDeleting) { | 117 TEST_F(SelectFileDialogExtensionTest, SelfDeleting) { |
| 118 SelfDeletingClient* client = new SelfDeletingClient(); | 118 SelfDeletingClient* client = new SelfDeletingClient(); |
| 119 // Ensure we don't crash or trip an Address Sanitizer warning about | 119 // Ensure we don't crash or trip an Address Sanitizer warning about |
| 120 // use-after-free. | 120 // use-after-free. |
| 121 ui::SelectedFileInfo file_info; | 121 ui::SelectedFileInfo file_info; |
| 122 SelectFileDialogExtension::OnFileSelected(kDefaultRoutingID, file_info, 0); | 122 SelectFileDialogExtension::OnFileSelected(kDefaultRoutingID, file_info, 0); |
| 123 // Simulate closing the dialog so the listener gets invoked. | 123 // Simulate closing the dialog so the listener gets invoked. |
| 124 client->dialog()->ExtensionDialogClosing(NULL); | 124 client->dialog()->ExtensionDialogClosing(NULL); |
| 125 } | 125 } |
| OLD | NEW |