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

Side by Side Diff: chrome/browser/ui/libgtk2ui/select_file_dialog_impl_test.cc

Issue 1363093004: Add BrowserSelectFileDialogTest.OpenCloseFileDialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn and gyp files for chromeos Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "base/run_loop.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_window.h"
8 #include "chrome/browser/ui/chrome_select_file_policy.h"
9 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.h"
sky 2015/11/06 21:04:10 This should be the first include.
joone 2015/11/09 20:50:07 It causes a #include order problem.
10 #include "chrome/browser/ui/view_ids.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/interactive_test_utils.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h"
15 #include "ui/shell_dialogs/select_file_dialog.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_observer.h"
18 #include "url/gurl.h"
19
20
21 const char kSimplePage[] = "/focus/page_with_focus.html";
22
23 class BrowserSelectFileDialogTest : public InProcessBrowserTest {
sky 2015/11/06 21:04:10 Use a using statement.
joone 2015/11/09 20:50:07 Done.
24 };
25
26 // Spins a run loop until a Widget's activation reaches the desired state.
27 class WidgetActivationWaiter : public views::WidgetObserver {
28 public:
29 explicit WidgetActivationWaiter(views::Widget* widget, bool active)
sky 2015/11/06 21:04:10 no explicit
joone 2015/11/09 20:50:06 Done.
30 : observed_(false), active_(active) {
31 widget->AddObserver(this);
32 EXPECT_NE(active, widget->IsActive());
33 }
34
35 void Wait() {
36 if (!observed_)
37 run_loop_.Run();
38 }
39
40 void OnWidgetActivationChanged(views::Widget* widget, bool active) override {
sky 2015/11/06 21:04:10 prefix this with // views::WidgetObserver: and mov
joone 2015/11/09 20:50:07 Done.
41 if (active_ != active)
42 return;
43
44 observed_ = true;
45 widget->RemoveObserver(this);
46 if (run_loop_.running())
47 run_loop_.Quit();
48 }
49
50 private:
51 base::RunLoop run_loop_;
52 bool observed_;
53 bool active_;
54
55 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter);
56 };
57
58 namespace libgtk2ui {
59
60 class FilePicker: public ui::SelectFileDialog::Listener {
sky 2015/11/06 21:04:09 Add description.
sky 2015/11/06 21:04:10 'FilePicker:' => 'FilePicker :'
joone 2015/11/09 20:50:07 Done.
joone 2015/11/09 20:50:07 Done.
61 public:
62 explicit FilePicker(BrowserWindow* window) {
63 select_file_dialog_ = ui::SelectFileDialog::Create(
64 this, new ChromeSelectFilePolicy(NULL));
sky 2015/11/06 21:04:09 nullptr.
joone 2015/11/09 20:50:07 Done.
65
66 gfx::NativeWindow parent_window = window->GetNativeWindow();
67 ui::SelectFileDialog::FileTypeInfo file_types;
68 file_types.support_drive = true;
69 const base::FilePath file_path;
70 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
71 base::string16(),
72 file_path,
73 &file_types,
74 0,
75 base::FilePath::StringType(),
76 parent_window,
77 NULL);
78 }
79
80 ~FilePicker() override {
81 if (select_file_dialog_.get())
82 select_file_dialog_->ListenerDestroyed();
83 }
84
85 void Close() {
86 SelectFileDialogImplGTK* file_dialog =
87 static_cast<SelectFileDialogImplGTK*>(select_file_dialog_.get());
88
89 while (file_dialog->dialogs_.begin() != file_dialog->dialogs_.end()) {
sky 2015/11/06 21:04:09 nit: no {}
sky 2015/11/06 21:04:10 !dialogs_.empty().
joone 2015/11/09 20:50:07 Done.
joone 2015/11/09 20:50:07 Done.
90 gtk_widget_destroy(*(file_dialog->dialogs_.begin()));
91 }
92 }
93
94 // SelectFileDialog::Listener implementation.
95 void FileSelected(const base::FilePath& path,
96 int index,
97 void* params) override {}
98 private:
99 // Dialog box used for opening and saving files.
100 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
101
102 DISALLOW_COPY_AND_ASSIGN(FilePicker);
103 };
104
105 } // namespace libgtk2ui
106
107 IN_PROC_BROWSER_TEST_F(BrowserSelectFileDialogTest, OpenCloseFileDialog) {
sky 2015/11/06 21:04:10 Document what that test is asserting.
joone 2015/11/09 20:50:07 Done.
108 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
109 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
110
111 const GURL url = embedded_test_server()->GetURL(kSimplePage);
112 ui_test_utils::NavigateToURL(browser(), url);
sky 2015/11/06 21:04:10 Why do you need to navigate?
joone 2015/11/09 20:50:07 Without the page loading, the test works fine so I
113 ASSERT_TRUE(browser()->window()->IsActive());
114
115 // Leaks in GtkFileChooserDialog. http://crbug.com/537468
116 ANNOTATE_SCOPED_MEMORY_LEAK;
117 libgtk2ui::FilePicker file_picker(browser()->window());
118
119 gfx::NativeWindow window = browser()->window()->GetNativeWindow();
120 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
121 ASSERT_NE(nullptr, widget);
122
123 // Run a nested loop until the browser window becomes inactive.
sky 2015/11/06 21:04:10 Document why this is done.
joone 2015/11/09 20:50:07 Done.
124 WidgetActivationWaiter wait_inactive(widget, false);
125 wait_inactive.Wait();
126 EXPECT_FALSE(browser()->window()->IsActive());
127 file_picker.Close();
128
129 // Run a nested loop until the browser window becomes active.
130 WidgetActivationWaiter wait_active(widget, true);
131 wait_active.Wait();
132 EXPECT_TRUE(browser()->window()->IsActive());
133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698