summaryrefslogtreecommitdiffstats
path: root/chrome/test/ui_test_utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/ui_test_utils.cc')
-rw-r--r--chrome/test/ui_test_utils.cc75
1 files changed, 6 insertions, 69 deletions
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 8ed4303..d8f8c75 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -35,6 +35,7 @@
#include "chrome/common/extensions/extension_action.h"
#include "chrome/test/automation/javascript_execution_controller.h"
#include "chrome/test/bookmark_load_observer.h"
+#include "chrome/test/test_navigation_observer.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/navigation_controller.h"
@@ -55,70 +56,6 @@ namespace ui_test_utils {
namespace {
-// Used to block until a navigation completes.
-class NavigationNotificationObserver : public NotificationObserver {
- public:
- NavigationNotificationObserver(NavigationController* controller,
- int number_of_navigations)
- : navigation_started_(false),
- navigations_completed_(0),
- number_of_navigations_(number_of_navigations),
- running_(false),
- done_(false) {
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- Source<NavigationController>(controller));
- registrar_.Add(this, content::NOTIFICATION_LOAD_START,
- Source<NavigationController>(controller));
- registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
- Source<NavigationController>(controller));
- }
-
- void Run() {
- if (!done_) {
- running_ = true;
- RunMessageLoop();
- }
- }
-
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED ||
- type == content::NOTIFICATION_LOAD_START) {
- navigation_started_ = true;
- } else if (type == content::NOTIFICATION_LOAD_STOP) {
- if (navigation_started_ &&
- ++navigations_completed_ == number_of_navigations_) {
- navigation_started_ = false;
- done_ = true;
- if (running_)
- MessageLoopForUI::current()->Quit();
- }
- }
- }
-
- private:
- NotificationRegistrar registrar_;
-
- // If true the navigation has started.
- bool navigation_started_;
-
- // The number of navigations that have been completed.
- int navigations_completed_;
-
- // The number of navigations to wait for.
- int number_of_navigations_;
-
- // Calls to Observe() can happen early, before the user calls Run(), or
- // after. When we've seen all the navigations we're looking for, we set
- // done_ to true; then when Run() is called we'll never need to run the
- // event loop. Also, we don't need to quit the event loop when we're
- // done if we never had to start an event loop.
- bool running_;
- bool done_;
- DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
-};
-
class DOMOperationObserver : public NotificationObserver {
public:
explicit DOMOperationObserver(RenderViewHost* render_view_host)
@@ -337,8 +274,8 @@ void WaitForNavigation(NavigationController* controller) {
void WaitForNavigations(NavigationController* controller,
int number_of_navigations) {
- NavigationNotificationObserver observer(controller, number_of_navigations);
- observer.Run();
+ TestNavigationObserver observer(controller, NULL, number_of_navigations);
+ observer.WaitForObservation();
}
void WaitForNewTab(Browser* browser) {
@@ -404,9 +341,9 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
int number_of_navigations,
WindowOpenDisposition disposition,
int browser_test_flags) {
- NavigationNotificationObserver
+ TestNavigationObserver
same_tab_observer(&browser->GetSelectedTabContents()->controller(),
- number_of_navigations);
+ NULL, number_of_navigations);
std::set<Browser*> initial_browsers;
for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
@@ -438,7 +375,7 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
tab_contents = browser->GetSelectedTabContents();
}
if (disposition == CURRENT_TAB) {
- same_tab_observer.Run();
+ same_tab_observer.WaitForObservation();
return;
} else if (tab_contents) {
NavigationController* controller = &tab_contents->controller();