summaryrefslogtreecommitdiffstats
path: root/chrome/test/ui_test_utils.cc
diff options
context:
space:
mode:
authorahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 17:08:44 +0000
committerahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 17:08:44 +0000
commit46f979d4c5716549777cef154423fa4fb76210d9 (patch)
tree8e11b421cea629422f64f7144890abc8524e7eb5 /chrome/test/ui_test_utils.cc
parent8050ca9e629f560af14653566de54a12dc2bcc78 (diff)
downloadchromium_src-46f979d4c5716549777cef154423fa4fb76210d9.zip
chromium_src-46f979d4c5716549777cef154423fa4fb76210d9.tar.gz
chromium_src-46f979d4c5716549777cef154423fa4fb76210d9.tar.bz2
Converted download UI tests to Browser tests.
Converted NavigateWithURLAsync/WaitForDownloadShelfVisible calls to NavigateToURLWithDisposition. This waits until the navigation is done before returning, avoiding the need for the 'sleep and wait' loop. BUG=none TEST=Run browser_tests --gtest_filter=DownloadTest.* Review URL: http://codereview.chromium.org/5610006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui_test_utils.cc')
-rw-r--r--chrome/test/ui_test_utils.cc102
1 files changed, 97 insertions, 5 deletions
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 0be4bd8..7eba05c 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -432,6 +432,17 @@ Browser* WaitForNewBrowser() {
return Source<Browser>(observer.source()).ptr();
}
+Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
+ TestNotificationObserver observer;
+ Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
+ if (new_browser == NULL) {
+ new_browser = WaitForNewBrowser();
+ // The new browser should never be in |excluded_browsers|.
+ DCHECK(!ContainsKey(excluded_browsers, new_browser));
+ }
+ return new_browser;
+}
+
void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
Browser::OpenURLOffTheRecord(profile, url);
Browser* browser = BrowserList::FindBrowserWithType(
@@ -440,16 +451,80 @@ 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);
+}
+
+// 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.
+static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
+ Browser* browser,
+ const GURL& url,
+ int number_of_navigations,
+ WindowOpenDisposition disposition,
+ int browser_test_flags) {
+ std::set<Browser*> initial_browsers;
+ for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
+ iter != BrowserList::end();
+ ++iter) {
+ initial_browsers.insert(*iter);
+ }
+ browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED);
+ if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
+ browser = WaitForBrowserNotInSet(initial_browsers);
+ if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
+ WaitForNotification(NotificationType::TAB_ADDED);
+ if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) {
+ // Some other flag caused the wait prior to this.
+ 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";
+}
+
+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);
}
DOMElementProxyRef GetActiveDOMDocument(Browser* browser) {
@@ -563,6 +638,12 @@ void WaitForNotification(NotificationType type) {
RegisterAndWait(&observer, type, NotificationService::AllSources());
}
+void WaitForNotificationFrom(NotificationType type,
+ const NotificationSource& source) {
+ TestNotificationObserver observer;
+ RegisterAndWait(&observer, type, source);
+}
+
void RegisterAndWait(NotificationObserver* observer,
NotificationType type,
const NotificationSource& source) {
@@ -606,6 +687,17 @@ bool BringBrowserWindowToFront(const Browser* browser) {
return true;
}
+Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) {
+ for (BrowserList::const_iterator iter = BrowserList::begin();
+ iter != BrowserList::end();
+ ++iter) {
+ if (excluded_browsers.find(*iter) == excluded_browsers.end())
+ return *iter;
+ }
+
+ return NULL;
+}
+
bool SendKeyPressSync(const Browser* browser,
app::KeyboardCode key,
bool control,