diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 15:58:08 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 15:58:08 +0000 |
commit | c9b19949487f406436c9f5cdfdf35ce3bd805d67 (patch) | |
tree | 0de3a25b34c84b1dcdbd84ae7205ca3a514fec7f /chrome/test/ui_test_utils.cc | |
parent | fdeb7ac65e407aa5334b6f5308f15be3dae70dd6 (diff) | |
download | chromium_src-c9b19949487f406436c9f5cdfdf35ce3bd805d67.zip chromium_src-c9b19949487f406436c9f5cdfdf35ce3bd805d67.tar.gz chromium_src-c9b19949487f406436c9f5cdfdf35ce3bd805d67.tar.bz2 |
Fixes bug where triggering session restore while the browser was
already running would end up creating an extra tab.
BUG=11594
TEST=open chrome with a single tabbed browser, turn on session
restore, navigate to a page with a popup, close the tabbed browser,
create a new window ala control-n (or double click on the desktop),
and make the restored window doesn't end upw
Review URL: http://codereview.chromium.org/1371002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui_test_utils.cc')
-rw-r--r-- | chrome/test/ui_test_utils.cc | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index f04b02e..781c918 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -214,60 +214,60 @@ class DownloadsCompleteObserver : public DownloadManager::Observer, DISALLOW_COPY_AND_ASSIGN(DownloadsCompleteObserver); }; -// Used to block until an application modal dialog is shown. -class AppModalDialogObserver : public NotificationObserver { +template <class T> +class SimpleNotificationObserver : public NotificationObserver { public: - AppModalDialogObserver() : dialog_(NULL) {} - - AppModalDialog* WaitForAppModalDialog() { - registrar_.Add(this, NotificationType::APP_MODAL_DIALOG_SHOWN, - NotificationService::AllSources()); - dialog_ = NULL; + SimpleNotificationObserver(NotificationType notification_type, + T* source) { + registrar_.Add(this, notification_type, Source<T>(source)); ui_test_utils::RunMessageLoop(); - DCHECK(dialog_); - return dialog_; } virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type == NotificationType::APP_MODAL_DIALOG_SHOWN) { - registrar_.Remove(this, NotificationType::APP_MODAL_DIALOG_SHOWN, - NotificationService::AllSources()); - dialog_ = Source<AppModalDialog>(source).ptr(); - MessageLoopForUI::current()->Quit(); - } else { - NOTREACHED(); - } + MessageLoopForUI::current()->Quit(); } private: NotificationRegistrar registrar_; - AppModalDialog* dialog_; - - DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); + DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); }; -template <class T> -class SimpleNotificationObserver : public NotificationObserver { +// SimpleNotificationObserver that waits for a single notification. When the +// notification is observer the source (of type S) is recorded and the message +// loop stopped. Use |source()| to access the source after the constructor +// returns. +template <class S> +class SimpleNotificationObserverWithSource : public NotificationObserver { public: - SimpleNotificationObserver(NotificationType notification_type, - T* source) { - registrar_.Add(this, notification_type, Source<T>(source)); + SimpleNotificationObserverWithSource(NotificationType notification_type, + const NotificationSource& source) + : source_(NULL) { + registrar_.Add(this, notification_type, source); ui_test_utils::RunMessageLoop(); } virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + source_ = Source<S>(source).ptr(); + + // Remove observer now, so that if there any other notifications we don't + // clobber source_. + registrar_.RemoveAll(); + MessageLoopForUI::current()->Quit(); } + S* source() const { return source_; } + private: + S* source_; NotificationRegistrar registrar_; - DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); + DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserverWithSource); }; class LanguageDetectionNotificationObserver : public NotificationObserver { @@ -447,6 +447,13 @@ void WaitForLoadStop(NavigationController* controller) { new_tab_observer(NotificationType::LOAD_STOP, controller); } +Browser* WaitForNewBrowser() { + SimpleNotificationObserverWithSource<Browser> observer( + NotificationType::BROWSER_WINDOW_READY, + NotificationService::AllSources()); + return observer.source(); +} + void OpenURLOffTheRecord(Profile* profile, const GURL& url) { Browser::OpenURLOffTheRecord(profile, url); Browser* browser = BrowserList::FindBrowserWithType( @@ -556,8 +563,10 @@ void WaitForDownloadCount(DownloadManager* download_manager, size_t count) { } AppModalDialog* WaitForAppModalDialog() { - AppModalDialogObserver observer; - return observer.WaitForAppModalDialog(); + SimpleNotificationObserverWithSource<AppModalDialog> observer( + NotificationType::APP_MODAL_DIALOG_SHOWN, + NotificationService::AllSources()); + return observer.source(); } void CrashTab(TabContents* tab) { |