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

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

Issue 7528003: CrOS - Fix flaky FileManagerDialogTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename message to worker-initialized Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/js/metadata_dispatcher.js ('k') | 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) 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/file_manager_dialog.h" 5 #include "chrome/browser/ui/views/file_manager_dialog.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ASSERT_FALSE(dialog_->IsRunning(native_window)); 101 ASSERT_FALSE(dialog_->IsRunning(native_window));
102 } 102 }
103 103
104 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, FileManagerDestroyListener) { 104 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, FileManagerDestroyListener) {
105 // Some users of SelectFileDialog destroy their listener before cleaning 105 // Some users of SelectFileDialog destroy their listener before cleaning
106 // up the dialog. Make sure we don't crash. 106 // up the dialog. Make sure we don't crash.
107 dialog_->ListenerDestroyed(); 107 dialog_->ListenerDestroyed();
108 listener_.reset(); 108 listener_.reset();
109 } 109 }
110 110
111 // Flaky: http://crbug.com/89733 111 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, SelectFileAndCancel) {
112 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, FLAKY_SelectFileAndCancel) {
113 // Add tmp mount point even though this test won't use it directly. 112 // Add tmp mount point even though this test won't use it directly.
114 // We need this to make sure that at least one top-level directory exists 113 // We need this to make sure that at least one top-level directory exists
115 // in the file browser. 114 // in the file browser.
116 FilePath tmp_dir("/tmp"); 115 FilePath tmp_dir("/tmp");
117 AddMountPoint(tmp_dir); 116 AddMountPoint(tmp_dir);
118 117
119 // Spawn a dialog to open a file. The dialog will signal that it is done 118 // Spawn a dialog to open a file. The dialog will signal that it is ready
120 // loading via chrome.test.sendMessage('ready') in the extension JavaScript. 119 // via chrome.test.sendMessage() in the extension JavaScript.
121 ExtensionTestMessageListener msg_listener("ready", false /* will_reply */); 120 ExtensionTestMessageListener init_listener("worker-initialized",
121 false /* will_reply */);
122 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); 122 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle();
123 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 123 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
124 string16() /* title */, 124 string16() /* title */,
125 FilePath() /* default_path */, 125 FilePath() /* default_path */,
126 NULL /* file_types */, 126 NULL /* file_types */,
127 0 /* file_type_index */, 127 0 /* file_type_index */,
128 FILE_PATH_LITERAL("") /* default_extension */, 128 FILE_PATH_LITERAL("") /* default_extension */,
129 NULL /* source_contents */, 129 NULL /* source_contents */,
130 owning_window, 130 owning_window,
131 this /* params */); 131 this /* params */);
132 LOG(INFO) << "Waiting for JavaScript ready message."; 132 LOG(INFO) << "Waiting for JavaScript ready message.";
133 ASSERT_TRUE(msg_listener.WaitUntilSatisfied()); 133 ASSERT_TRUE(init_listener.WaitUntilSatisfied());
134 134
135 // Dialog should be running now. 135 // Dialog should be running now.
136 ASSERT_TRUE(dialog_->IsRunning(owning_window)); 136 ASSERT_TRUE(dialog_->IsRunning(owning_window));
137 137
138 // Inject JavaScript to click the cancel button and wait for notification 138 // Inject JavaScript to click the cancel button and wait for notification
139 // that the window has closed. 139 // that the window has closed.
140 ui_test_utils::WindowedNotificationObserver host_destroyed( 140 ui_test_utils::WindowedNotificationObserver host_destroyed(
141 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 141 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
142 NotificationService::AllSources()); 142 NotificationService::AllSources());
143 RenderViewHost* host = dialog_->GetRenderViewHost(); 143 RenderViewHost* host = dialog_->GetRenderViewHost();
(...skipping 30 matching lines...) Expand all
174 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); 174 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html");
175 175
176 // Create an empty file to give us something to select. 176 // Create an empty file to give us something to select.
177 FILE* fp = file_util::OpenFile(test_file, "w"); 177 FILE* fp = file_util::OpenFile(test_file, "w");
178 ASSERT_TRUE(fp != NULL); 178 ASSERT_TRUE(fp != NULL);
179 ASSERT_TRUE(file_util::CloseFile(fp)); 179 ASSERT_TRUE(file_util::CloseFile(fp));
180 180
181 // Spawn a dialog to open a file. Provide the path to the file so the dialog 181 // Spawn a dialog to open a file. Provide the path to the file so the dialog
182 // will automatically select it. Ensure that the OK button is enabled by 182 // will automatically select it. Ensure that the OK button is enabled by
183 // waiting for chrome.test.sendMessage('selection-change-complete'). 183 // waiting for chrome.test.sendMessage('selection-change-complete').
184 ExtensionTestMessageListener msg_listener("selection-change-complete", 184 // The extension starts a Web Worker to read file metadata, so it may send
185 false /* will_reply */); 185 // 'selection-change-complete' before 'worker-initialized'. This is OK.
186 ExtensionTestMessageListener init_listener("worker-initialized",
187 false /* will_reply */);
188 ExtensionTestMessageListener selection_listener("selection-change-complete",
189 false /* will_reply */);
186 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); 190 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle();
187 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 191 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
188 string16() /* title */, 192 string16() /* title */,
189 test_file, 193 test_file,
190 NULL /* file_types */, 194 NULL /* file_types */,
191 0 /* file_type_index */, 195 0 /* file_type_index */,
192 FILE_PATH_LITERAL("") /* default_extension */, 196 FILE_PATH_LITERAL("") /* default_extension */,
193 NULL /* source_contents */, 197 NULL /* source_contents */,
194 owning_window, 198 owning_window,
195 this /* params */); 199 this /* params */);
200 LOG(INFO) << "Waiting for JavaScript initialized message.";
201 ASSERT_TRUE(init_listener.WaitUntilSatisfied());
196 LOG(INFO) << "Waiting for JavaScript selection-change-complete message."; 202 LOG(INFO) << "Waiting for JavaScript selection-change-complete message.";
197 ASSERT_TRUE(msg_listener.WaitUntilSatisfied()); 203 ASSERT_TRUE(selection_listener.WaitUntilSatisfied());
198 204
199 // Dialog should be running now. 205 // Dialog should be running now.
200 ASSERT_TRUE(dialog_->IsRunning(owning_window)); 206 ASSERT_TRUE(dialog_->IsRunning(owning_window));
201 207
202 // Inject JavaScript to click the open button and wait for notification 208 // Inject JavaScript to click the open button and wait for notification
203 // that the window has closed. 209 // that the window has closed.
204 ui_test_utils::WindowedNotificationObserver host_destroyed( 210 ui_test_utils::WindowedNotificationObserver host_destroyed(
205 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 211 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
206 NotificationService::AllSources()); 212 NotificationService::AllSources());
207 RenderViewHost* host = dialog_->GetRenderViewHost(); 213 RenderViewHost* host = dialog_->GetRenderViewHost();
(...skipping 10 matching lines...) Expand all
218 // Dialog no longer believes it is running. 224 // Dialog no longer believes it is running.
219 ASSERT_FALSE(dialog_->IsRunning(owning_window)); 225 ASSERT_FALSE(dialog_->IsRunning(owning_window));
220 226
221 // Listener should have been informed that the file was opened. 227 // Listener should have been informed that the file was opened.
222 ASSERT_TRUE(listener_->file_selected()); 228 ASSERT_TRUE(listener_->file_selected());
223 ASSERT_FALSE(listener_->canceled()); 229 ASSERT_FALSE(listener_->canceled());
224 ASSERT_EQ(test_file, listener_->path()); 230 ASSERT_EQ(test_file, listener_->path());
225 ASSERT_EQ(this, listener_->params()); 231 ASSERT_EQ(this, listener_->params());
226 } 232 }
227 233
228 // Flaky: http://crbug.com/89733 234 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, SelectFileAndSave) {
229 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, DISABLED_SelectFileAndSave) {
230 // Allow the tmp directory to be mounted. We explicitly use /tmp because 235 // Allow the tmp directory to be mounted. We explicitly use /tmp because
231 // it it whitelisted for file system access on Chrome OS. 236 // it it whitelisted for file system access on Chrome OS.
232 FilePath tmp_dir("/tmp"); 237 FilePath tmp_dir("/tmp");
233 AddMountPoint(tmp_dir); 238 AddMountPoint(tmp_dir);
234 239
235 // Create a directory with a single file in it. ScopedTempDir will delete 240 // Create a directory with a single file in it. ScopedTempDir will delete
236 // itself and our temp file when it goes out of scope. 241 // itself and our temp file when it goes out of scope.
237 ScopedTempDir scoped_temp_dir; 242 ScopedTempDir scoped_temp_dir;
238 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); 243 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir));
239 FilePath temp_dir = scoped_temp_dir.path(); 244 FilePath temp_dir = scoped_temp_dir.path();
240 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); 245 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html");
241 246
242 // Spawn a dialog to save a file, providing a suggested path. 247 // Spawn a dialog to save a file, providing a suggested path.
243 // Ensure "Save" button is enabled by waiting for notification from 248 // Ensure "Save" button is enabled by waiting for notification from
244 // chrome.test.sendMessage(). 249 // chrome.test.sendMessage().
245 ExtensionTestMessageListener msg_listener("directory-change-complete", 250 // The extension starts a Web Worker to read file metadata, so it may send
246 false /* will_reply */); 251 // 'directory-change-complete' before 'worker-initialized'. This is OK.
252 ExtensionTestMessageListener init_listener("worker-initialized",
253 false /* will_reply */);
254 ExtensionTestMessageListener dir_change_listener("directory-change-complete",
255 false /* will_reply */);
247 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); 256 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle();
248 dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, 257 dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
249 string16() /* title */, 258 string16() /* title */,
250 test_file, 259 test_file,
251 NULL /* file_types */, 260 NULL /* file_types */,
252 0 /* file_type_index */, 261 0 /* file_type_index */,
253 FILE_PATH_LITERAL("") /* default_extension */, 262 FILE_PATH_LITERAL("") /* default_extension */,
254 NULL /* source_contents */, 263 NULL /* source_contents */,
255 owning_window, 264 owning_window,
256 this /* params */); 265 this /* params */);
257 LOG(INFO) << "Waiting for JavaScript message."; 266 LOG(INFO) << "Waiting for JavaScript initialized message.";
258 ASSERT_TRUE(msg_listener.WaitUntilSatisfied()); 267 ASSERT_TRUE(init_listener.WaitUntilSatisfied());
268 LOG(INFO) << "Waiting for JavaScript directory-change-complete message.";
269 ASSERT_TRUE(dir_change_listener.WaitUntilSatisfied());
259 270
260 // Dialog should be running now. 271 // Dialog should be running now.
261 ASSERT_TRUE(dialog_->IsRunning(owning_window)); 272 ASSERT_TRUE(dialog_->IsRunning(owning_window));
262 273
263 // Inject JavaScript to click the save button and wait for notification 274 // Inject JavaScript to click the save button and wait for notification
264 // that the window has closed. 275 // that the window has closed.
265 ui_test_utils::WindowedNotificationObserver host_destroyed( 276 ui_test_utils::WindowedNotificationObserver host_destroyed(
266 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 277 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
267 NotificationService::AllSources()); 278 NotificationService::AllSources());
268 RenderViewHost* host = dialog_->GetRenderViewHost(); 279 RenderViewHost* host = dialog_->GetRenderViewHost();
269 string16 main_frame; 280 string16 main_frame;
270 string16 script = ASCIIToUTF16( 281 string16 script = ASCIIToUTF16(
271 "console.log(\'Test JavaScript injected.\');" 282 "console.log(\'Test JavaScript injected.\');"
272 "document.querySelector('.ok').click();"); 283 "document.querySelector('.ok').click();");
273 // The file selection handler closes the dialog and does not return control 284 // The file selection handler closes the dialog and does not return control
274 // to JavaScript, so do not wait for return values. 285 // to JavaScript, so do not wait for return values.
275 host->ExecuteJavascriptInWebFrame(main_frame, script); 286 host->ExecuteJavascriptInWebFrame(main_frame, script);
276 LOG(INFO) << "Waiting for window close notification."; 287 LOG(INFO) << "Waiting for window close notification.";
277 host_destroyed.Wait(); 288 host_destroyed.Wait();
278 289
279 // Dialog no longer believes it is running. 290 // Dialog no longer believes it is running.
280 ASSERT_FALSE(dialog_->IsRunning(owning_window)); 291 ASSERT_FALSE(dialog_->IsRunning(owning_window));
281 292
282 // Listener should have been informed that the file was selected. 293 // Listener should have been informed that the file was selected.
283 ASSERT_TRUE(listener_->file_selected()); 294 ASSERT_TRUE(listener_->file_selected());
284 ASSERT_FALSE(listener_->canceled()); 295 ASSERT_FALSE(listener_->canceled());
285 ASSERT_EQ(test_file, listener_->path()); 296 ASSERT_EQ(test_file, listener_->path());
286 ASSERT_EQ(this, listener_->params()); 297 ASSERT_EQ(this, listener_->params());
287 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/metadata_dispatcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698