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 "chrome/test/base/js_injection_ready_observer.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" |
8 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
9 #include "content/browser/tab_contents/navigation_controller.h" | 11 #include "content/browser/tab_contents/navigation_controller.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
11 #include "content/browser/webui/web_ui.h" | 13 #include "content/browser/webui/web_ui.h" |
12 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
13 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
14 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
15 #include "chrome/test/base/ui_test_utils.h" | |
16 | 17 |
17 TestHtmlDialogObserver::TestHtmlDialogObserver() | 18 TestHtmlDialogObserver::TestHtmlDialogObserver( |
18 : web_ui_(NULL), done_(false), running_(false) { | 19 JsInjectionReadyObserver* js_injection_ready_observer) |
| 20 : js_injection_ready_observer_(js_injection_ready_observer), |
| 21 web_ui_(NULL), done_(false), running_(false) { |
19 registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 22 registrar_.Add(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
20 content::NotificationService::AllSources()); | 23 content::NotificationService::AllSources()); |
21 } | 24 } |
22 | 25 |
23 TestHtmlDialogObserver::~TestHtmlDialogObserver() { | 26 TestHtmlDialogObserver::~TestHtmlDialogObserver() { |
24 } | 27 } |
25 | 28 |
26 void TestHtmlDialogObserver::Observe( | 29 void TestHtmlDialogObserver::Observe( |
27 int type, | 30 int type, |
28 const content::NotificationSource& source, | 31 const content::NotificationSource& source, |
29 const content::NotificationDetails& details) { | 32 const content::NotificationDetails& details) { |
30 switch (type) { | 33 switch (type) { |
31 case chrome::NOTIFICATION_HTML_DIALOG_SHOWN: | 34 case chrome::NOTIFICATION_HTML_DIALOG_SHOWN: |
| 35 if (js_injection_ready_observer_) { |
| 36 js_injection_ready_observer_->OnJsInjectionReady( |
| 37 content::Details<RenderViewHost>(details).ptr()); |
| 38 } |
32 web_ui_ = content::Source<WebUI>(source).ptr(); | 39 web_ui_ = content::Source<WebUI>(source).ptr(); |
33 registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 40 registrar_.Remove(this, chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
34 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
35 // Wait for navigation on the new WebUI instance to complete. This depends | 42 // Wait for navigation on the new WebUI instance to complete. This depends |
36 // on receiving the notification of the HtmlDialog being shown before the | 43 // on receiving the notification of the HtmlDialog being shown before the |
37 // NavigationController finishes loading. The HtmlDialog notification is | 44 // NavigationController finishes loading. The HtmlDialog notification is |
38 // issued from html_dialog_ui.cc on RenderView creation which results from | 45 // issued from html_dialog_ui.cc on RenderView creation which results from |
39 // the call to render_manager_.Navigate in the method | 46 // the call to render_manager_.Navigate in the method |
40 // TabContents::NavigateToEntry. The new RenderView is later told to | 47 // TabContents::NavigateToEntry. The new RenderView is later told to |
41 // navigate in this method, ensuring that this is not a race condition. | 48 // navigate in this method, ensuring that this is not a race condition. |
(...skipping 19 matching lines...) Expand all Loading... |
61 } | 68 } |
62 | 69 |
63 WebUI* TestHtmlDialogObserver::GetWebUI() { | 70 WebUI* TestHtmlDialogObserver::GetWebUI() { |
64 if (!done_) { | 71 if (!done_) { |
65 EXPECT_FALSE(running_); | 72 EXPECT_FALSE(running_); |
66 running_ = true; | 73 running_ = true; |
67 ui_test_utils::RunMessageLoop(); | 74 ui_test_utils::RunMessageLoop(); |
68 } | 75 } |
69 return web_ui_; | 76 return web_ui_; |
70 } | 77 } |
OLD | NEW |