| 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/process_util.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 | 224 |
| 225 private: | 225 private: |
| 226 NotificationRegistrar registrar_; | 226 NotificationRegistrar registrar_; |
| 227 | 227 |
| 228 AppModalDialog* dialog_; | 228 AppModalDialog* dialog_; |
| 229 | 229 |
| 230 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); | 230 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 class CrashedRenderProcessObserver : public NotificationObserver { | 233 template <class T> |
| 234 class SimpleNotificationObserver : public NotificationObserver { |
| 234 public: | 235 public: |
| 235 explicit CrashedRenderProcessObserver(RenderProcessHost* rph) { | 236 SimpleNotificationObserver(NotificationType notification_type, |
| 236 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 237 T* source) { |
| 237 Source<RenderProcessHost>(rph)); | 238 registrar_.Add(this, notification_type, Source<T>(source)); |
| 238 ui_test_utils::RunMessageLoop(); | 239 ui_test_utils::RunMessageLoop(); |
| 239 } | 240 } |
| 240 | 241 |
| 241 virtual void Observe(NotificationType type, | 242 virtual void Observe(NotificationType type, |
| 242 const NotificationSource& source, | 243 const NotificationSource& source, |
| 243 const NotificationDetails& details) { | 244 const NotificationDetails& details) { |
| 244 if (type == NotificationType::RENDERER_PROCESS_CLOSED) { | 245 MessageLoopForUI::current()->Quit(); |
| 245 MessageLoopForUI::current()->Quit(); | |
| 246 } else { | |
| 247 NOTREACHED(); | |
| 248 } | |
| 249 } | 246 } |
| 250 | 247 |
| 251 private: | 248 private: |
| 252 NotificationRegistrar registrar_; | 249 NotificationRegistrar registrar_; |
| 253 | 250 |
| 254 DISALLOW_COPY_AND_ASSIGN(CrashedRenderProcessObserver); | 251 DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); |
| 255 }; | 252 }; |
| 256 | 253 |
| 257 } // namespace | 254 } // namespace |
| 258 | 255 |
| 259 void RunMessageLoop() { | 256 void RunMessageLoop() { |
| 260 MessageLoopForUI* loop = MessageLoopForUI::current(); | 257 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 261 bool did_allow_task_nesting = loop->NestableTasksAllowed(); | 258 bool did_allow_task_nesting = loop->NestableTasksAllowed(); |
| 262 loop->SetNestableTasksAllowed(true); | 259 loop->SetNestableTasksAllowed(true); |
| 263 #if defined(TOOLKIT_VIEWS) | 260 #if defined(TOOLKIT_VIEWS) |
| 264 views::AcceleratorHandler handler; | 261 views::AcceleratorHandler handler; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 298 |
| 302 void WaitForNavigation(NavigationController* controller) { | 299 void WaitForNavigation(NavigationController* controller) { |
| 303 WaitForNavigations(controller, 1); | 300 WaitForNavigations(controller, 1); |
| 304 } | 301 } |
| 305 | 302 |
| 306 void WaitForNavigations(NavigationController* controller, | 303 void WaitForNavigations(NavigationController* controller, |
| 307 int number_of_navigations) { | 304 int number_of_navigations) { |
| 308 NavigationNotificationObserver observer(controller, number_of_navigations); | 305 NavigationNotificationObserver observer(controller, number_of_navigations); |
| 309 } | 306 } |
| 310 | 307 |
| 308 void WaitForNewTab(Browser* browser) { |
| 309 SimpleNotificationObserver<Browser> |
| 310 new_tab_observer(NotificationType::TAB_ADDED, browser); |
| 311 } |
| 312 |
| 313 void WaitForLoadStop(NavigationController* controller) { |
| 314 SimpleNotificationObserver<NavigationController> |
| 315 new_tab_observer(NotificationType::LOAD_STOP, controller); |
| 316 } |
| 317 |
| 311 void NavigateToURL(Browser* browser, const GURL& url) { | 318 void NavigateToURL(Browser* browser, const GURL& url) { |
| 312 NavigateToURLBlockUntilNavigationsComplete(browser, url, 1); | 319 NavigateToURLBlockUntilNavigationsComplete(browser, url, 1); |
| 313 } | 320 } |
| 314 | 321 |
| 315 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, | 322 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, |
| 316 const GURL& url, | 323 const GURL& url, |
| 317 int number_of_navigations) { | 324 int number_of_navigations) { |
| 318 NavigationController* controller = | 325 NavigationController* controller = |
| 319 &browser->GetSelectedTabContents()->controller(); | 326 &browser->GetSelectedTabContents()->controller(); |
| 320 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 327 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 408 } |
| 402 | 409 |
| 403 AppModalDialog* WaitForAppModalDialog() { | 410 AppModalDialog* WaitForAppModalDialog() { |
| 404 AppModalDialogObserver observer; | 411 AppModalDialogObserver observer; |
| 405 return observer.WaitForAppModalDialog(); | 412 return observer.WaitForAppModalDialog(); |
| 406 } | 413 } |
| 407 | 414 |
| 408 void CrashTab(TabContents* tab) { | 415 void CrashTab(TabContents* tab) { |
| 409 RenderProcessHost* rph = tab->render_view_host()->process(); | 416 RenderProcessHost* rph = tab->render_view_host()->process(); |
| 410 base::KillProcess(rph->process().handle(), 0, false); | 417 base::KillProcess(rph->process().handle(), 0, false); |
| 411 CrashedRenderProcessObserver crash_observer(rph); | 418 SimpleNotificationObserver<RenderProcessHost> |
| 419 crash_observer(NotificationType::RENDERER_PROCESS_CLOSED, rph); |
| 412 } | 420 } |
| 413 | 421 |
| 414 } // namespace ui_test_utils | 422 } // namespace ui_test_utils |
| OLD | NEW |