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

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

Issue 1462903004: Add test infrastructure for the file-picker modal test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.h"
6
7 #include "base/run_loop.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/chrome_select_file_policy.h"
11 #include "chrome/browser/ui/view_ids.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "ui/shell_dialogs/select_file_dialog.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_observer.h"
19
20 using BrowserSelectFileDialogTest = InProcessBrowserTest;
21
22 // Spins a run loop until a Widget's activation reaches the desired state.
23 class WidgetActivationWaiter : public views::WidgetObserver {
24 public:
25 WidgetActivationWaiter(views::Widget* widget, bool active)
26 : observed_(false), active_(active) {
27 widget->AddObserver(this);
28 EXPECT_NE(active, widget->IsActive());
29 }
30
31 void Wait() {
32 if (!observed_)
33 run_loop_.Run();
34 }
35
36 private:
37 // views::WidgetObserver:
38 void OnWidgetActivationChanged(views::Widget* widget, bool active) override {
39 if (active_ != active)
40 return;
41
42 observed_ = true;
43 widget->RemoveObserver(this);
44 if (run_loop_.running())
45 run_loop_.Quit();
46 }
47
48 base::RunLoop run_loop_;
49 bool observed_;
50 bool active_;
51
52 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter);
53 };
54
55 namespace libgtk2ui {
56
57 // FilePicker opens a GtkFileChooser.
58 class FilePicker : public ui::SelectFileDialog::Listener {
59 public:
60 explicit FilePicker(BrowserWindow* window) {
61 select_file_dialog_ = ui::SelectFileDialog::Create(
62 this, new ChromeSelectFilePolicy(nullptr));
63
64 gfx::NativeWindow parent_window = window->GetNativeWindow();
65 ui::SelectFileDialog::FileTypeInfo file_types;
66 file_types.support_drive = true;
67 const base::FilePath file_path;
68 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
69 base::string16(),
70 file_path,
71 &file_types,
72 0,
73 base::FilePath::StringType(),
74 parent_window,
75 nullptr);
76 }
77
78 ~FilePicker() override {
79 select_file_dialog_->ListenerDestroyed();
80 }
81
82 void Close() {
83 SelectFileDialogImplGTK* file_dialog =
84 static_cast<SelectFileDialogImplGTK*>(select_file_dialog_.get());
85
86
87 while (!file_dialog->dialogs_.empty())
88 gtk_widget_destroy(*(file_dialog->dialogs_.begin()));
89 }
90
91 // SelectFileDialog::Listener implementation.
92 void FileSelected(const base::FilePath& path,
93 int index,
94 void* params) override {}
95 private:
96 // Dialog box used for opening and saving files.
97 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
98
99 DISALLOW_COPY_AND_ASSIGN(FilePicker);
100 };
101
102 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698