Commit 80b050cf authored by jam@chromium.org's avatar jam@chromium.org

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
parent 83afcbcc
...@@ -87,8 +87,6 @@ ...@@ -87,8 +87,6 @@
'test/data/content-sniffer-test3-frame.txt', 'test/data/content-sniffer-test3-frame.txt',
'test/data/content-sniffer-test3.html', 'test/data/content-sniffer-test3.html',
'test/data/nosniff-test.html', 'test/data/nosniff-test.html',
'test/data/speech/basic_recognition.html',
'test/data/speech/grammar_attribute.html',
'test/data/title2.html', 'test/data/title2.html',
], ],
}, },
...@@ -640,8 +638,6 @@ ...@@ -640,8 +638,6 @@
'test/data/showmodaldialog.html', 'test/data/showmodaldialog.html',
'test/data/showmodaldialog_dialog.html', 'test/data/showmodaldialog_dialog.html',
'test/data/simple.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/blank_page.html',
'test/data/ssl/frame_left.html', 'test/data/ssl/frame_left.html',
'test/data/ssl/frame_right.html', 'test/data/ssl/frame_right.html',
......
...@@ -3039,8 +3039,6 @@ ...@@ -3039,8 +3039,6 @@
'../content/browser/renderer_host/render_process_host_browsertest.cc', '../content/browser/renderer_host/render_process_host_browsertest.cc',
'../content/browser/renderer_host/render_view_host_manager_browsertest.cc', '../content/browser/renderer_host/render_view_host_manager_browsertest.cc',
'../content/browser/renderer_host/resource_dispatcher_host_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': [ 'rules': [
{ {
......
<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>
<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>
<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>
<title>Default Title</title>
<style>
iframe { width: 98%; height: 96%; }
</style>
<iframe src="location_redirect_frame1.html"></iframe>
<script>
function navigate() {
location = "location_redirect_frame2.html";
}
</script>
<script>
parent.document.title = "foo";
</script>
<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>
<script>
history_length = history.length;
</script>
<html>
<head><title>redirecting</title></head>
<body onload="location.replace(location.search.substring(1))">redirecting...</body>
</html>
<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>
<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>
<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>
...@@ -6,13 +6,10 @@ ...@@ -6,13 +6,10 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.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/renderer_host/render_view_host_impl.h"
#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "content/browser/speech/input_tag_speech_dispatcher_host.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
...@@ -20,9 +17,15 @@ ...@@ -20,9 +17,15 @@
#include "content/public/browser/speech_recognition_manager.h" #include "content/public/browser/speech_recognition_manager.h"
#include "content/public/browser/speech_recognition_session_config.h" #include "content/public/browser/speech_recognition_session_config.h"
#include "content/public/browser/speech_recognition_session_context.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/content_switches.h"
#include "content/public/common/speech_recognition_error.h" #include "content/public/common/speech_recognition_error.h"
#include "content/public/common/speech_recognition_result.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" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
using content::SpeechRecognitionEventListener; using content::SpeechRecognitionEventListener;
...@@ -181,25 +184,20 @@ class FakeSpeechRecognitionManager : public content::SpeechRecognitionManager { ...@@ -181,25 +184,20 @@ class FakeSpeechRecognitionManager : public content::SpeechRecognitionManager {
base::WaitableEvent recognition_started_event_; base::WaitableEvent recognition_started_event_;
}; };
class SpeechRecognitionBrowserTest : public InProcessBrowserTest { class SpeechRecognitionBrowserTest : public content::ContentBrowserTest {
public: public:
// InProcessBrowserTest methods // ContentBrowserTest methods
virtual void SetUpCommandLine(CommandLine* command_line) { virtual void SetUpCommandLine(CommandLine* command_line) {
EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableSpeechInput)); 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: 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 // 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 // load & sets that coordinate in the URL fragment. We send mouse down & up
// events at that coordinate to trigger speech recognition. // events at that coordinate to trigger speech recognition.
GURL test_url = testUrl(filename); GURL test_url = content::GetTestUrl("speech", filename);
ui_test_utils::NavigateToURL(browser(), test_url); content::NavigateToURL(shell(), test_url);
WebKit::WebMouseEvent mouse_event; WebKit::WebMouseEvent mouse_event;
mouse_event.type = WebKit::WebInputEvent::MouseDown; mouse_event.type = WebKit::WebInputEvent::MouseDown;
...@@ -207,7 +205,7 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest { ...@@ -207,7 +205,7 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest {
mouse_event.x = 0; mouse_event.x = 0;
mouse_event.y = 0; mouse_event.y = 0;
mouse_event.clickCount = 1; mouse_event.clickCount = 1;
WebContents* web_contents = chrome::GetActiveWebContents(browser()); WebContents* web_contents = shell()->web_contents();
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP, content::NOTIFICATION_LOAD_STOP,
...@@ -224,16 +222,16 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest { ...@@ -224,16 +222,16 @@ class SpeechRecognitionBrowserTest : public InProcessBrowserTest {
observer.Wait(); observer.Wait();
} }
void RunSpeechRecognitionTest(const FilePath::CharType* filename) { void RunSpeechRecognitionTest(const char* filename) {
// The fake speech input manager would receive the speech input // The fake speech input manager would receive the speech input
// request and return the test string as recognition result. The test page // 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. // then sets the URL fragment as 'pass' if it received the expected string.
LoadAndStartSpeechRecognitionTest(filename); 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() { virtual void SetUpInProcessBrowserTestFixture() {
fake_speech_recognition_manager_.set_should_send_fake_response(true); fake_speech_recognition_manager_.set_should_send_fake_response(true);
speech_recognition_manager_ = &fake_speech_recognition_manager_; speech_recognition_manager_ = &fake_speech_recognition_manager_;
...@@ -268,12 +266,12 @@ content::SpeechRecognitionManager* ...@@ -268,12 +266,12 @@ content::SpeechRecognitionManager*
// a renderer crashes, we get a call to // a renderer crashes, we get a call to
// SpeechRecognitionManager::CancelAllRequestsWithDelegate. // SpeechRecognitionManager::CancelAllRequestsWithDelegate.
IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) { 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()); EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty());
} }
IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) { 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", EXPECT_EQ("http://example.com/grammar.xml",
fake_speech_recognition_manager_.grammar()); fake_speech_recognition_manager_.grammar());
} }
...@@ -285,13 +283,11 @@ IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) { ...@@ -285,13 +283,11 @@ IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) {
// test page JavaScript in this case. // test page JavaScript in this case.
fake_speech_recognition_manager_.set_should_send_fake_response(false); fake_speech_recognition_manager_.set_should_send_fake_response(false);
LoadAndStartSpeechRecognitionTest( LoadAndStartSpeechRecognitionTest("basic_recognition.html");
FILE_PATH_LITERAL("basic_recognition.html"));
// Make the renderer crash. This should trigger // Make the renderer crash. This should trigger
// InputTagSpeechDispatcherHost to cancel all pending sessions. // InputTagSpeechDispatcherHost to cancel all pending sessions.
GURL test_url("about:crash"); content::NavigateToURL(shell(), GURL(chrome::kChromeUICrashURL));
ui_test_utils::NavigateToURL(browser(), test_url);
EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all()); EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all());
} }
......
...@@ -570,6 +570,8 @@ ...@@ -570,6 +570,8 @@
'browser/plugin_browsertest.cc', 'browser/plugin_browsertest.cc',
'browser/plugin_service_impl_browsertest.cc', 'browser/plugin_service_impl_browsertest.cc',
'browser/renderer_host/render_view_host_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/webkit_browsertest.cc',
'browser/worker_host/test/worker_browsertest.cc', 'browser/worker_host/test/worker_browsertest.cc',
'renderer/mouse_lock_dispatcher_browsertest.cc', 'renderer/mouse_lock_dispatcher_browsertest.cc',
......
...@@ -27,13 +27,12 @@ typedef struct _GtkToolItem GtkToolItem; ...@@ -27,13 +27,12 @@ typedef struct _GtkToolItem GtkToolItem;
#endif #endif
class GURL; class GURL;
class WebContents;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class ShellJavaScriptDialogCreator; class ShellJavaScriptDialogCreator;
class SiteInstance; class SiteInstance;
class WebContents;
// This represents one window of the Content Shell, i.e. all the UI including // 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. // buttons and url bar, as well as the web content area.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/shell/shell.h" #include "content/shell/shell.h"
#include "content/shell/shell_browser_context.h" #include "content/shell/shell_browser_context.h"
#include "content/shell/shell_content_browser_client.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_main_delegate.h"
#include "content/shell/shell_switches.h" #include "content/shell/shell_switches.h"
#include "content/test/test_content_client.h" #include "content/test/test_content_client.h"
...@@ -56,6 +57,15 @@ void ContentBrowserTest::SetUp() { ...@@ -56,6 +57,15 @@ void ContentBrowserTest::SetUp() {
SetUpCommandLine(command_line); 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) #if defined(OS_MACOSX)
// See InProcessBrowserTest::PrepareTestCommandLine(). // See InProcessBrowserTest::PrepareTestCommandLine().
FilePath subprocess_path; FilePath subprocess_path;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
class GURL; class GURL;
namespace content { namespace content {
class ContentRendererClient;
class Shell; class Shell;
class ShellMainDelegate; class ShellMainDelegate;
...@@ -41,6 +42,9 @@ class ContentBrowserTest : public BrowserTestBase { ...@@ -41,6 +42,9 @@ class ContentBrowserTest : public BrowserTestBase {
scoped_ptr<content::ShellMainDelegate> shell_main_delegate_; scoped_ptr<content::ShellMainDelegate> shell_main_delegate_;
Shell* shell_; Shell* shell_;
// ContentRendererClient when running in single-process mode.
scoped_ptr<ContentRendererClient> single_process_renderer_client_;
}; };
} // namespace content } // namespace content
......
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