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

Side by Side Diff: chrome/browser/ui/views/select_file_dialog_extension_browsertest.cc

Issue 902493002: Fix flakiness of SelectFileDialogExtensionBrowserTest.SelectFileAndCancel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/chromeos/file_manager/volume_manager.h" 16 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
17 #include "chrome/browser/extensions/component_loader.h" 17 #include "chrome/browser/extensions/component_loader.h"
18 #include "chrome/browser/extensions/extension_browsertest.h" 18 #include "chrome/browser/extensions/extension_browsertest.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
29 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
30 #include "extensions/test/extension_test_message_listener.h" 28 #include "extensions/test/extension_test_message_listener.h"
31 #include "ui/shell_dialogs/select_file_dialog.h" 29 #include "ui/shell_dialogs/select_file_dialog.h"
32 #include "ui/shell_dialogs/selected_file_info.h" 30 #include "ui/shell_dialogs/selected_file_info.h"
33 31
34 using content::BrowserContext; 32 using content::BrowserContext;
35 33
36 // Mock listener used by test below. 34 // Mock listener used by test below.
(...skipping 10 matching lines...) Expand all
47 base::FilePath path() const { return path_; } 45 base::FilePath path() const { return path_; }
48 void* params() const { return params_; } 46 void* params() const { return params_; }
49 47
50 // ui::SelectFileDialog::Listener implementation. 48 // ui::SelectFileDialog::Listener implementation.
51 void FileSelected(const base::FilePath& path, 49 void FileSelected(const base::FilePath& path,
52 int index, 50 int index,
53 void* params) override { 51 void* params) override {
54 file_selected_ = true; 52 file_selected_ = true;
55 path_ = path; 53 path_ = path;
56 params_ = params; 54 params_ = params;
55 QuitMessageLoop();
57 } 56 }
58 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& selected_file_info, 57 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& selected_file_info,
59 int index, 58 int index,
60 void* params) override { 59 void* params) override {
61 FileSelected(selected_file_info.local_path, index, params); 60 FileSelected(selected_file_info.local_path, index, params);
62 } 61 }
63 void MultiFilesSelected(const std::vector<base::FilePath>& files, 62 void MultiFilesSelected(const std::vector<base::FilePath>& files,
64 void* params) override {} 63 void* params) override {
64 QuitMessageLoop();
65 }
65 void FileSelectionCanceled(void* params) override { 66 void FileSelectionCanceled(void* params) override {
66 canceled_ = true; 67 canceled_ = true;
67 params_ = params; 68 params_ = params;
69 QuitMessageLoop();
70 }
71
72 void WaitForCalled() {
73 message_loop_runner_ = new content::MessageLoopRunner();
74 message_loop_runner_->Run();
68 } 75 }
69 76
70 private: 77 private:
78 void QuitMessageLoop() {
79 if (message_loop_runner_.get())
80 message_loop_runner_->Quit();
81 }
82
71 bool file_selected_; 83 bool file_selected_;
72 bool canceled_; 84 bool canceled_;
73 base::FilePath path_; 85 base::FilePath path_;
74 void* params_; 86 void* params_;
87 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
75 88
76 DISALLOW_COPY_AND_ASSIGN(MockSelectFileDialogListener); 89 DISALLOW_COPY_AND_ASSIGN(MockSelectFileDialogListener);
77 }; 90 };
78 91
79 class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest { 92 class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest {
80 public: 93 public:
81 enum DialogButtonType { 94 enum DialogButtonType {
82 DIALOG_BTN_OK, 95 DIALOG_BTN_OK,
83 DIALOG_BTN_CANCEL 96 DIALOG_BTN_CANCEL
84 }; 97 };
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 0 /* file_type_index */, 196 0 /* file_type_index */,
184 FILE_PATH_LITERAL("") /* default_extension */, 197 FILE_PATH_LITERAL("") /* default_extension */,
185 owning_window, 198 owning_window,
186 this /* params */); 199 this /* params */);
187 } 200 }
188 201
189 void CloseDialog(DialogButtonType button_type, 202 void CloseDialog(DialogButtonType button_type,
190 const gfx::NativeWindow& owning_window) { 203 const gfx::NativeWindow& owning_window) {
191 // Inject JavaScript to click the cancel button and wait for notification 204 // Inject JavaScript to click the cancel button and wait for notification
192 // that the window has closed. 205 // that the window has closed.
193 content::WindowedNotificationObserver host_destroyed(
194 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
195 content::NotificationService::AllSources());
196 content::RenderViewHost* host = dialog_->GetRenderViewHost(); 206 content::RenderViewHost* host = dialog_->GetRenderViewHost();
197 std::string button_class = 207 std::string button_class =
198 (button_type == DIALOG_BTN_OK) ? ".button-panel .ok" : 208 (button_type == DIALOG_BTN_OK) ? ".button-panel .ok" :
199 ".button-panel .cancel"; 209 ".button-panel .cancel";
200 base::string16 script = base::ASCIIToUTF16( 210 base::string16 script = base::ASCIIToUTF16(
201 "console.log(\'Test JavaScript injected.\');" 211 "console.log(\'Test JavaScript injected.\');"
202 "document.querySelector(\'" + button_class + "\').click();"); 212 "document.querySelector(\'" + button_class + "\').click();");
203 // The file selection handler closes the dialog and does not return control 213 // The file selection handler closes the dialog and does not return control
204 // to JavaScript, so do not wait for return values. 214 // to JavaScript, so do not wait for return values.
205 host->GetMainFrame()->ExecuteJavaScript(script); 215 host->GetMainFrame()->ExecuteJavaScript(script);
206 LOG(INFO) << "Waiting for window close notification."; 216 LOG(INFO) << "Waiting for window close notification.";
207 host_destroyed.Wait(); 217 listener_->WaitForCalled();
208 218
209 // Dialog no longer believes it is running. 219 // Dialog no longer believes it is running.
210 ASSERT_FALSE(dialog_->IsRunning(owning_window)); 220 ASSERT_FALSE(dialog_->IsRunning(owning_window));
211 } 221 }
212 222
213 scoped_ptr<MockSelectFileDialogListener> listener_; 223 scoped_ptr<MockSelectFileDialogListener> listener_;
214 scoped_refptr<SelectFileDialogExtension> dialog_; 224 scoped_refptr<SelectFileDialogExtension> dialog_;
215 225
216 scoped_ptr<MockSelectFileDialogListener> second_listener_; 226 scoped_ptr<MockSelectFileDialogListener> second_listener_;
217 scoped_refptr<SelectFileDialogExtension> second_dialog_; 227 scoped_refptr<SelectFileDialogExtension> second_dialog_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); 366 ASSERT_FALSE(second_dialog_->IsRunning(owning_window));
357 367
358 // Click cancel button. 368 // Click cancel button.
359 CloseDialog(DIALOG_BTN_CANCEL, owning_window); 369 CloseDialog(DIALOG_BTN_CANCEL, owning_window);
360 370
361 // Listener should have been informed of the cancellation. 371 // Listener should have been informed of the cancellation.
362 ASSERT_FALSE(listener_->file_selected()); 372 ASSERT_FALSE(listener_->file_selected());
363 ASSERT_TRUE(listener_->canceled()); 373 ASSERT_TRUE(listener_->canceled());
364 ASSERT_EQ(this, listener_->params()); 374 ASSERT_EQ(this, listener_->params());
365 } 375 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698