Index: chrome/test/base/ui_test_utils.h |
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h |
index 38ac0db71686916b457c353bb064adc34845b63f..25b537779615ceec062266bcd6615b0bd6b5324e 100644 |
--- a/chrome/test/base/ui_test_utils.h |
+++ b/chrome/test/base/ui_test_utils.h |
@@ -14,6 +14,8 @@ |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/strings/string16.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_list_observer.h" |
#include "components/history/core/browser/history_service.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_observer.h" |
@@ -287,6 +289,31 @@ class HistoryEnumerator { |
DISALLOW_COPY_AND_ASSIGN(HistoryEnumerator); |
}; |
+// Use in browser interactive uitests to wait until a browser is set to active. |
+// To use create and call WaitForActivation(). |
+// TODO(warx): check if code base exists the requirement for deactivation sync, |
+// this class can be modified to support that. |
+class BrowserActivationWaiter : public chrome::BrowserListObserver { |
+ public: |
+ explicit BrowserActivationWaiter(Browser* browser); |
+ ~BrowserActivationWaiter() override; |
+ |
+ // Returns when the |browser_| which is supplied by the constructor becomes |
+ // activated. If it is not activated, a message loop is used until the |
+ // |browser_| is activated, otherwise this returns immediately. |
+ void WaitForActivation(); |
+ |
+ private: |
+ // chrome::BrowserListObserver override: |
+ void OnBrowserSetLastActive(Browser* browser) override; |
+ |
+ Browser* browser_; |
+ bool observed_; |
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BrowserActivationWaiter); |
+}; |
+ |
} // namespace ui_test_utils |
#endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ |