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

Side by Side Diff: chrome/test/test_html_dialog_observer.cc

Issue 7861024: Adds testing infrastructure to web_ui_browsertest to support testing HtmlDialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move observing html dialog to separate class and test declarations to JS. Created 9 years, 3 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
(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.
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 }
OLDNEW
« chrome/test/test_html_dialog_observer.h ('K') | « chrome/test/test_html_dialog_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698