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/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. | |
Paweł Hajdan Jr.
2011/09/15 22:11:31
This might be racy as commented on before. Please
flackr
2011/09/16 15:44:00
If I register for all NavigationControllers then I
Paweł Hajdan Jr.
2011/09/19 17:48:12
Excellent. Could you please add the most important
flackr
2011/09/20 14:16:17
Done. Hopefully it's not too wordy.
| |
35 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | |
36 Source<NavigationController>( | |
37 &web_ui_->tab_contents()->controller())); | |
38 break; | |
39 case content::NOTIFICATION_LOAD_STOP: | |
40 DCHECK(web_ui_); | |
41 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP, | |
42 Source<NavigationController>( | |
43 &web_ui_->tab_contents()->controller())); | |
44 done_ = true; | |
45 // If the message loop is running stop it. | |
46 if (running_) { | |
47 running_ = false; | |
48 MessageLoopForUI::current()->Quit(); | |
49 } | |
50 break; | |
51 default: | |
52 NOTREACHED(); | |
53 }; | |
54 } | |
55 | |
56 WebUI* TestHtmlDialogObserver::GetWebUI() { | |
57 if (!done_) { | |
58 EXPECT_FALSE(running_); | |
59 running_ = true; | |
60 ui_test_utils::RunMessageLoop(); | |
61 } | |
62 return web_ui_; | |
63 } | |
OLD | NEW |