Commit 35daebe0 authored by jam@chromium.org's avatar jam@chromium.org

Move TitleWatcher from ui_test_utils.h to browser_test_utils.h so it can be...

Move TitleWatcher from ui_test_utils.h to browser_test_utils.h so it can be reused by content_browsertests.

BUG=90448
TBR=scottmg
Review URL: https://chromiumcodereview.appspot.com/10815025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147618 0039d316-1c4b-4281-b951-d872f2087c98
parent 86fcebea
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/test_server.h" #include "net/test/test_server.h"
// Regression test for http://crbug.com/63649. // Regression test for http://crbug.com/63649.
...@@ -107,7 +108,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { ...@@ -107,7 +108,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
content::RenderViewHost* host = content::RenderViewHost* host =
...@@ -128,7 +129,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) { ...@@ -128,7 +129,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
string16 expected_title1(ASCIIToUTF16("1")); string16 expected_title1(ASCIIToUTF16("1"));
ui_test_utils::TitleWatcher title_watcher1( content::TitleWatcher title_watcher1(
chrome::GetActiveWebContents(browser()), expected_title1); chrome::GetActiveWebContents(browser()), expected_title1);
content::RenderViewHost* host = content::RenderViewHost* host =
...@@ -138,7 +139,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) { ...@@ -138,7 +139,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) {
EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
string16 expected_title2(ASCIIToUTF16("2")); string16 expected_title2(ASCIIToUTF16("2"));
ui_test_utils::TitleWatcher title_watcher2( content::TitleWatcher title_watcher2(
chrome::GetActiveWebContents(browser()), expected_title2); chrome::GetActiveWebContents(browser()), expected_title2);
ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
...@@ -162,7 +163,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { ...@@ -162,7 +163,7 @@ IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) {
L"", L"CallOnStartup = function() { document.title = \"OK\"; }")); L"", L"CallOnStartup = function() { document.title = \"OK\"; }"));
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
content::RenderViewHost* host = content::RenderViewHost* host =
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/test/net/url_request_failed_job.h" #include "content/test/net/url_request_failed_job.h"
#include "content/test/net/url_request_mock_http_job.h" #include "content/test/net/url_request_mock_http_job.h"
...@@ -39,7 +40,7 @@ class ErrorPageTest : public InProcessBrowserTest { ...@@ -39,7 +40,7 @@ class ErrorPageTest : public InProcessBrowserTest {
void NavigateToURLAndWaitForTitle(const GURL& url, void NavigateToURLAndWaitForTitle(const GURL& url,
const std::string& expected_title, const std::string& expected_title,
int num_navigations) { int num_navigations) {
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), chrome::GetActiveWebContents(browser()),
ASCIIToUTF16(expected_title)); ASCIIToUTF16(expected_title));
...@@ -85,7 +86,7 @@ class ErrorPageTest : public InProcessBrowserTest { ...@@ -85,7 +86,7 @@ class ErrorPageTest : public InProcessBrowserTest {
void NavigateHistoryAndWaitForTitle(const std::string& expected_title, void NavigateHistoryAndWaitForTitle(const std::string& expected_title,
int num_navigations, int num_navigations,
HistoryNavigationDirection direction) { HistoryNavigationDirection direction) {
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), chrome::GetActiveWebContents(browser()),
ASCIIToUTF16(expected_title)); ASCIIToUTF16(expected_title));
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/test_server.h" #include "net/test/test_server.h"
namespace { namespace {
...@@ -68,7 +69,7 @@ class SearchProviderTest : public InProcessBrowserTest { ...@@ -68,7 +69,7 @@ class SearchProviderTest : public InProcessBrowserTest {
const IsSearchProviderTestData& data) { const IsSearchProviderTestData& data) {
string16 title = data.tab->GetTitle(); string16 title = data.tab->GetTitle();
if (title.empty()) { if (title.empty()) {
ui_test_utils::TitleWatcher title_watcher(data.tab, ASCIIToUTF16("OK")); content::TitleWatcher title_watcher(data.tab, ASCIIToUTF16("OK"));
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
title = title_watcher.WaitAndGetTitle(); title = title_watcher.WaitAndGetTitle();
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
...@@ -138,7 +139,7 @@ class HistoryBrowserTest : public InProcessBrowserTest { ...@@ -138,7 +139,7 @@ class HistoryBrowserTest : public InProcessBrowserTest {
void LoadAndWaitForURL(const GURL& url) { void LoadAndWaitForURL(const GURL& url) {
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
namespace { namespace {
...@@ -52,7 +53,7 @@ IN_PROC_BROWSER_TEST_F(PrefetchBrowserTest, PrefetchOn) { ...@@ -52,7 +53,7 @@ IN_PROC_BROWSER_TEST_F(PrefetchBrowserTest, PrefetchOn) {
GURL url = test_server()->GetURL(kPrefetchPage); GURL url = test_server()->GetURL(kPrefetchPage);
const string16 expected_title = ASCIIToUTF16("link onload"); const string16 expected_title = ASCIIToUTF16("link onload");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), chrome::GetActiveWebContents(browser()),
expected_title); expected_title);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
...@@ -65,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestNoPrefetching, PrefetchOff) { ...@@ -65,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestNoPrefetching, PrefetchOff) {
GURL url = test_server()->GetURL(kPrefetchPage); GURL url = test_server()->GetURL(kPrefetchPage);
const string16 expected_title = ASCIIToUTF16("link onerror"); const string16 expected_title = ASCIIToUTF16("link onerror");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), chrome::GetActiveWebContents(browser()),
expected_title); expected_title);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
...@@ -250,7 +251,7 @@ class TestPrerenderContents : public PrerenderContents { ...@@ -250,7 +251,7 @@ class TestPrerenderContents : public PrerenderContents {
session_storage_namespace); session_storage_namespace);
string16 ready_title = ASCIIToUTF16(kReadyTitle); string16 ready_title = ASCIIToUTF16(kReadyTitle);
if (prerender_should_wait_for_ready_title_) if (prerender_should_wait_for_ready_title_)
ready_title_watcher_.reset(new ui_test_utils::TitleWatcher( ready_title_watcher_.reset(new content::TitleWatcher(
web_contents, ready_title)); web_contents, ready_title));
return web_contents; return web_contents;
} }
...@@ -364,7 +365,7 @@ class TestPrerenderContents : public PrerenderContents { ...@@ -364,7 +365,7 @@ class TestPrerenderContents : public PrerenderContents {
// If true, before calling DidPrerenderPass, will wait for the title of the // If true, before calling DidPrerenderPass, will wait for the title of the
// prerendered page to turn to "READY". // prerendered page to turn to "READY".
bool prerender_should_wait_for_ready_title_; bool prerender_should_wait_for_ready_title_;
scoped_ptr<ui_test_utils::TitleWatcher> ready_title_watcher_; scoped_ptr<content::TitleWatcher> ready_title_watcher_;
}; };
// PrerenderManager that uses TestPrerenderContents. // PrerenderManager that uses TestPrerenderContents.
...@@ -689,7 +690,7 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest { ...@@ -689,7 +690,7 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
void NavigateToDestUrlAndWaitForPassTitle() { void NavigateToDestUrlAndWaitForPassTitle() {
string16 expected_title = ASCIIToUTF16(kPassTitle); string16 expected_title = ASCIIToUTF16(kPassTitle);
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
GetPrerenderContents()->prerender_contents()->web_contents(), GetPrerenderContents()->prerender_contents()->web_contents(),
expected_title); expected_title);
NavigateToDestURL(); NavigateToDestURL();
...@@ -2114,7 +2115,7 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderUnload) { ...@@ -2114,7 +2115,7 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderUnload) {
set_loader_path("files/prerender/prerender_loader_with_unload.html"); set_loader_path("files/prerender/prerender_loader_with_unload.html");
PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
string16 expected_title = ASCIIToUTF16("Unloaded"); string16 expected_title = ASCIIToUTF16("Unloaded");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(current_browser()), expected_title); chrome::GetActiveWebContents(current_browser()), expected_title);
NavigateToDestURL(); NavigateToDestURL();
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/test_server.h" #include "net/test/test_server.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
...@@ -88,7 +89,7 @@ class ReferrerPolicyTest : public InProcessBrowserTest { ...@@ -88,7 +89,7 @@ class ReferrerPolicyTest : public InProcessBrowserTest {
// Adds all possible titles to the TitleWatcher, so we don't time out // Adds all possible titles to the TitleWatcher, so we don't time out
// waiting for the title if the test fails. // waiting for the title if the test fails.
void AddAllPossibleTitles(const GURL& url, void AddAllPossibleTitles(const GURL& url,
ui_test_utils::TitleWatcher* title_watcher) { content::TitleWatcher* title_watcher) {
title_watcher->AlsoWaitForTitle( title_watcher->AlsoWaitForTitle(
GetExpectedTitle(url, EXPECT_EMPTY_REFERRER)); GetExpectedTitle(url, EXPECT_EMPTY_REFERRER));
title_watcher->AlsoWaitForTitle( title_watcher->AlsoWaitForTitle(
...@@ -140,7 +141,7 @@ class ReferrerPolicyTest : public InProcessBrowserTest { ...@@ -140,7 +141,7 @@ class ReferrerPolicyTest : public InProcessBrowserTest {
string16 expected_title = GetExpectedTitle(start_url, expected_referrer); string16 expected_title = GetExpectedTitle(start_url, expected_referrer);
content::WebContents* tab = chrome::GetActiveWebContents(browser()); content::WebContents* tab = chrome::GetActiveWebContents(browser());
ui_test_utils::TitleWatcher title_watcher(tab, expected_title); content::TitleWatcher title_watcher(tab, expected_title);
// Watch for all possible outcomes to avoid timeouts if something breaks. // Watch for all possible outcomes to avoid timeouts if something breaks.
AddAllPossibleTitles(start_url, &title_watcher); AddAllPossibleTitles(start_url, &title_watcher);
...@@ -380,8 +381,8 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) { ...@@ -380,8 +381,8 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) {
string16 expected_title = string16 expected_title =
GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER); GetExpectedTitle(start_url, EXPECT_ORIGIN_AS_REFERRER);
content::WebContents* tab = chrome::GetActiveWebContents(browser()); content::WebContents* tab = chrome::GetActiveWebContents(browser());
scoped_ptr<ui_test_utils::TitleWatcher> title_watcher( scoped_ptr<content::TitleWatcher> title_watcher(
new ui_test_utils::TitleWatcher(tab, expected_title)); new content::TitleWatcher(tab, expected_title));
// Watch for all possible outcomes to avoid timeouts if something breaks. // Watch for all possible outcomes to avoid timeouts if something breaks.
AddAllPossibleTitles(start_url, title_watcher.get()); AddAllPossibleTitles(start_url, title_watcher.get());
...@@ -390,14 +391,14 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) { ...@@ -390,14 +391,14 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, History) {
chrome::GoBack(browser(), CURRENT_TAB); chrome::GoBack(browser(), CURRENT_TAB);
EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
title_watcher.reset(new ui_test_utils::TitleWatcher(tab, expected_title)); title_watcher.reset(new content::TitleWatcher(tab, expected_title));
AddAllPossibleTitles(start_url, title_watcher.get()); AddAllPossibleTitles(start_url, title_watcher.get());
// Reload to B. // Reload to B.
chrome::Reload(browser(), CURRENT_TAB); chrome::Reload(browser(), CURRENT_TAB);
EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher->WaitAndGetTitle());
title_watcher.reset(new ui_test_utils::TitleWatcher(tab, expected_title)); title_watcher.reset(new content::TitleWatcher(tab, expected_title));
AddAllPossibleTitles(start_url, title_watcher.get()); AddAllPossibleTitles(start_url, title_watcher.get());
// Shift-reload to B. // Shift-reload to B.
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/common/security_style.h" #include "content/public/common/security_style.h"
#include "content/public/common/ssl_status.h" #include "content/public/common/ssl_status.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "net/base/cert_status_flags.h" #include "net/base/cert_status_flags.h"
#include "net/test/test_server.h" #include "net/test/test_server.h"
...@@ -528,7 +529,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { ...@@ -528,7 +529,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) {
// Setup page title observer. // Setup page title observer.
WebContents* tab = chrome::GetActiveWebContents(browser()); WebContents* tab = chrome::GetActiveWebContents(browser());
ui_test_utils::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Create GURLs to test pages. // Create GURLs to test pages.
...@@ -578,7 +579,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { ...@@ -578,7 +579,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
// Setup page title observer. // Setup page title observer.
WebContents* tab = chrome::GetActiveWebContents(browser()); WebContents* tab = chrome::GetActiveWebContents(browser());
ui_test_utils::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Visit bad HTTPS page. // Visit bad HTTPS page.
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "content/public/common/page_transition_types.h" #include "content/public/common/page_transition_types.h"
#include "content/public/common/renderer_preferences.h" #include "content/public/common/renderer_preferences.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "net/base/mock_host_resolver.h" #include "net/base/mock_host_resolver.h"
...@@ -1436,7 +1437,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, WindowOpenClose) { ...@@ -1436,7 +1437,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, WindowOpenClose) {
FilePath(), FilePath().AppendASCII("window.close.html")); FilePath(), FilePath().AppendASCII("window.close.html"));
string16 title = ASCIIToUTF16("Title Of Awesomeness"); string16 title = ASCIIToUTF16("Title Of Awesomeness");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), title); chrome::GetActiveWebContents(browser()), title);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2);
EXPECT_EQ(title, title_watcher.WaitAndGetTitle()); EXPECT_EQ(title, title_watcher.WaitAndGetTitle());
...@@ -1458,7 +1459,7 @@ IN_PROC_BROWSER_TEST_F(ShowModalDialogTest, BasicTest) { ...@@ -1458,7 +1459,7 @@ IN_PROC_BROWSER_TEST_F(ShowModalDialogTest, BasicTest) {
FilePath(), FilePath().AppendASCII("showmodaldialog.html")); FilePath(), FilePath().AppendASCII("showmodaldialog.html"));
string16 expected_title(ASCIIToUTF16("SUCCESS")); string16 expected_title(ASCIIToUTF16("SUCCESS"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
...@@ -1471,7 +1472,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DisallowFileUrlUniversalAccessTest) { ...@@ -1471,7 +1472,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DisallowFileUrlUniversalAccessTest) {
FilePath(), FilePath().AppendASCII("fileurl_universalaccess.html")); FilePath(), FilePath().AppendASCII("fileurl_universalaccess.html"));
string16 expected_title(ASCIIToUTF16("Disallowed")); string16 expected_title(ASCIIToUTF16("Disallowed"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("Allowed")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("Allowed"));
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "net/base/auth.h" #include "net/base/auth.h"
#include "net/base/mock_host_resolver.h" #include "net/base/mock_host_resolver.h"
...@@ -314,7 +315,7 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) { ...@@ -314,7 +315,7 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestBasicAuth) {
string16 expected_title = string16 expected_title =
ExpectedTitleFromAuth(ASCIIToUTF16("basicuser"), ASCIIToUTF16("secret")); ExpectedTitleFromAuth(ASCIIToUTF16("basicuser"), ASCIIToUTF16("secret"));
ui_test_utils::TitleWatcher title_watcher(contents, expected_title); content::TitleWatcher title_watcher(contents, expected_title);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
} }
...@@ -363,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) { ...@@ -363,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestDigestAuth) {
auth_supplied_waiter.Wait(); auth_supplied_waiter.Wait();
string16 expected_title = ExpectedTitleFromAuth(username, password); string16 expected_title = ExpectedTitleFromAuth(username, password);
ui_test_utils::TitleWatcher title_watcher(contents, expected_title); content::TitleWatcher title_watcher(contents, expected_title);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
} }
...@@ -413,8 +414,8 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) { ...@@ -413,8 +414,8 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestTwoAuths) {
UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_));
string16 expected_title2 = ExpectedTitleFromAuth( string16 expected_title2 = ExpectedTitleFromAuth(
UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_));
ui_test_utils::TitleWatcher title_watcher1(contents1, expected_title1); content::TitleWatcher title_watcher1(contents1, expected_title1);
ui_test_utils::TitleWatcher title_watcher2(contents2, expected_title2); content::TitleWatcher title_watcher2(contents2, expected_title2);
handler1->SetAuth(UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_)); handler1->SetAuth(UTF8ToUTF16(username_basic_), UTF8ToUTF16(password_));
handler2->SetAuth(UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_)); handler2->SetAuth(UTF8ToUTF16(username_digest_), UTF8ToUTF16(password_));
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h" #include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -1380,8 +1381,8 @@ IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, OnBeforeUnloadOnClose) { ...@@ -1380,8 +1381,8 @@ IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, OnBeforeUnloadOnClose) {
// Close panel and respond to the onbeforeunload dialog with cancel. This is // Close panel and respond to the onbeforeunload dialog with cancel. This is
// equivalent to clicking "Stay on this page" // equivalent to clicking "Stay on this page"
scoped_ptr<ui_test_utils::TitleWatcher> title_watcher( scoped_ptr<content::TitleWatcher> title_watcher(
new ui_test_utils::TitleWatcher(web_contents, title_first_close)); new content::TitleWatcher(web_contents, title_first_close));
panel->Close(); panel->Close();
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
alert->native_dialog()->CancelAppModalDialog(); alert->native_dialog()->CancelAppModalDialog();
...@@ -1391,7 +1392,7 @@ IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, OnBeforeUnloadOnClose) { ...@@ -1391,7 +1392,7 @@ IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, OnBeforeUnloadOnClose) {
// Close panel and respond to the onbeforeunload dialog with close. This is // Close panel and respond to the onbeforeunload dialog with close. This is
// equivalent to clicking the OS close button on the dialog. // equivalent to clicking the OS close button on the dialog.
title_watcher.reset( title_watcher.reset(
new ui_test_utils::TitleWatcher(web_contents, title_second_close)); new content::TitleWatcher(web_contents, title_second_close));
panel->Close(); panel->Close();
alert = ui_test_utils::WaitForAppModalDialog(); alert = ui_test_utils::WaitForAppModalDialog();
alert->native_dialog()->CloseAppModalDialog(); alert->native_dialog()->CloseAppModalDialog();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h" #include "content/test/net/url_request_mock_http_job.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
...@@ -275,7 +276,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { ...@@ -275,7 +276,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
// won't put up the beforeunload dialog because it's waiting for an ack from // won't put up the beforeunload dialog because it's waiting for an ack from
// the renderer. // the renderer.
string16 expected_title = ASCIIToUTF16("cancelled"); string16 expected_title = ASCIIToUTF16("cancelled");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
ClickModalDialogButton(false); ClickModalDialogButton(false);
ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
......
...@@ -979,73 +979,6 @@ void WindowedTabAddedNotificationObserver::Observe( ...@@ -979,73 +979,6 @@ void WindowedTabAddedNotificationObserver::Observe(
content::WindowedNotificationObserver::Observe(type, source, details); content::WindowedNotificationObserver::Observe(type, source, details);
} }
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,
content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
content::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,
content::NOTIFICATION_LOAD_STOP,
content::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 content::MessageLoopRunner;
message_loop_runner_->Run();
return observed_title_;
}
void TitleWatcher::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) {
WebContents* source_contents = content::Source<WebContents>(source).ptr();
ASSERT_EQ(web_contents_, source_contents);
} else if (type == content::NOTIFICATION_LOAD_STOP) {
NavigationController* controller =
content::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();
}
}
BrowserAddedObserver::BrowserAddedObserver() BrowserAddedObserver::BrowserAddedObserver()
: notification_observer_( : notification_observer_(
chrome::NOTIFICATION_BROWSER_OPENED, chrome::NOTIFICATION_BROWSER_OPENED,
......
...@@ -425,44 +425,6 @@ class WindowedNotificationObserverWithDetails ...@@ -425,44 +425,6 @@ class WindowedNotificationObserverWithDetails
DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserverWithDetails); DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserverWithDetails);
}; };
// Watches title changes on a tab, blocking until an expected title is set.
class TitleWatcher : public content::NotificationObserver {
public:
// |web_contents| must be non-NULL and needs to stay alive for the
// entire lifetime of |this|. |expected_title| is the title that |this|
// will wait for.
TitleWatcher(content::WebContents* web_contents,
const string16& expected_title);
virtual ~TitleWatcher();
// Adds another title to watch for.
void AlsoWaitForTitle(const string16& expected_title);
// Waits until the title matches either expected_title or one of the titles
// added with AlsoWaitForTitle. Returns the value of the most recently
// observed matching title.
const string16& WaitAndGetTitle() WARN_UNUSED_RESULT;
private:
// content::NotificationObserver
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
content::WebContents* web_contents_;
std::vector<string16> expected_titles_;
content::NotificationRegistrar notification_registrar_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
// The most recently observed expected title, if any.
string16 observed_title_;
bool expected_title_observed_;
bool quit_loop_on_observation_;
DISALLOW_COPY_AND_ASSIGN(TitleWatcher);
};
// Convenience class for waiting for a new browser to be created. // Convenience class for waiting for a new browser to be created.
// Like WindowedNotificationObserver, this class provides a safe, non-racey // Like WindowedNotificationObserver, this class provides a safe, non-racey
// way to wait for a new browser to be created. // way to wait for a new browser to be created.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/layout_browsertest.h" #include "content/test/layout_browsertest.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
...@@ -30,7 +31,7 @@ class MediaTest : public InProcessBrowserTest { ...@@ -30,7 +31,7 @@ class MediaTest : public InProcessBrowserTest {
const string16 kPlaying = ASCIIToUTF16("PLAYING"); const string16 kPlaying = ASCIIToUTF16("PLAYING");
const string16 kFailed = ASCIIToUTF16("FAILED"); const string16 kFailed = ASCIIToUTF16("FAILED");
const string16 kError = ASCIIToUTF16("ERROR"); const string16 kError = ASCIIToUTF16("ERROR");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), kPlaying); chrome::GetActiveWebContents(browser()), kPlaying);
title_watcher.AlsoWaitForTitle(kFailed); title_watcher.AlsoWaitForTitle(kFailed);
title_watcher.AlsoWaitForTitle(kError); title_watcher.AlsoWaitForTitle(kError);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/ui_controls/ui_controls.h" #include "ui/ui_controls/ui_controls.h"
namespace { namespace {
...@@ -51,7 +52,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { ...@@ -51,7 +52,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) {
// Navigate to the test html page. // Navigate to the test html page.
string16 load_expected_title(ASCIIToUTF16("onload")); string16 load_expected_title(ASCIIToUTF16("onload"));
ui_test_utils::TitleWatcher load_title_watcher(tab, load_expected_title); content::TitleWatcher load_title_watcher(tab, load_expected_title);
ui_test_utils::NavigateToURL(browser(), test_url); ui_test_utils::NavigateToURL(browser(), test_url);
// Wait for the onload() handler to complete so we can do the // Wait for the onload() handler to complete so we can do the
// next part of the test. // next part of the test.
...@@ -63,8 +64,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { ...@@ -63,8 +64,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) {
// Wait on the correct intermediate title. // Wait on the correct intermediate title.
string16 entered_expected_title(ASCIIToUTF16("entered")); string16 entered_expected_title(ASCIIToUTF16("entered"));
ui_test_utils::TitleWatcher entered_title_watcher( content::TitleWatcher entered_title_watcher(tab, entered_expected_title);
tab, entered_expected_title);
EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle()); EXPECT_EQ(entered_expected_title, entered_title_watcher.WaitAndGetTitle());
// Move the cursor above the content again, which should trigger // Move the cursor above the content again, which should trigger
...@@ -73,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) { ...@@ -73,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_TestOnMouseOut) {
// Wait on the correct final value of the cookie. // Wait on the correct final value of the cookie.
string16 left_expected_title(ASCIIToUTF16("left")); string16 left_expected_title(ASCIIToUTF16("left"));
ui_test_utils::TitleWatcher left_title_watcher(tab, left_expected_title); content::TitleWatcher left_title_watcher(tab, left_expected_title);
EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle()); EXPECT_EQ(left_expected_title, left_title_watcher.WaitAndGetTitle());
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h" #include "content/test/net/url_request_mock_http_job.h"
#include "webkit/plugins/plugin_switches.h" #include "webkit/plugins/plugin_switches.h"
...@@ -84,7 +85,7 @@ class PluginTest : public InProcessBrowserTest { ...@@ -84,7 +85,7 @@ class PluginTest : public InProcessBrowserTest {
void LoadAndWait(const GURL& url) { void LoadAndWait(const GURL& url) {
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("plugin_not_found")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("plugin_not_found"));
...@@ -175,7 +176,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest, ...@@ -175,7 +176,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest,
browser(), GetURL("execute_script_delete_in_mouse_up.html")); browser(), GetURL("execute_script_delete_in_mouse_up.html"));
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser())); ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser()));
...@@ -202,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInvokeAlert) { ...@@ -202,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest, SelfDeletePluginInvokeAlert) {
0); 0);
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
...@@ -400,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_PluginConvertPointTest) { ...@@ -400,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_PluginConvertPointTest) {
ui_test_utils::NavigateToURL(browser(), GetURL("convert_point.html")); ui_test_utils::NavigateToURL(browser(), GetURL("convert_point.html"));
string16 expected_title(ASCIIToUTF16("OK")); string16 expected_title(ASCIIToUTF16("OK"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// TODO(stuartmorgan): When the automation system supports sending clicks, // TODO(stuartmorgan): When the automation system supports sending clicks,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_failed_job.h" #include "content/test/net/url_request_failed_job.h"
#include "content/test/net/url_request_mock_http_job.h" #include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -86,7 +87,7 @@ class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest, ...@@ -86,7 +87,7 @@ class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest,
const std::string& expected_title, const std::string& expected_title,
int expected_navigations) { int expected_navigations) {
string16 expected_title16(ASCIIToUTF16(expected_title)); string16 expected_title16(ASCIIToUTF16(expected_title));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title16); chrome::GetActiveWebContents(browser()), expected_title16);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), url, expected_navigations); browser(), url, expected_navigations);
...@@ -400,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ...@@ -400,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
// pages of which the error page is one. Instead, use automation to kick // pages of which the error page is one. Instead, use automation to kick
// off the navigation, and wait to see that the tab loads. // off the navigation, and wait to see that the tab loads.
string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness"));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title16); chrome::GetActiveWebContents(browser()), expected_title16);
bool success; bool success;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/test_server.h" #include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -68,7 +69,7 @@ class SessionHistoryTest : public InProcessBrowserTest { ...@@ -68,7 +69,7 @@ class SessionHistoryTest : public InProcessBrowserTest {
void NavigateAndCheckTitle(const char* filename, void NavigateAndCheckTitle(const char* filename,
const std::string& expected_title) { const std::string& expected_title) {
string16 expected_title16(ASCIIToUTF16(expected_title)); string16 expected_title16(ASCIIToUTF16(expected_title));
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title16); chrome::GetActiveWebContents(browser()), expected_title16);
ui_test_utils::NavigateToURL(browser(), GetURL(filename)); ui_test_utils::NavigateToURL(browser(), GetURL(filename));
ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/browser/worker_host/worker_service_impl.h" #include "content/browser/worker_host/worker_service_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/layout_browsertest.h" #include "content/test/layout_browsertest.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
...@@ -287,7 +288,7 @@ class WorkerTest : public InProcessBrowserTest { ...@@ -287,7 +288,7 @@ class WorkerTest : public InProcessBrowserTest {
const std::string& query) { const std::string& query) {
GURL url = GetTestURL(test_case, query); GURL url = GetTestURL(test_case, query);
const string16 expected_title = ASCIIToUTF16("OK"); const string16 expected_title = ASCIIToUTF16("OK");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser), expected_title); chrome::GetActiveWebContents(browser), expected_title);
ui_test_utils::NavigateToURL(browser, url); ui_test_utils::NavigateToURL(browser, url);
string16 final_title = title_watcher.WaitAndGetTitle(); string16 final_title = title_watcher.WaitAndGetTitle();
......
...@@ -5,7 +5,14 @@ ...@@ -5,7 +5,14 @@
#ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
#define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
#include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
namespace base { namespace base {
...@@ -21,6 +28,47 @@ class RunLoop; ...@@ -21,6 +28,47 @@ class RunLoop;
namespace content { namespace content {
class MessageLoopRunner;
class WebContents;
// Watches title changes on a tab, blocking until an expected title is set.
class TitleWatcher : public NotificationObserver {
public:
// |web_contents| must be non-NULL and needs to stay alive for the
// entire lifetime of |this|. |expected_title| is the title that |this|
// will wait for.
TitleWatcher(WebContents* web_contents,
const string16& expected_title);
virtual ~TitleWatcher();
// Adds another title to watch for.
void AlsoWaitForTitle(const string16& expected_title);
// Waits until the title matches either expected_title or one of the titles
// added with AlsoWaitForTitle. Returns the value of the most recently
// observed matching title.
const string16& WaitAndGetTitle() WARN_UNUSED_RESULT;
private:
// NotificationObserver
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
WebContents* web_contents_;
std::vector<string16> expected_titles_;
NotificationRegistrar notification_registrar_;
scoped_refptr<MessageLoopRunner> message_loop_runner_;
// The most recently observed expected title, if any.
string16 observed_title_;
bool expected_title_observed_;
bool quit_loop_on_observation_;
DISALLOW_COPY_AND_ASSIGN(TitleWatcher);
};
} // namespace content } // namespace content
#endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
...@@ -4,6 +4,78 @@ ...@@ -4,6 +4,78 @@
#include "content/public/test/browser_test_utils.h" #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 { 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 } // namespace content
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -185,7 +186,7 @@ void InProcessBrowserLayoutTest::RunLayoutTestInternal( ...@@ -185,7 +186,7 @@ void InProcessBrowserLayoutTest::RunLayoutTestInternal(
const std::string& test_case_file_name, const GURL& url) { const std::string& test_case_file_name, const GURL& url) {
LOG(INFO) << "Navigating to URL " << url << " and blocking."; LOG(INFO) << "Navigating to URL " << url << " and blocking.";
const string16 expected_title = ASCIIToUTF16("done"); const string16 expected_title = ASCIIToUTF16("done");
ui_test_utils::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
chrome::GetActiveWebContents(browser()), expected_title); chrome::GetActiveWebContents(browser()), expected_title);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
LOG(INFO) << "Navigation completed, now waiting for title."; LOG(INFO) << "Navigation completed, now waiting for title.";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment