OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/base/test_html_dialog_observer.h" |
| 6 |
| 7 #include "chrome/common/chrome_notification_types.h" |
| 8 #include "content/common/content_notification_types.h" |
| 9 #include "content/common/notification_details.h" |
| 10 #include "content/common/notification_service.h" |
| 11 #include "content/common/notification_source.h" |
| 12 #include "content/browser/tab_contents/navigation_controller.h" |
| 13 #include "content/browser/tab_contents/tab_contents.h" |
| 14 #include "content/browser/webui/web_ui.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 |
| 17 TestHtmlDialogObserver::TestHtmlDialogObserver() |
| 18 : web_ui_(NULL), done_(false), running_(false) { |
| 19 registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
| 20 NotificationService::AllSources()); |
| 21 } |
| 22 |
| 23 TestHtmlDialogObserver::~TestHtmlDialogObserver() { |
| 24 } |
| 25 |
| 26 void TestHtmlDialogObserver::Observe(int type, |
| 27 const NotificationSource& source, |
| 28 const NotificationDetails& details) { |
| 29 switch (type) { |
| 30 case chrome::NOTIFICATION_HTML_DIALOG_SHOWN: |
| 31 web_ui_ = Source<WebUI>(source).ptr(); |
| 32 registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
| 33 NotificationService::AllSources()); |
| 34 // Wait for navigation on the new WebUI instance to complete. This depends |
| 35 // on receiving the notification of the HtmlDialog being shown before the |
| 36 // NavigationController finishes loading. The HtmlDialog notification is |
| 37 // issued from html_dialog_ui.cc on RenderView creation which results from |
| 38 // the call to render_manager_.Navigate in the method |
| 39 // TabContents::NavigateToEntry. The new RenderView is later told to |
| 40 // navigate in this method, ensuring that this is not a race condition. |
| 41 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 42 Source<NavigationController>( |
| 43 &web_ui_->tab_contents()->controller())); |
| 44 break; |
| 45 case content::NOTIFICATION_LOAD_STOP: |
| 46 DCHECK(web_ui_); |
| 47 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, |
| 48 Source<NavigationController>( |
| 49 &web_ui_->tab_contents()->controller())); |
| 50 done_ = true; |
| 51 // If the message loop is running stop it. |
| 52 if (running_) { |
| 53 running_ = false; |
| 54 MessageLoopForUI::current()->Quit(); |
| 55 } |
| 56 break; |
| 57 default: |
| 58 NOTREACHED(); |
| 59 }; |
| 60 } |
| 61 |
| 62 WebUI* TestHtmlDialogObserver::GetWebUI() { |
| 63 if (!done_) { |
| 64 EXPECT_FALSE(running_); |
| 65 running_ = true; |
| 66 ui_test_utils::RunMessageLoop(); |
| 67 } |
| 68 return web_ui_; |
| 69 } |
OLD | NEW |