Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2109)

Unified Diff: content/test/browser_test_utils.cc

Issue 10815025: Move TitleWatcher from ui_test_utils.h to browser_test_utils.h so it can be reused by content_brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/layout_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/browser_test_utils.cc
===================================================================
--- content/test/browser_test_utils.cc (revision 147602)
+++ content/test/browser_test_utils.cc (working copy)
@@ -4,6 +4,78 @@
#include "content/public/test/browser_test_utils.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
namespace content {
+TitleWatcher::TitleWatcher(WebContents* web_contents,
+ const string16& expected_title)
+ : web_contents_(web_contents),
+ expected_title_observed_(false),
+ quit_loop_on_observation_(false) {
+ EXPECT_TRUE(web_contents != NULL);
+ expected_titles_.push_back(expected_title);
+ notification_registrar_.Add(this,
+ NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
+ Source<WebContents>(web_contents));
+
+ // When navigating through the history, the restored NavigationEntry's title
+ // will be used. If the entry ends up having the same title after we return
+ // to it, as will usually be the case, the
+ // NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED will then be suppressed, since the
+ // NavigationEntry's title hasn't changed.
+ notification_registrar_.Add(
+ this,
+ NOTIFICATION_LOAD_STOP,
+ Source<NavigationController>(&web_contents->GetController()));
+}
+
+void TitleWatcher::AlsoWaitForTitle(const string16& expected_title) {
+ expected_titles_.push_back(expected_title);
+}
+
+TitleWatcher::~TitleWatcher() {
+}
+
+const string16& TitleWatcher::WaitAndGetTitle() {
+ if (expected_title_observed_)
+ return observed_title_;
+ quit_loop_on_observation_ = true;
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
+ return observed_title_;
+}
+
+void TitleWatcher::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) {
+ WebContents* source_contents = Source<WebContents>(source).ptr();
+ ASSERT_EQ(web_contents_, source_contents);
+ } else if (type == NOTIFICATION_LOAD_STOP) {
+ NavigationController* controller =
+ Source<NavigationController>(source).ptr();
+ ASSERT_EQ(&web_contents_->GetController(), controller);
+ } else {
+ FAIL() << "Unexpected notification received.";
+ }
+
+ std::vector<string16>::const_iterator it =
+ std::find(expected_titles_.begin(),
+ expected_titles_.end(),
+ web_contents_->GetTitle());
+ if (it == expected_titles_.end())
+ return;
+ observed_title_ = *it;
+ expected_title_observed_ = true;
+ if (quit_loop_on_observation_) {
+ // Only call Quit once, on first Observe:
+ quit_loop_on_observation_ = false;
+ message_loop_runner_->Quit();
+ }
+}
+
} // namespace content
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/layout_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698