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

Side by Side Diff: chrome/test/ui_test_utils.cc

Issue 149460: Convert JavascriptAlertActivatesTab to browser_tests framework. (Closed)
Patch Set: kill duplication Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/test/ui_test_utils.h" 5 #include "chrome/test/ui_test_utils.h"
6 6
7 #include "base/json_reader.h" 7 #include "base/json_reader.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // The number of downloads to wait on completing. 187 // The number of downloads to wait on completing.
188 size_t wait_count_; 188 size_t wait_count_;
189 189
190 // Whether an internal message loop has been started and must be quit upon 190 // Whether an internal message loop has been started and must be quit upon
191 // all downloads completing. 191 // all downloads completing.
192 bool waiting_; 192 bool waiting_;
193 193
194 DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver); 194 DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver);
195 }; 195 };
196 196
197 // Used to block until an application modal dialog is shown.
198 class AppModalDialogObserver : public NotificationObserver {
199 public:
200 AppModalDialogObserver() {}
201
202 AppModalDialog* WaitForAppModalDialog() {
203 registrar_.Add(this, NotificationType::APP_MODAL_DIALOG_SHOWN,
204 NotificationService::AllSources());
205 dialog_ = NULL;
206 ui_test_utils::RunMessageLoop();
207 DCHECK(dialog_);
208 return dialog_;
209 }
210
211 virtual void Observe(NotificationType type,
212 const NotificationSource& source,
213 const NotificationDetails& details) {
214 if (type == NotificationType::APP_MODAL_DIALOG_SHOWN) {
215 registrar_.Remove(this, NotificationType::APP_MODAL_DIALOG_SHOWN,
216 NotificationService::AllSources());
217 dialog_ = Source<AppModalDialog>(source).ptr();
218 MessageLoopForUI::current()->Quit();
219 } else {
220 NOTREACHED();
221 }
222 }
223
224 private:
225 NotificationRegistrar registrar_;
226
227 AppModalDialog* dialog_;
228
229 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver);
230 };
231
197 } // namespace 232 } // namespace
198 233
199 void RunMessageLoop() { 234 void RunMessageLoop() {
200 MessageLoopForUI* loop = MessageLoopForUI::current(); 235 MessageLoopForUI* loop = MessageLoopForUI::current();
201 bool did_allow_task_nesting = loop->NestableTasksAllowed(); 236 bool did_allow_task_nesting = loop->NestableTasksAllowed();
202 loop->SetNestableTasksAllowed(true); 237 loop->SetNestableTasksAllowed(true);
203 #if defined (OS_WIN) 238 #if defined (OS_WIN)
204 views::AcceleratorHandler handler; 239 views::AcceleratorHandler handler;
205 loop->Run(&handler); 240 loop->Run(&handler);
206 #else 241 #else
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 PathService::Get(chrome::DIR_TEST_DATA, &path); 358 PathService::Get(chrome::DIR_TEST_DATA, &path);
324 path = path.Append(FilePath::FromWStringHack(dir)); 359 path = path.Append(FilePath::FromWStringHack(dir));
325 path = path.Append(FilePath::FromWStringHack(file)); 360 path = path.Append(FilePath::FromWStringHack(file));
326 return net::FilePathToFileURL(path); 361 return net::FilePathToFileURL(path);
327 } 362 }
328 363
329 void WaitForDownloadCount(DownloadManager* download_manager, size_t count) { 364 void WaitForDownloadCount(DownloadManager* download_manager, size_t count) {
330 DownloadsCompleteObserver download_observer(download_manager, count); 365 DownloadsCompleteObserver download_observer(download_manager, count);
331 } 366 }
332 367
368 AppModalDialog* WaitForAppModalDialog() {
369 AppModalDialogObserver observer;
370 return observer.WaitForAppModalDialog();
371 }
372
333 } // namespace ui_test_utils 373 } // namespace ui_test_utils
OLDNEW
« chrome/common/notification_type.h ('K') | « chrome/test/ui_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698