Mailbox support for texture layers.
[chromium-blink-merge.git] / ui / web_dialogs / test / test_web_dialog_observer.cc
blob5cd7b5397034122a602ff02d590ef8430138d6c5
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
3 // found in the LICENSE file.
5 #include "ui/web_dialogs/test/test_web_dialog_observer.h"
7 #include "base/logging.h"
8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/notification_details.h"
10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_source.h"
12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_ui.h"
15 #include "content/public/test/js_injection_ready_observer.h"
16 #include "content/public/test/test_utils.h"
18 using content::NavigationController;
20 namespace ui {
21 namespace test {
23 TestWebDialogObserver::TestWebDialogObserver(
24 content::JsInjectionReadyObserver* js_injection_ready_observer)
25 : js_injection_ready_observer_(js_injection_ready_observer),
26 web_ui_(NULL),
27 done_(false),
28 running_(false) {
31 TestWebDialogObserver::~TestWebDialogObserver() {
34 void TestWebDialogObserver::Observe(
35 int type,
36 const content::NotificationSource& source,
37 const content::NotificationDetails& details) {
38 switch (type) {
39 break;
40 case content::NOTIFICATION_LOAD_STOP:
41 DCHECK(web_ui_);
42 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP,
43 content::Source<NavigationController>(
44 &web_ui_->GetWebContents()->GetController()));
45 done_ = true;
46 // If the message loop is running stop it.
47 if (running_) {
48 running_ = false;
49 message_loop_runner_->Quit();
51 break;
52 default:
53 NOTREACHED();
57 void TestWebDialogObserver::OnDialogShown(
58 content::WebUI* webui,
59 content::RenderViewHost* render_view_host) {
60 if (js_injection_ready_observer_) {
61 js_injection_ready_observer_->OnJsInjectionReady(render_view_host);
63 web_ui_ = webui;
64 // Wait for navigation on the new WebUI instance to complete. This depends
65 // on receiving the notification of the WebDialog being shown before the
66 // NavigationController finishes loading. The WebDialog notification is
67 // issued from web_dialog_ui.cc on RenderView creation which results from
68 // the call to render_manager_.Navigate in the method
69 // WebContents::NavigateToEntry. The new RenderView is later told to
70 // navigate in this method, ensuring that this is not a race condition.
71 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
72 content::Source<NavigationController>(
73 &web_ui_->GetWebContents()->GetController()));
76 content::WebUI* TestWebDialogObserver::GetWebUI() {
77 if (!done_) {
78 DCHECK(running_ == false);
79 running_ = true;
80 message_loop_runner_ = new content::MessageLoopRunner;
81 message_loop_runner_->Run();
83 return web_ui_;
86 } // namespace test
87 } // namespace ui