Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Side by Side Diff: chrome/test/base/test_web_dialog_observer.cc

Issue 10332231: Remove chrome::NOTIFICATION_WEB_DIALOG_SHOWN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add web_dialog_observer.h to chrome_browser.gypi Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_web_dialog_observer.h" 5 #include "chrome/test/base/test_web_dialog_observer.h"
6 6
7 #include "chrome/common/chrome_notification_types.h"
8 #include "content/test/js_injection_ready_observer.h" 7 #include "content/test/js_injection_ready_observer.h"
9 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/notification_details.h" 11 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
17 16
18 using content::NavigationController; 17 using content::NavigationController;
19 18
20 TestWebDialogObserver::TestWebDialogObserver( 19 TestWebDialogObserver::TestWebDialogObserver(
21 JsInjectionReadyObserver* js_injection_ready_observer) 20 JsInjectionReadyObserver* js_injection_ready_observer)
22 : js_injection_ready_observer_(js_injection_ready_observer), 21 : js_injection_ready_observer_(js_injection_ready_observer),
23 web_ui_(NULL), 22 web_ui_(NULL),
24 done_(false), 23 done_(false),
25 running_(false) { 24 running_(false) {
26 registrar_.Add(this, chrome::NOTIFICATION_WEB_DIALOG_SHOWN,
27 content::NotificationService::AllSources());
28 } 25 }
29 26
30 TestWebDialogObserver::~TestWebDialogObserver() { 27 TestWebDialogObserver::~TestWebDialogObserver() {
31 } 28 }
32 29
33 void TestWebDialogObserver::Observe( 30 void TestWebDialogObserver::Observe(
34 int type, 31 int type,
35 const content::NotificationSource& source, 32 const content::NotificationSource& source,
36 const content::NotificationDetails& details) { 33 const content::NotificationDetails& details) {
37 switch (type) { 34 switch (type) {
38 case chrome::NOTIFICATION_WEB_DIALOG_SHOWN:
39 if (js_injection_ready_observer_) {
40 js_injection_ready_observer_->OnJsInjectionReady(
41 content::Details<content::RenderViewHost>(details).ptr());
42 }
43 web_ui_ = content::Source<content::WebUI>(source).ptr();
44 registrar_.Remove(this, chrome::NOTIFICATION_WEB_DIALOG_SHOWN,
45 content::NotificationService::AllSources());
46 // Wait for navigation on the new WebUI instance to complete. This depends
47 // on receiving the notification of the WebDialog being shown before the
48 // NavigationController finishes loading. The WebDialog notification is
49 // issued from web_dialog_ui.cc on RenderView creation which results from
50 // the call to render_manager_.Navigate in the method
51 // WebContents::NavigateToEntry. The new RenderView is later told to
52 // navigate in this method, ensuring that this is not a race condition.
53 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
54 content::Source<NavigationController>(
55 &web_ui_->GetWebContents()->GetController()));
56 break; 35 break;
57 case content::NOTIFICATION_LOAD_STOP: 36 case content::NOTIFICATION_LOAD_STOP:
58 DCHECK(web_ui_); 37 DCHECK(web_ui_);
59 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, 38 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP,
60 content::Source<NavigationController>( 39 content::Source<NavigationController>(
61 &web_ui_->GetWebContents()->GetController())); 40 &web_ui_->GetWebContents()->GetController()));
62 done_ = true; 41 done_ = true;
63 // If the message loop is running stop it. 42 // If the message loop is running stop it.
64 if (running_) { 43 if (running_) {
65 running_ = false; 44 running_ = false;
66 MessageLoopForUI::current()->Quit(); 45 MessageLoopForUI::current()->Quit();
67 } 46 }
68 break; 47 break;
69 default: 48 default:
70 NOTREACHED(); 49 NOTREACHED();
71 }; 50 };
72 } 51 }
73 52
53 void TestWebDialogObserver::OnDialogShown(
54 content::WebUI* webui,
55 content::RenderViewHost* render_view_host) {
56 if (js_injection_ready_observer_) {
57 js_injection_ready_observer_->OnJsInjectionReady(render_view_host);
58 }
59 web_ui_ = webui;
60 // Wait for navigation on the new WebUI instance to complete. This depends
61 // on receiving the notification of the WebDialog being shown before the
62 // NavigationController finishes loading. The WebDialog notification is
63 // issued from web_dialog_ui.cc on RenderView creation which results from
64 // the call to render_manager_.Navigate in the method
65 // WebContents::NavigateToEntry. The new RenderView is later told to
66 // navigate in this method, ensuring that this is not a race condition.
67 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
68 content::Source<NavigationController>(
69 &web_ui_->GetWebContents()->GetController()));
70 }
71
74 content::WebUI* TestWebDialogObserver::GetWebUI() { 72 content::WebUI* TestWebDialogObserver::GetWebUI() {
75 if (!done_) { 73 if (!done_) {
76 EXPECT_FALSE(running_); 74 EXPECT_FALSE(running_);
77 running_ = true; 75 running_ = true;
78 ui_test_utils::RunMessageLoop(); 76 ui_test_utils::RunMessageLoop();
79 } 77 }
80 return web_ui_; 78 return web_ui_;
81 } 79 }
OLDNEW
« no previous file with comments | « chrome/test/base/test_web_dialog_observer.h ('k') | chrome/test/data/webui/certificate_viewer_ui_test-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698