OLD | NEW |
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/test/base/test_html_dialog_observer.h" | 5 #include "chrome/test/base/test_html_dialog_observer.h" |
6 | 6 |
7 #include "chrome/common/chrome_notification_types.h" | 7 #include "chrome/common/chrome_notification_types.h" |
8 #include "content/test/js_injection_ready_observer.h" | 8 #include "content/test/js_injection_ready_observer.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
11 #include "content/browser/webui/web_ui.h" | 11 #include "content/browser/webui/web_ui.h" |
12 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
| 18 using content::NavigationController; |
| 19 |
18 TestHtmlDialogObserver::TestHtmlDialogObserver( | 20 TestHtmlDialogObserver::TestHtmlDialogObserver( |
19 JsInjectionReadyObserver* js_injection_ready_observer) | 21 JsInjectionReadyObserver* js_injection_ready_observer) |
20 : js_injection_ready_observer_(js_injection_ready_observer), | 22 : js_injection_ready_observer_(js_injection_ready_observer), |
21 web_ui_(NULL), done_(false), running_(false) { | 23 web_ui_(NULL), done_(false), running_(false) { |
22 registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 24 registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
23 content::NotificationService::AllSources()); | 25 content::NotificationService::AllSources()); |
24 } | 26 } |
25 | 27 |
26 TestHtmlDialogObserver::~TestHtmlDialogObserver() { | 28 TestHtmlDialogObserver::~TestHtmlDialogObserver() { |
27 } | 29 } |
(...skipping 12 matching lines...) Expand all Loading... |
40 registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 42 registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
41 content::NotificationService::AllSources()); | 43 content::NotificationService::AllSources()); |
42 // Wait for navigation on the new WebUI instance to complete. This depends | 44 // Wait for navigation on the new WebUI instance to complete. This depends |
43 // on receiving the notification of the HtmlDialog being shown before the | 45 // on receiving the notification of the HtmlDialog being shown before the |
44 // NavigationController finishes loading. The HtmlDialog notification is | 46 // NavigationController finishes loading. The HtmlDialog notification is |
45 // issued from html_dialog_ui.cc on RenderView creation which results from | 47 // issued from html_dialog_ui.cc on RenderView creation which results from |
46 // the call to render_manager_.Navigate in the method | 48 // the call to render_manager_.Navigate in the method |
47 // TabContents::NavigateToEntry. The new RenderView is later told to | 49 // TabContents::NavigateToEntry. The new RenderView is later told to |
48 // navigate in this method, ensuring that this is not a race condition. | 50 // navigate in this method, ensuring that this is not a race condition. |
49 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 51 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
50 content::Source<content::NavigationController>( | 52 content::Source<NavigationController>( |
51 &web_ui_->web_contents()->GetController())); | 53 &web_ui_->web_contents()->GetController())); |
52 break; | 54 break; |
53 case content::NOTIFICATION_LOAD_STOP: | 55 case content::NOTIFICATION_LOAD_STOP: |
54 DCHECK(web_ui_); | 56 DCHECK(web_ui_); |
55 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, | 57 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, |
56 content::Source<content::NavigationController>( | 58 content::Source<NavigationController>( |
57 &web_ui_->web_contents()->GetController())); | 59 &web_ui_->web_contents()->GetController())); |
58 done_ = true; | 60 done_ = true; |
59 // If the message loop is running stop it. | 61 // If the message loop is running stop it. |
60 if (running_) { | 62 if (running_) { |
61 running_ = false; | 63 running_ = false; |
62 MessageLoopForUI::current()->Quit(); | 64 MessageLoopForUI::current()->Quit(); |
63 } | 65 } |
64 break; | 66 break; |
65 default: | 67 default: |
66 NOTREACHED(); | 68 NOTREACHED(); |
67 }; | 69 }; |
68 } | 70 } |
69 | 71 |
70 WebUI* TestHtmlDialogObserver::GetWebUI() { | 72 WebUI* TestHtmlDialogObserver::GetWebUI() { |
71 if (!done_) { | 73 if (!done_) { |
72 EXPECT_FALSE(running_); | 74 EXPECT_FALSE(running_); |
73 running_ = true; | 75 running_ = true; |
74 ui_test_utils::RunMessageLoop(); | 76 ui_test_utils::RunMessageLoop(); |
75 } | 77 } |
76 return web_ui_; | 78 return web_ui_; |
77 } | 79 } |
OLD | NEW |