diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 03:11:56 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 03:11:56 +0000 |
commit | 80b050cf2b5f38f77c51000f65c111bcc6ded331 (patch) | |
tree | 5d7dec7da50501b0fe4219e40e5a0e1082e13784 | |
parent | 83afcbcc9bf7be3cdf91a4a6af573638c042a694 (diff) | |
download | chromium_src-80b050cf2b5f38f77c51000f65c111bcc6ded331.zip chromium_src-80b050cf2b5f38f77c51000f65c111bcc6ded331.tar.gz chromium_src-80b050cf2b5f38f77c51000f65c111bcc6ded331.tar.bz2 |
Convert speech and session history browser_tests to run under content_browsertests.
Also add support for single-process.
BUG=90448
Review URL: https://chromiumcodereview.appspot.com/10820043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148711 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 98 insertions, 288 deletions
diff --git a/chrome/browser_tests.isolate b/chrome/browser_tests.isolate index 00930ed..2c4e06a 100644 --- a/chrome/browser_tests.isolate +++ b/chrome/browser_tests.isolate @@ -87,8 +87,6 @@ 'test/data/content-sniffer-test3-frame.txt', 'test/data/content-sniffer-test3.html', 'test/data/nosniff-test.html', - 'test/data/speech/basic_recognition.html', - 'test/data/speech/grammar_attribute.html', 'test/data/title2.html', ], }, @@ -640,8 +638,6 @@ 'test/data/showmodaldialog.html', 'test/data/showmodaldialog_dialog.html', 'test/data/simple.html', - 'test/data/speech/basic_recognition.html', - 'test/data/speech/grammar_attribute.html', 'test/data/ssl/blank_page.html', 'test/data/ssl/frame_left.html', 'test/data/ssl/frame_right.html', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 42468e9..f4ab4bab 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3039,8 +3039,6 @@ '../content/browser/renderer_host/render_process_host_browsertest.cc', '../content/browser/renderer_host/render_view_host_manager_browsertest.cc', '../content/browser/renderer_host/resource_dispatcher_host_browsertest.cc', - '../content/browser/session_history_browsertest.cc', - '../content/browser/speech/speech_recognition_browsertest.cc', ], 'rules': [ { diff --git a/chrome/test/data/session_history/form.html b/chrome/test/data/session_history/form.html deleted file mode 100644 index f20e02d..0000000 --- a/chrome/test/data/session_history/form.html +++ /dev/null @@ -1,31 +0,0 @@ -<html> -<head> -<title>form</title> -<script> -// Simulate the user clicking on the submit button. -function submitForm(name) { - var node = document.getElementById(name); - node.click(); -} -// Simulate the user filling a form value. -function fillForm(name, value) { - var node = document.getElementById(name); - node.value = value; -} -</script> -</head> -<body> - -<form method="post" action="/echotitle"> - -<p><input name="text" id="itext"> -<p><select name="select" id="iselect"> - <option selected>a - <option>b - <option>c -</select> -<p><input type="submit" value="Submit" id="isubmit"> - -</form> -</body> -</html> diff --git a/chrome/test/data/session_history/fragment.html b/chrome/test/data/session_history/fragment.html deleted file mode 100644 index b5d6601..0000000 --- a/chrome/test/data/session_history/fragment.html +++ /dev/null @@ -1,12 +0,0 @@ -<html> -<head><title>fragment</title></head> -<body> -A page with anchor fragment targets. -<p> -<a name="a">What's this? A reference fragment?</a> -<p> -<a name="b">And another!</a> -<p> -<a name="c">Last one, I promise.</a> -</body> -</html> diff --git a/chrome/test/data/session_history/frames.html b/chrome/test/data/session_history/frames.html deleted file mode 100644 index a28c4e6..0000000 --- a/chrome/test/data/session_history/frames.html +++ /dev/null @@ -1,45 +0,0 @@ -<html> -<head> -<title>bot1</title> -<script> -// --- Convenience functions for testing. -function setTitle() { - var fbot = document.getElementById("fbot"); - document.title = fbot.contentDocument.title; -} -// Simulate the user clicking a link. -function clickLink(name) { - var ftop = document.getElementById("ftop"); - var node = ftop.contentDocument.getElementById(name); - var evt = document.createEvent("MouseEvents"); - evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, - false, false, false, false, 0, null); - node.dispatchEvent(evt); -} -// Simulate the user filling a form value. -function fillForm(name, value) { - var fbot = document.getElementById("fbot"); - var node = fbot.contentDocument.getElementById(name); - node.value = value; -} -// Simulate the user clicking on the submit button. -function submitForm(name) { - var fbot = document.getElementById("fbot"); - var node = fbot.contentDocument.getElementById(name); - node.click(); -} -function init() { - var fbot = document.getElementById("fbot"); - // This will set our title to the bottom frame, so we can test that - // we actually navigated. - fbot.onload = setTitle; -} -</script> -</head> - -<frameset onLoad="init()" rows="20%,80%" name="main"> - <frame src="top.html" id="ftop" name="top"> - <frame src="bot1.html" id="fbot" name="bottom"> -</frameset> - -</html> diff --git a/chrome/test/data/session_history/location_redirect.html b/chrome/test/data/session_history/location_redirect.html deleted file mode 100644 index 07f0f2a..0000000 --- a/chrome/test/data/session_history/location_redirect.html +++ /dev/null @@ -1,5 +0,0 @@ -<title>Default Title</title> -<style> -iframe { width: 98%; height: 96%; } -</style> -<iframe src="location_redirect_frame1.html"></iframe> diff --git a/chrome/test/data/session_history/location_redirect_frame1.html b/chrome/test/data/session_history/location_redirect_frame1.html deleted file mode 100644 index 3b9c05e..0000000 --- a/chrome/test/data/session_history/location_redirect_frame1.html +++ /dev/null @@ -1,5 +0,0 @@ -<script> -function navigate() { - location = "location_redirect_frame2.html"; -} -</script> diff --git a/chrome/test/data/session_history/location_redirect_frame2.html b/chrome/test/data/session_history/location_redirect_frame2.html deleted file mode 100644 index 21e040e..0000000 --- a/chrome/test/data/session_history/location_redirect_frame2.html +++ /dev/null @@ -1,3 +0,0 @@ -<script> -parent.document.title = "foo"; -</script> diff --git a/chrome/test/data/session_history/no-title.html b/chrome/test/data/session_history/no-title.html deleted file mode 100644 index ff70517..0000000 --- a/chrome/test/data/session_history/no-title.html +++ /dev/null @@ -1 +0,0 @@ -<body>no title specified</body> diff --git a/chrome/test/data/session_history/post.html b/chrome/test/data/session_history/post.html deleted file mode 100644 index ab89b76..0000000 --- a/chrome/test/data/session_history/post.html +++ /dev/null @@ -1,28 +0,0 @@ -<html> -<head> -<title>post</title> -<script> -// stolen from darin's page cycler -var options = location.search.substring(1).split('&'); - -function getopt(name) { - var r = new RegExp("^" + name + "="); - for (i = 0; i < options.length; ++i) { - if (options[i].match(r)) { - return options[i].substring(name.length + 1); - } - } - return null; -} - -function checkParams() { - document.title = "post:" + getopt("text") + "," + getopt("select"); -} -checkParams(); -</script> -</head> - -<body> -Form submission accepted. Thanks for playing. -</body> -</html> diff --git a/chrome/test/data/session_history/record_length.html b/chrome/test/data/session_history/record_length.html deleted file mode 100644 index 0fb4f70..0000000 --- a/chrome/test/data/session_history/record_length.html +++ /dev/null @@ -1,3 +0,0 @@ -<script> -history_length = history.length; -</script> diff --git a/chrome/test/data/session_history/replace.html b/chrome/test/data/session_history/replace.html deleted file mode 100644 index 4c79a6f..0000000 --- a/chrome/test/data/session_history/replace.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>redirecting</title></head> -<body onload="location.replace(location.search.substring(1))">redirecting...</body> -</html> diff --git a/chrome/test/data/session_history/top.html b/chrome/test/data/session_history/top.html deleted file mode 100644 index 70e3c71..0000000 --- a/chrome/test/data/session_history/top.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<body> -<a href="bot1.html" id="abot1" target="bottom">bot1</a> -<a href="bot2.html" id="abot2" target="bottom">bot2</a> -<a href="bot3.html" id="abot3" target="bottom">bot3</a> -<a href="form.html" id="aform" target="bottom">form</a> -</body> -</html> diff --git a/chrome/test/data/speech/basic_recognition.html b/chrome/test/data/speech/basic_recognition.html deleted file mode 100644 index f40f595..0000000 --- a/chrome/test/data/speech/basic_recognition.html +++ /dev/null @@ -1,23 +0,0 @@ -<html> - <head> - <title>Speech input test</title> - <script type="text/javascript"> - function onspeechresult(value) { - if (value == "Pictures of the moon") { - document.getElementById('status').innerHTML = 'PASS'; - document.location = '#pass'; - } else { - document.location = '#fail'; - } - } - </script> - </head> - <body style="padding:0; margin:0;"> - <input id='inputField' x-webkit-speech - onwebkitspeechchange="onspeechresult(this.value);" - onchange="onspeechresult(this.value);" - style="position:absolute; margin:0; padding:0; border:0; width:10px;"> - <br> - <div id="status">FAIL</div> - </body> -</html> diff --git a/chrome/test/data/speech/grammar_attribute.html b/chrome/test/data/speech/grammar_attribute.html deleted file mode 100644 index 93f41d3..0000000 --- a/chrome/test/data/speech/grammar_attribute.html +++ /dev/null @@ -1,24 +0,0 @@ -<html> - <head> - <title>Speech input with grammar attribute test</title> - <script type="text/javascript"> - function onspeechresult(value) { - if (value == "Pictures of the moon") { - document.getElementById('status').innerHTML = 'PASS'; - document.location = '#pass'; - } else { - document.location = '#fail'; - } - } - </script> - </head> - <body style="padding:0; margin:0;"> - <input id='inputField' x-webkit-speech - x-webkit-grammar="http://example.com/grammar.xml" - onwebkitspeechchange="onspeechresult(this.value);" - onchange="onspeechresult(this.value);" - style="position:absolute; margin:0; padding:0; border:0; width:10px;"> - <br> - <div id="status">FAIL</div> - </body> -</html> diff --git a/content/browser/session_history_browsertest.cc b/content/browser/session_history_browsertest.cc index 176f7c7..232ad17 100644 --- a/content/browser/session_history_browsertest.cc +++ b/content/browser/session_history_browsertest.cc @@ -4,31 +4,34 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_commands.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" #include "content/public/common/url_constants.h" #include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_utils.h" +#include "content/shell/shell.h" +#include "content/test/content_browser_test.h" +#include "content/test/content_browser_test_utils.h" #include "net/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" -class SessionHistoryTest : public InProcessBrowserTest { +namespace content { + +class SessionHistoryTest : public ContentBrowserTest { protected: SessionHistoryTest() {} virtual void SetUpOnMainThread() { ASSERT_TRUE(test_server()->Start()); + NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); } // Simulate clicking a link. Only works on the frames.html testserver page. void ClickLink(std::string node_id) { GURL url("javascript:clickLink('" + node_id + "')"); - ui_test_utils::NavigateToURL(browser(), url); + NavigateToURL(shell(), url); } // Simulate filling in form data. Only works on the frames.html page with @@ -38,28 +41,28 @@ class SessionHistoryTest : public InProcessBrowserTest { // This will return immediately, but since the JS executes synchronously // on the renderer, it will complete before the next navigate message is // processed. - ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0); + NavigateToURL(shell(), url); } // Simulate submitting a form. Only works on the frames.html page with // subframe = form.html, and on form.html itself. void SubmitForm(std::string node_id) { GURL url("javascript:submitForm('" + node_id + "')"); - ui_test_utils::NavigateToURL(browser(), url); + NavigateToURL(shell(), url); } // Navigate session history using history.go(distance). void JavascriptGo(std::string distance) { GURL url("javascript:history.go('" + distance + "')"); - ui_test_utils::NavigateToURL(browser(), url); + NavigateToURL(shell(), url); } std::string GetTabTitle() { - return UTF16ToASCII(chrome::GetActiveWebContents(browser())->GetTitle()); + return UTF16ToASCII(shell()->web_contents()->GetTitle()); } GURL GetTabURL() { - return chrome::GetActiveWebContents(browser())->GetURL(); + return shell()->web_contents()->GetURL(); } GURL GetURL(const std::string file) { @@ -69,25 +72,32 @@ class SessionHistoryTest : public InProcessBrowserTest { void NavigateAndCheckTitle(const char* filename, const std::string& expected_title) { string16 expected_title16(ASCIIToUTF16(expected_title)); - content::TitleWatcher title_watcher( - chrome::GetActiveWebContents(browser()), expected_title16); - ui_test_utils::NavigateToURL(browser(), GetURL(filename)); + TitleWatcher title_watcher(shell()->web_contents(), expected_title16); + NavigateToURL(shell(), GetURL(filename)); ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); } + bool CanGoBack() { + return shell()->web_contents()->GetController().CanGoBack(); + } + + bool CanGoForward() { + return shell()->web_contents()->GetController().CanGoForward(); + } + void GoBack() { - content::WindowedNotificationObserver load_stop_observer( - content::NOTIFICATION_LOAD_STOP, - content::NotificationService::AllSources()); - chrome::GoBack(browser(), CURRENT_TAB); + WindowedNotificationObserver load_stop_observer( + NOTIFICATION_LOAD_STOP, + NotificationService::AllSources()); + shell()->web_contents()->GetController().GoBack(); load_stop_observer.Wait(); } void GoForward() { - content::WindowedNotificationObserver load_stop_observer( - content::NOTIFICATION_LOAD_STOP, - content::NotificationService::AllSources()); - chrome::GoForward(browser(), CURRENT_TAB); + WindowedNotificationObserver load_stop_observer( + NOTIFICATION_LOAD_STOP, + NotificationService::AllSources()); + shell()->web_contents()->GetController().GoForward(); load_stop_observer.Wait(); } }; @@ -95,9 +105,7 @@ class SessionHistoryTest : public InProcessBrowserTest { // If this flakes, use http://crbug.com/61619 on windows and // http://crbug.com/102094 on mac. IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { - // about:blank should be loaded first. - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); + ASSERT_FALSE(CanGoBack()); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); @@ -121,7 +129,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { // history is [blank, bot1, *bot3] - ASSERT_FALSE(chrome::CanGoForward(browser())); + ASSERT_FALSE(CanGoForward()); EXPECT_EQ("bot3", GetTabTitle()); GoBack(); @@ -130,7 +138,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { GoBack(); EXPECT_EQ("about:blank", GetTabTitle()); - ASSERT_FALSE(chrome::CanGoBack(browser())); + ASSERT_FALSE(CanGoBack()); EXPECT_EQ("about:blank", GetTabTitle()); GoForward(); @@ -143,11 +151,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { // Test that back/forward works when navigating in subframes. // If this flakes, use http://crbug.com/48833 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { - // about:blank should be loaded first. - GURL home(chrome::kAboutBlankURL); - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); - EXPECT_EQ(GURL(chrome::kAboutBlankURL), GetTabURL()); + ASSERT_FALSE(CanGoBack()); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); @@ -172,7 +176,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { GoBack(); EXPECT_EQ("about:blank", GetTabTitle()); - EXPECT_EQ(home, GetTabURL()); + EXPECT_EQ(GURL(chrome::kAboutBlankURL), GetTabURL()); GoForward(); EXPECT_EQ("bot1", GetTabTitle()); @@ -188,7 +192,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { // history is [blank, bot1, bot2, *bot1] - ASSERT_FALSE(chrome::CanGoForward(browser())); + ASSERT_FALSE(CanGoForward()); EXPECT_EQ("bot1", GetTabTitle()); EXPECT_EQ(frames, GetTabURL()); @@ -204,9 +208,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { // Test that back/forward preserves POST data and document state in subframes. // If this flakes use http://crbug.com/61619 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) { - // about:blank should be loaded first. - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); + ASSERT_FALSE(CanGoBack()); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); @@ -259,9 +261,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) { // across frames (ie, from frame -> nonframe). // Hangs, see http://crbug.com/45058. IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { - // about:blank should be loaded first. - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); + ASSERT_FALSE(CanGoBack()); GURL frames(GetURL("frames.html")); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); @@ -297,9 +297,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { // navigations. Bug 730379. // If this flakes use http://crbug.com/61619. IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { - // about:blank should be loaded first. - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); + ASSERT_FALSE(CanGoBack()); GURL fragment(GetURL("fragment.html")); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment")); @@ -326,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { // history is [blank, fragment, fragment#a, bot3] - ASSERT_FALSE(chrome::CanGoForward(browser())); + ASSERT_FALSE(CanGoForward()); EXPECT_EQ(GetURL("bot3.html"), GetTabURL()); GoBack(); @@ -345,9 +343,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { - // about:blank should be loaded first. - ASSERT_FALSE(chrome::CanGoBack(browser())); - EXPECT_EQ("about:blank", GetTabTitle()); + ASSERT_FALSE(CanGoBack()); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); @@ -375,7 +371,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { JavascriptGo("-3"); EXPECT_EQ("about:blank", GetTabTitle()); - ASSERT_FALSE(chrome::CanGoBack(browser())); + ASSERT_FALSE(CanGoBack()); EXPECT_EQ("about:blank", GetTabTitle()); JavascriptGo("1"); @@ -385,7 +381,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { // history is [blank, bot1, *bot3] - ASSERT_FALSE(chrome::CanGoForward(browser())); + ASSERT_FALSE(CanGoForward()); EXPECT_EQ("bot3", GetTabTitle()); JavascriptGo("-1"); @@ -394,7 +390,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { JavascriptGo("-1"); EXPECT_EQ("about:blank", GetTabTitle()); - ASSERT_FALSE(chrome::CanGoBack(browser())); + ASSERT_FALSE(CanGoBack()); EXPECT_EQ("about:blank", GetTabTitle()); JavascriptGo("1"); @@ -423,8 +419,7 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) { ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle( "location_redirect.html", "Default Title")); - ui_test_utils::NavigateToURL( - browser(), GURL("javascript:void(frames[0].navigate())")); + NavigateToURL(shell(), GURL("javascript:void(frames[0].navigate())")); EXPECT_EQ("foo", GetTabTitle()); GoBack(); @@ -434,23 +429,23 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) { // http://code.google.com/p/chromium/issues/detail?id=56267 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { int length; - ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + ASSERT_TRUE(ExecuteJavaScriptAndExtractInt( + shell()->web_contents()->GetRenderViewHost(), L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(1, length); - ui_test_utils::NavigateToURL(browser(), GetURL("title1.html")); + NavigateToURL(shell(), GetURL("title1.html")); - ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + ASSERT_TRUE(ExecuteJavaScriptAndExtractInt( + shell()->web_contents()->GetRenderViewHost(), L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(2, length); // Now test that history.length is updated when the navigation is committed. - ui_test_utils::NavigateToURL(browser(), GetURL("record_length.html")); + NavigateToURL(shell(), GetURL("record_length.html")); - ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + ASSERT_TRUE(ExecuteJavaScriptAndExtractInt( + shell()->web_contents()->GetRenderViewHost(), L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(3, length); @@ -458,10 +453,12 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { GoBack(); // Ensure history.length is properly truncated. - ui_test_utils::NavigateToURL(browser(), GetURL("title2.html")); + NavigateToURL(shell(), GetURL("title2.html")); - ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + ASSERT_TRUE(ExecuteJavaScriptAndExtractInt( + shell()->web_contents()->GetRenderViewHost(), L"", L"domAutomationController.send(history.length)", &length)); EXPECT_EQ(2, length); } + +} // namespace content diff --git a/content/browser/speech/speech_recognition_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc index 9d62a17..1497201 100644 --- a/content/browser/speech/speech_recognition_browsertest.cc +++ b/content/browser/speech/speech_recognition_browsertest.cc @@ -6,13 +6,10 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "base/string_number_conversions.h" #include "base/synchronization/waitable_event.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "content/browser/web_contents/web_contents_impl.h" @@ -20,9 +17,15 @@ #include "content/public/browser/speech_recognition_manager.h" #include "content/public/browser/speech_recognition_session_config.h" #include "content/public/browser/speech_recognition_session_context.h" +#include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" #include "content/public/common/speech_recognition_error.h" #include "content/public/common/speech_recognition_result.h" +#include "content/public/common/url_constants.h" +#include "content/public/test/test_utils.h" +#include "content/shell/shell.h" +#include "content/test/content_browser_test.h" +#include "content/test/content_browser_test_utils.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" using content::SpeechRecognitionEventListener; @@ -181,25 +184,20 @@ class FakeSpeechRecognitionManager : public content::SpeechRecognitionManager { base::WaitableEvent recognition_started_event_; }; -class SpeechRecognitionBrowserTest : public InProcessBrowserTest { +class SpeechRecognitionBrowserTest : public content::ContentBrowserTest { public: - // InProcessBrowserTest methods + // ContentBrowserTest methods virtual void SetUpCommandLine(CommandLine* command_line) { EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableSpeechInput)); } - GURL testUrl(const FilePath::CharType* filename) { - const FilePath kTestDir(FILE_PATH_LITERAL("speech")); - return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename)); - } - protected: - void LoadAndStartSpeechRecognitionTest(const FilePath::CharType* filename) { + void LoadAndStartSpeechRecognitionTest(const char* filename) { // The test page calculates the speech button's coordinate in the page on // load & sets that coordinate in the URL fragment. We send mouse down & up // events at that coordinate to trigger speech recognition. - GURL test_url = testUrl(filename); - ui_test_utils::NavigateToURL(browser(), test_url); + GURL test_url = content::GetTestUrl("speech", filename); + content::NavigateToURL(shell(), test_url); WebKit::WebMouseEvent mouse_event; mouse_event.type = WebKit::WebInputEvent::MouseDown; @@ -207,7 +205,7 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest { mouse_event.x = 0; mouse_event.y = 0; mouse_event.clickCount = 1; - WebContents* web_contents = chrome::GetActiveWebContents(browser()); + WebContents* web_contents = shell()->web_contents(); content::WindowedNotificationObserver observer( content::NOTIFICATION_LOAD_STOP, @@ -224,16 +222,16 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest { observer.Wait(); } - void RunSpeechRecognitionTest(const FilePath::CharType* filename) { + void RunSpeechRecognitionTest(const char* filename) { // The fake speech input manager would receive the speech input // request and return the test string as recognition result. The test page // then sets the URL fragment as 'pass' if it received the expected string. LoadAndStartSpeechRecognitionTest(filename); - EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); + EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref()); } - // InProcessBrowserTest methods. + // ContentBrowserTest methods. virtual void SetUpInProcessBrowserTestFixture() { fake_speech_recognition_manager_.set_should_send_fake_response(true); speech_recognition_manager_ = &fake_speech_recognition_manager_; @@ -268,12 +266,12 @@ content::SpeechRecognitionManager* // a renderer crashes, we get a call to // SpeechRecognitionManager::CancelAllRequestsWithDelegate. IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) { - RunSpeechRecognitionTest(FILE_PATH_LITERAL("basic_recognition.html")); + RunSpeechRecognitionTest("basic_recognition.html"); EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty()); } IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) { - RunSpeechRecognitionTest(FILE_PATH_LITERAL("grammar_attribute.html")); + RunSpeechRecognitionTest("grammar_attribute.html"); EXPECT_EQ("http://example.com/grammar.xml", fake_speech_recognition_manager_.grammar()); } @@ -285,13 +283,11 @@ IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) { // test page JavaScript in this case. fake_speech_recognition_manager_.set_should_send_fake_response(false); - LoadAndStartSpeechRecognitionTest( - FILE_PATH_LITERAL("basic_recognition.html")); + LoadAndStartSpeechRecognitionTest("basic_recognition.html"); // Make the renderer crash. This should trigger // InputTagSpeechDispatcherHost to cancel all pending sessions. - GURL test_url("about:crash"); - ui_test_utils::NavigateToURL(browser(), test_url); + content::NavigateToURL(shell(), GURL(chrome::kChromeUICrashURL)); EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all()); } diff --git a/content/content_tests.gypi b/content/content_tests.gypi index a973c80..d897ef5 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -570,6 +570,8 @@ 'browser/plugin_browsertest.cc', 'browser/plugin_service_impl_browsertest.cc', 'browser/renderer_host/render_view_host_browsertest.cc', + 'browser/session_history_browsertest.cc', + 'browser/speech/speech_recognition_browsertest.cc', 'browser/webkit_browsertest.cc', 'browser/worker_host/test/worker_browsertest.cc', 'renderer/mouse_lock_dispatcher_browsertest.cc', diff --git a/content/shell/shell.h b/content/shell/shell.h index 1ac10fc..d8cbc35 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -27,13 +27,12 @@ typedef struct _GtkToolItem GtkToolItem; #endif class GURL; -class WebContents; - namespace content { class BrowserContext; class ShellJavaScriptDialogCreator; class SiteInstance; +class WebContents; // This represents one window of the Content Shell, i.e. all the UI including // buttons and url bar, as well as the web content area. diff --git a/content/test/content_browser_test.cc b/content/test/content_browser_test.cc index 6ba8a3f..0fab44b 100644 --- a/content/test/content_browser_test.cc +++ b/content/test/content_browser_test.cc @@ -16,6 +16,7 @@ #include "content/shell/shell.h" #include "content/shell/shell_browser_context.h" #include "content/shell/shell_content_browser_client.h" +#include "content/shell/shell_content_renderer_client.h" #include "content/shell/shell_main_delegate.h" #include "content/shell/shell_switches.h" #include "content/test/test_content_client.h" @@ -56,6 +57,15 @@ void ContentBrowserTest::SetUp() { SetUpCommandLine(command_line); + // Single-process mode is not set in BrowserMain, so process it explicitly, + // and set up renderer. + if (command_line->HasSwitch(switches::kSingleProcess)) { + RenderProcessHost::set_run_renderer_in_process(true); + single_process_renderer_client_.reset(new ShellContentRendererClient); + content::GetContentClient()->set_renderer_for_testing( + single_process_renderer_client_.get()); + } + #if defined(OS_MACOSX) // See InProcessBrowserTest::PrepareTestCommandLine(). FilePath subprocess_path; diff --git a/content/test/content_browser_test.h b/content/test/content_browser_test.h index c9b6da2..5870bb0 100644 --- a/content/test/content_browser_test.h +++ b/content/test/content_browser_test.h @@ -12,6 +12,7 @@ class GURL; namespace content { +class ContentRendererClient; class Shell; class ShellMainDelegate; @@ -41,6 +42,9 @@ class ContentBrowserTest : public BrowserTestBase { scoped_ptr<content::ShellMainDelegate> shell_main_delegate_; Shell* shell_; + + // ContentRendererClient when running in single-process mode. + scoped_ptr<ContentRendererClient> single_process_renderer_client_; }; } // namespace content |