| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/string16.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 9 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 10 | 17 |
| 11 namespace base { | 18 namespace base { |
| 12 class RunLoop; | 19 class RunLoop; |
| 13 } | 20 } |
| 14 | 21 |
| 15 // A collections of functions designed for use with content_browsertests and | 22 // A collections of functions designed for use with content_browsertests and |
| 16 // browser_tests. | 23 // browser_tests. |
| 17 // TO BE CLEAR: any function here must work against both binaries. If it only | 24 // TO BE CLEAR: any function here must work against both binaries. If it only |
| 18 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h. | 25 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h. |
| 19 // If it only works with content_browsertests, it should be in | 26 // If it only works with content_browsertests, it should be in |
| 20 // content\test\content_browser_test_utils.h. | 27 // content\test\content_browser_test_utils.h. |
| 21 | 28 |
| 22 namespace content { | 29 namespace content { |
| 23 | 30 |
| 31 class MessageLoopRunner; |
| 32 class WebContents; |
| 33 |
| 34 // Watches title changes on a tab, blocking until an expected title is set. |
| 35 class TitleWatcher : public NotificationObserver { |
| 36 public: |
| 37 // |web_contents| must be non-NULL and needs to stay alive for the |
| 38 // entire lifetime of |this|. |expected_title| is the title that |this| |
| 39 // will wait for. |
| 40 TitleWatcher(WebContents* web_contents, |
| 41 const string16& expected_title); |
| 42 virtual ~TitleWatcher(); |
| 43 |
| 44 // Adds another title to watch for. |
| 45 void AlsoWaitForTitle(const string16& expected_title); |
| 46 |
| 47 // Waits until the title matches either expected_title or one of the titles |
| 48 // added with AlsoWaitForTitle. Returns the value of the most recently |
| 49 // observed matching title. |
| 50 const string16& WaitAndGetTitle() WARN_UNUSED_RESULT; |
| 51 |
| 52 private: |
| 53 // NotificationObserver |
| 54 virtual void Observe(int type, |
| 55 const NotificationSource& source, |
| 56 const NotificationDetails& details) OVERRIDE; |
| 57 |
| 58 WebContents* web_contents_; |
| 59 std::vector<string16> expected_titles_; |
| 60 NotificationRegistrar notification_registrar_; |
| 61 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 62 |
| 63 // The most recently observed expected title, if any. |
| 64 string16 observed_title_; |
| 65 |
| 66 bool expected_title_observed_; |
| 67 bool quit_loop_on_observation_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); |
| 70 }; |
| 71 |
| 24 } // namespace content | 72 } // namespace content |
| 25 | 73 |
| 26 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 74 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| OLD | NEW |