| Index: chrome/test/ui_test_utils.cc
|
| diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
|
| index bf4d9dca3766da47bf9b2d58a7d5b391f489138a..2a3088861b58cc8d86d7b80ebdbee40eda456d84 100644
|
| --- a/chrome/test/ui_test_utils.cc
|
| +++ b/chrome/test/ui_test_utils.cc
|
| @@ -48,6 +48,20 @@
|
|
|
| namespace ui_test_utils {
|
|
|
| +// Waits for a new tab to be added anywhere.
|
| +Browser* WaitForAnyNewTab();
|
| +
|
| +// Navigates the specified tab (via |disposition|) of |browser| to |url|,
|
| +// blocking until the |number_of_navigations| specified complete.
|
| +// |disposition| indicates what tab the download occurs in, and
|
| +// |browser_test_flags| controls what to wait for before continuing.
|
| +void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
|
| + Browser* browser,
|
| + const GURL& url,
|
| + int number_of_navigations,
|
| + WindowOpenDisposition disposition,
|
| + int browser_test_flags);
|
| +
|
| namespace {
|
|
|
| // Used to block until a navigation completes.
|
| @@ -407,6 +421,21 @@ void WaitForNavigations(NavigationController* controller,
|
| NavigationNotificationObserver observer(controller, number_of_navigations);
|
| }
|
|
|
| +void WaitForWindowClosed(Browser* browser) {
|
| + TestNotificationObserver observer;
|
| + RegisterAndWait(&observer,
|
| + NotificationType::BROWSER_CLOSED,
|
| + Source<Browser>(browser));
|
| +}
|
| +
|
| +Browser* WaitForAnyNewTab() {
|
| + TestNotificationObserver observer;
|
| + RegisterAndWait(&observer,
|
| + NotificationType::TAB_ADDED,
|
| + NotificationService::AllSources());
|
| + return Source<Browser>(observer.source()).ptr();
|
| +}
|
| +
|
| void WaitForNewTab(Browser* browser) {
|
| TestNotificationObserver observer;
|
| RegisterAndWait(&observer, NotificationType::TAB_ADDED,
|
| @@ -429,7 +458,21 @@ Browser* WaitForNewBrowser() {
|
| TestNotificationObserver observer;
|
| RegisterAndWait(&observer, NotificationType::BROWSER_WINDOW_READY,
|
| NotificationService::AllSources());
|
| - return Source<Browser>(observer.source()).ptr();
|
| + Browser* new_browser = Source<Browser>(observer.source()).ptr();
|
| + return new_browser;
|
| +}
|
| +
|
| +Browser* WaitForNewBrowserWithCount(size_t start_count) {
|
| + TestNotificationObserver observer;
|
| + size_t cur_count = BrowserList::size();
|
| + Browser* new_browser = NULL;
|
| + if (cur_count <= start_count) {
|
| + new_browser = WaitForNewBrowser();
|
| + } else {
|
| + int index = start_count;
|
| + new_browser = GetBrowser(index);
|
| + }
|
| + return new_browser;
|
| }
|
|
|
| void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
|
| @@ -440,16 +483,69 @@ void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
|
| }
|
|
|
| void NavigateToURL(Browser* browser, const GURL& url) {
|
| - NavigateToURLBlockUntilNavigationsComplete(browser, url, 1);
|
| + NavigateToURLWithDisposition(browser, url, CURRENT_TAB,
|
| + BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| +}
|
| +
|
| +void NavigateToURLWithDisposition(Browser* browser,
|
| + const GURL& url,
|
| + WindowOpenDisposition disposition,
|
| + int browser_test_flags) {
|
| + NavigateToURLWithDispositionBlockUntilNavigationsComplete(
|
| + browser,
|
| + url,
|
| + 1,
|
| + disposition,
|
| + browser_test_flags);
|
| }
|
|
|
| void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
|
| const GURL& url,
|
| int number_of_navigations) {
|
| - NavigationController* controller =
|
| - &browser->GetSelectedTabContents()->controller();
|
| - browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
|
| - WaitForNavigations(controller, number_of_navigations);
|
| + NavigateToURLWithDispositionBlockUntilNavigationsComplete(
|
| + browser,
|
| + url,
|
| + number_of_navigations,
|
| + CURRENT_TAB,
|
| + BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| +}
|
| +
|
| +void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
|
| + Browser* browser,
|
| + const GURL& url,
|
| + int number_of_navigations,
|
| + WindowOpenDisposition disposition,
|
| + int browser_test_flags) {
|
| + size_t browser_count = BrowserList::size();
|
| + browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED);
|
| + if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
|
| + browser = WaitForNewBrowserWithCount(browser_count);
|
| + if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
|
| + WaitForAnyNewTab();
|
| + if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION))
|
| + return;
|
| + TabContents* tab_contents = NULL;
|
| + if (disposition == NEW_BACKGROUND_TAB) {
|
| + // We've opened up a new tab, but not selected it.
|
| + tab_contents = browser->GetTabContentsAt(browser->selected_index() + 1);
|
| + EXPECT_TRUE(tab_contents != NULL)
|
| + << " Unable to wait for navigation to \"" << url.spec()
|
| + << "\" because the new tab is not available yet";
|
| + return;
|
| + } else if ((disposition == CURRENT_TAB) ||
|
| + (disposition == NEW_FOREGROUND_TAB) ||
|
| + (disposition == SINGLETON_TAB)) {
|
| + // The currently selected tab is the right one.
|
| + tab_contents = browser->GetSelectedTabContents();
|
| + }
|
| + if (tab_contents) {
|
| + NavigationController* controller = &tab_contents->controller();
|
| + WaitForNavigations(controller, number_of_navigations);
|
| + return;
|
| + }
|
| + EXPECT_TRUE(NULL != tab_contents) << " Unable to wait for navigation to \""
|
| + << url.spec() << "\""
|
| + << " because we can't get the tab contents";
|
| }
|
|
|
| DOMElementProxyRef GetActiveDOMDocument(Browser* browser) {
|
| @@ -606,6 +702,17 @@ bool BringBrowserWindowToFront(const Browser* browser) {
|
| return true;
|
| }
|
|
|
| +Browser* GetBrowser(int index) {
|
| + if (index >= 0) {
|
| + BrowserList::const_iterator iter = BrowserList::begin();
|
| + for ( ; (iter != BrowserList::end()) && (index > 0); ++iter, --index) {}
|
| + if (iter != BrowserList::end()) {
|
| + return *iter;
|
| + }
|
| + }
|
| + return NULL;
|
| +}
|
| +
|
| bool SendKeyPressSync(const Browser* browser,
|
| app::KeyboardCode key,
|
| bool control,
|
|
|