Fixed alert/confirm/prompt crashing the page

This commit is contained in:
Joe Ferris 2011-03-11 12:07:30 -05:00
parent 6c247a0669
commit 30d90f9f35
3 changed files with 47 additions and 0 deletions

View File

@ -437,4 +437,29 @@ describe Capybara::Driver::Webkit do
subject.find("//p").first.text.should == "/next"
end
end
context "popup app" do
before(:all) do
@app = lambda do |env|
body = <<-HTML
<html><body>
<script type="text/javascript">
alert("alert");
confirm("confirm");
prompt("prompt");
</script>
<p>success</p>
</body></html>
HTML
sleep(0.5)
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end
end
it "doesn't crash from alerts" do
subject.find("//p").first.text.should == "success"
end
end
end

View File

@ -43,6 +43,25 @@ void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, c
std::cout << qPrintable(message) << std::endl;
}
void WebPage::javaScriptAlert(QWebFrame *frame, const QString &message) {
Q_UNUSED(frame);
std::cout << "ALERT: " << qPrintable(message) << std::endl;
}
bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &message) {
Q_UNUSED(frame);
Q_UNUSED(message);
return true;
}
bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result) {
Q_UNUSED(frame)
Q_UNUSED(message)
Q_UNUSED(defaultValue)
Q_UNUSED(result)
return false;
}
void WebPage::loadStarted() {
m_loading = true;
}

View File

@ -18,6 +18,9 @@ class WebPage : public QWebPage {
protected:
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
virtual void javaScriptAlert(QWebFrame *frame, const QString &message);
virtual bool javaScriptConfirm(QWebFrame *frame, const QString &message);
virtual bool javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result);
private:
QString m_capybaraJavascript;