| OLD | NEW |
| 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/process_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/dom_operation_notification_details.h" | 13 #include "chrome/browser/dom_operation_notification_details.h" |
| 13 #include "chrome/browser/download/download_manager.h" | 14 #include "chrome/browser/download/download_manager.h" |
| 14 #include "chrome/browser/tab_contents/navigation_controller.h" | 15 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 15 #include "chrome/browser/tab_contents/navigation_entry.h" | 16 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 16 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
| 19 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 223 } |
| 223 | 224 |
| 224 private: | 225 private: |
| 225 NotificationRegistrar registrar_; | 226 NotificationRegistrar registrar_; |
| 226 | 227 |
| 227 AppModalDialog* dialog_; | 228 AppModalDialog* dialog_; |
| 228 | 229 |
| 229 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); | 230 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); |
| 230 }; | 231 }; |
| 231 | 232 |
| 233 class CrashedRenderProcessObserver : public NotificationObserver { |
| 234 public: |
| 235 explicit CrashedRenderProcessObserver(RenderProcessHost* rph) { |
| 236 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
| 237 Source<RenderProcessHost>(rph)); |
| 238 ui_test_utils::RunMessageLoop(); |
| 239 } |
| 240 |
| 241 virtual void Observe(NotificationType type, |
| 242 const NotificationSource& source, |
| 243 const NotificationDetails& details) { |
| 244 if (type == NotificationType::RENDERER_PROCESS_CLOSED) { |
| 245 MessageLoopForUI::current()->Quit(); |
| 246 } else { |
| 247 NOTREACHED(); |
| 248 } |
| 249 } |
| 250 |
| 251 private: |
| 252 NotificationRegistrar registrar_; |
| 253 |
| 254 DISALLOW_COPY_AND_ASSIGN(CrashedRenderProcessObserver); |
| 255 }; |
| 256 |
| 232 } // namespace | 257 } // namespace |
| 233 | 258 |
| 234 void RunMessageLoop() { | 259 void RunMessageLoop() { |
| 235 MessageLoopForUI* loop = MessageLoopForUI::current(); | 260 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 236 bool did_allow_task_nesting = loop->NestableTasksAllowed(); | 261 bool did_allow_task_nesting = loop->NestableTasksAllowed(); |
| 237 loop->SetNestableTasksAllowed(true); | 262 loop->SetNestableTasksAllowed(true); |
| 238 #if defined (OS_WIN) | 263 #if defined (OS_WIN) |
| 239 views::AcceleratorHandler handler; | 264 views::AcceleratorHandler handler; |
| 240 loop->Run(&handler); | 265 loop->Run(&handler); |
| 241 #else | 266 #else |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 388 |
| 364 void WaitForDownloadCount(DownloadManager* download_manager, size_t count) { | 389 void WaitForDownloadCount(DownloadManager* download_manager, size_t count) { |
| 365 DownloadsCompleteObserver download_observer(download_manager, count); | 390 DownloadsCompleteObserver download_observer(download_manager, count); |
| 366 } | 391 } |
| 367 | 392 |
| 368 AppModalDialog* WaitForAppModalDialog() { | 393 AppModalDialog* WaitForAppModalDialog() { |
| 369 AppModalDialogObserver observer; | 394 AppModalDialogObserver observer; |
| 370 return observer.WaitForAppModalDialog(); | 395 return observer.WaitForAppModalDialog(); |
| 371 } | 396 } |
| 372 | 397 |
| 398 void CrashTab(TabContents* tab) { |
| 399 RenderProcessHost* rph = tab->render_view_host()->process(); |
| 400 base::KillProcess(rph->process().handle(), 0, false); |
| 401 CrashedRenderProcessObserver crash_observer(rph); |
| 402 } |
| 403 |
| 373 } // namespace ui_test_utils | 404 } // namespace ui_test_utils |
| OLD | NEW |