summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-29 22:24:01 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-29 22:24:01 +0000
commit45671618a6690a8501f01905a4ed6d19cfcdc0b1 (patch)
tree92137770b65d54fb7b025e7d004bc3c0c107955f /chrome/test
parent30369d92f0970a3b4f8720a00449023cb171fd28 (diff)
downloadchromium_src-45671618a6690a8501f01905a4ed6d19cfcdc0b1.zip
chromium_src-45671618a6690a8501f01905a4ed6d19cfcdc0b1.tar.gz
chromium_src-45671618a6690a8501f01905a4ed6d19cfcdc0b1.tar.bz2
Migrating the SSL UI tests to be browser tests.
Reenabling all of them. Hopefully it'll help with flakiness. Note that I am keeping the SSL UI tests alive until the browser test framework has been ported to Mac and Linux. BUG=6584,2136 TEST=Run the browser tests. Review URL: http://codereview.chromium.org/101013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14901 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/ssl/google.html2
-rw-r--r--chrome/test/ui_test_utils.cc117
-rw-r--r--chrome/test/ui_test_utils.h61
3 files changed, 114 insertions, 66 deletions
diff --git a/chrome/test/data/ssl/google.html b/chrome/test/data/ssl/google.html
index 3ef1ca1..ac08534 100644
--- a/chrome/test/data/ssl/google.html
+++ b/chrome/test/data/ssl/google.html
@@ -1,4 +1,4 @@
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><style>body,td,a,p,.h{font-family:arial,sans-serif}.h{font-size:20px}.h{color:#3366cc}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}#gbar{float:left;font-weight:bold;height:22px;padding-left:2px}.gbh,.gb2 div{border-top:1px solid #c9d7f1;font-size:0;height:0}.gbh{position:absolute;top:24px;width:100%}.gb2 div{margin:5px}#gbi{background:#fff;border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;font-size:13px;top:24px;z-index:1000}#guser{padding-bottom:7px !important}#gbar,#guser{font-size:13px;padding-top:1px !important}@media all{.gb1,.gb3{height:22px;margin-right:.73em;vertical-align:top}.gb2 a{display:block;padding:.2em .5em}}#gbi,.gb2{display:none;position:absolute;width:8em}.gb2{z-index:1001}#gbar a,#gbar a:active,#gbar a:visited{color:#00c;font-weight:normal}.gb2 a,.gb3 a{text-decoration:none}#gbar .gb2 a:hover{background:#36c;color:#fff;display:block}</style><script>window.google={kEI:"BuG9R7b_PI6SoASYhdTtDQ",kEXPI:"17259,17735,17870",kHL:"en"};
function sf(){document.f.q.focus()}
window.rwt=function(b,d,e,g,h,f,i){var a=encodeURIComponent||escape,c=b.href.split("#");b.href="/url?sa=t"+(d?"&oi="+a(d):"")+(e?"&cad="+a(e):"")+"&ct="+a(g)+"&cd="+a(h)+"&url="+a(c[0]).replace(/\+/g,"%2B")+"&ei=BuG9R7b_PI6SoASYhdTtDQ"+(f?"&usg="+f:"")+i+(c[1]?"#"+c[1]:"");b.onmousedown="";return true};
-window.gbar={};(function(){var a=window.gbar,b,g,h;function l(c,f,e){c.display=h?"none":"block";c.left=f+"px";c.top=e+"px"}a.tg=function(c){var f=0,e=0,d,m=0,n,j=window.navExtra,k,i=document;g=g||i.getElementById("gbar").getElementsByTagName("span");(c||window.event).cancelBubble=!m;if(!b){b=i.createElement(Array.every||window.createPopup?"iframe":"DIV");b.frameBorder="0";b.scrolling="no";b.src="#";g[7].parentNode.appendChild(b).id="gbi";if(j&&g[7])for(n in j){k=i.createElement("span");k.appendChild(j[n]);g[7].parentNode.insertBefore(k,g[7]).className="gb2"}i.onclick=a.close}while(d=g[++m]){if(e){l(d.style,e+1,f+25);f+=d.firstChild.tagName=="DIV"?9:20}if(d.className=="gb3"){do e+=d.offsetLeft;while(d=d.offsetParent)}}b.style.height=f+"px";l(b.style,e,24);h=!h};a.close=function(c){h&&a.tg(c)}})();</script></head><body onload="sf();if(document.images){new Image().src='/images/nav_logo3.png'}" topmargin="3" alink="#ff0000" bgcolor="#ffffff" link="#0000cc" marginheight="3" text="#000000" vlink="#551a8b"><div id="gbar"><nobr><span class="gb1">Web</span> <span class="gb1"><a href="http://images.google.com/imghp?hl=en&amp;tab=wi">Images</a></span> <span class="gb1"><a href="http://maps.google.com/maps?hl=en&amp;tab=wl">Maps</a></span> <span class="gb1"><a href="http://news.google.com/nwshp?hl=en&amp;tab=wn">News</a></span> <span class="gb1"><a href="http://www.google.com/prdhp?hl=en&amp;tab=wf">Shopping</a></span> <span class="gb1"><a href="http://mail.google.com/mail/?hl=en&amp;tab=wm">Gmail</a></span> <span class="gb3"><a href="http://www.google.com/intl/en/options/" onclick="this.blur();gbar.tg(event);return !1"><u>more</u> <small>▼</small></a></span> <span class="gb2"><a href="http://video.google.com/?hl=en&amp;tab=wv">Video</a></span> <span class="gb2"><a href="http://groups.google.com/grphp?hl=en&amp;tab=wg">Groups</a></span> <span class="gb2"><a href="http://books.google.com/bkshp?hl=en&amp;tab=wp">Books</a></span> <span class="gb2"><a href="http://scholar.google.com/schhp?hl=en&amp;tab=ws">Scholar</a></span> <span class="gb2"><a href="http://finance.google.com/finance?hl=en&amp;tab=we">Finance</a></span> <span class="gb2"><a href="http://blogsearch.google.com/?hl=en&amp;tab=wb">Blogs</a></span> <span class="gb2"><div></div></span> <span class="gb2"><a href="http://www.youtube.com/?hl=en&amp;tab=w1">YouTube</a></span> <span class="gb2"><a href="http://www.google.com/calendar/render?hl=en&amp;tab=wc">Calendar</a></span> <span class="gb2"><a href="http://picasaweb.google.com/home?hl=en&amp;tab=wq">Photos</a></span> <span class="gb2"><a href="http://docs.google.com/?hl=en&amp;tab=wo">Documents</a></span> <span class="gb2"><a href="http://www.google.com/reader/view/?hl=en&amp;tab=wy">Reader</a></span> <span class="gb2"><div></div></span> <span class="gb2"><a href="http://www.google.com/intl/en/options/">even more »</a></span> </nobr></div><div class="gbh" style="left: 0pt;"></div><div class="gbh" style="right: 0pt;"></div><div id="guser" style="padding: 0pt 0pt 4px; font-size: 84%;" width="100%" align="right"><nobr><b>jcampan@gmail.com</b> | <a href="http://www.google.com/url?sa=p&amp;pref=ig&amp;pval=3&amp;q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&amp;usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg">iGoogle</a> | <a href="https://www.google.com/accounts/ManageAccount">My Account</a> | <a href="http://www.google.com/accounts/Logout?continue=http://www.google.com/">Sign out</a></nobr></div><center><br id="lgpd" clear="all"><img alt="Google" src="google_files/logo.gif" height="110" width="276"><br><br><form action="/search" name="f"><table cellpadding="0" cellspacing="0"><tbody><tr valign="top"><td width="25%">&nbsp;</td><td align="center" nowrap="nowrap"><input name="hl" value="en" type="hidden"><input maxlength="2048" name="q" size="55" title="Google Search" value=""><br><input name="btnG" value="Google Search" type="submit"><input name="btnI" value="I'm Feeling Lucky" type="submit"></td><td nowrap="nowrap" width="25%"><font size="-2">&nbsp;&nbsp;<a href="http://www.google.com/advanced_search?hl=en">Advanced Search</a><br>&nbsp;&nbsp;<a href="http://www.google.com/preferences?hl=en">Preferences</a><br>&nbsp;&nbsp;<a href="http://www.google.com/language_tools?hl=en">Language Tools</a></font></td></tr></tbody></table></form><br><br><font size="-1"><a href="http://www.google.com/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="http://www.google.com/services/">Business Solutions</a> - <a href="http://www.google.com/intl/en/about.html">About Google</a></font><p><font size="-2">©2008 Google</font></p></center></body></html> \ No newline at end of file
+window.gbar={};(function(){var a=window.gbar,b,g,h;function l(c,f,e){c.display=h?"none":"block";c.left=f+"px";c.top=e+"px"}a.tg=function(c){var f=0,e=0,d,m=0,n,j=window.navExtra,k,i=document;g=g||i.getElementById("gbar").getElementsByTagName("span");(c||window.event).cancelBubble=!m;if(!b){b=i.createElement(Array.every||window.createPopup?"iframe":"DIV");b.frameBorder="0";b.scrolling="no";b.src="#";g[7].parentNode.appendChild(b).id="gbi";if(j&&g[7])for(n in j){k=i.createElement("span");k.appendChild(j[n]);g[7].parentNode.insertBefore(k,g[7]).className="gb2"}i.onclick=a.close}while(d=g[++m]){if(e){l(d.style,e+1,f+25);f+=d.firstChild.tagName=="DIV"?9:20}if(d.className=="gb3"){do e+=d.offsetLeft;while(d=d.offsetParent)}}b.style.height=f+"px";l(b.style,e,24);h=!h};a.close=function(c){h&&a.tg(c)}})();</script></head><body onload="sf();if(document.images){new Image().src='/images/nav_logo3.png'}" topmargin="3" alink="#ff0000" bgcolor="#ffffff" link="#0000cc" marginheight="3" text="#000000" vlink="#551a8b"><div id="gbar"><nobr><span class="gb1">Web</span> <span class="gb1"><a href="imghp?hl=en&amp;tab=wi">Images</a></span> <span class="gb1"><a href="maps?hl=en&amp;tab=wl">Maps</a></span> <span class="gb1"><a href="nwshp?hl=en&amp;tab=wn">News</a></span> <span class="gb1"><a href="prdhp?hl=en&amp;tab=wf">Shopping</a></span> <span class="gb1"><a href="mail/?hl=en&amp;tab=wm">Gmail</a></span> <span class="gb3"><a href="intl/en/options/" onclick="this.blur();gbar.tg(event);return !1"><u>more</u> <small>▼</small></a></span> <span class="gb2"><a href="?hl=en&amp;tab=wv">Video</a></span> <span class="gb2"><a href="grphp?hl=en&amp;tab=wg">Groups</a></span> <span class="gb2"><a href="bkshp?hl=en&amp;tab=wp">Books</a></span> <span class="gb2"><a href="schhp?hl=en&amp;tab=ws">Scholar</a></span> <span class="gb2"><a href="finance?hl=en&amp;tab=we">Finance</a></span> <span class="gb2"><a href="?hl=en&amp;tab=wb">Blogs</a></span> <span class="gb2"><div></div></span> <span class="gb2"><a href="?hl=en&amp;tab=w1">YouTube</a></span> <span class="gb2"><a href="calendar/render?hl=en&amp;tab=wc">Calendar</a></span> <span class="gb2"><a href="home?hl=en&amp;tab=wq">Photos</a></span> <span class="gb2"><a href="?hl=en&amp;tab=wo">Documents</a></span> <span class="gb2"><a href="reader/view/?hl=en&amp;tab=wy">Reader</a></span> <span class="gb2"><div></div></span> <span class="gb2"><a href="intl/en/options/">even more »</a></span> </nobr></div><div class="gbh" style="left: 0pt;"></div><div class="gbh" style="right: 0pt;"></div><div id="guser" style="padding: 0pt 0pt 4px; font-size: 84%;" width="100%" align="right"><nobr><b>jcampan@gmail.com</b> | <a href="url?sa=p&amp;pref=ig&amp;pval=3&amp;q=ig%3Fhl%3Den%26source%3Diglk&amp;usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg">iGoogle</a> | <a href="https://www.google.com/accounts/ManageAccount">My Account</a> | <a href="accounts/Logout?continue=">Sign out</a></nobr></div><center><br id="lgpd" clear="all"><img alt="Google" src="google_files/logo.gif" height="110" width="276"><br><br><form action="/search" name="f"><table cellpadding="0" cellspacing="0"><tbody><tr valign="top"><td width="25%">&nbsp;</td><td align="center" nowrap="nowrap"><input name="hl" value="en" type="hidden"><input maxlength="2048" name="q" size="55" title="Google Search" value=""><br><input name="btnG" value="Google Search" type="submit"><input name="btnI" value="I'm Feeling Lucky" type="submit"></td><td nowrap="nowrap" width="25%"><font size="-2">&nbsp;&nbsp;<a href="advanced_search?hl=en">Advanced Search</a><br>&nbsp;&nbsp;<a href="preferences?hl=en">Preferences</a><br>&nbsp;&nbsp;<a href="language_tools?hl=en">Language Tools</a></font></td></tr></tbody></table></form><br><br><font size="-1"><a href="intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="services/">Business Solutions</a> - <a href="intl/en/about.html">About Google</a></font><p><font size="-2">©2008 Google</font></p></center></body></html>
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index bd8ff59..6d9094b 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -4,11 +4,12 @@
#include "chrome/test/ui_test_utils.h"
+#include "base/json_reader.h"
#include "base/message_loop.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
-#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
#include "chrome/views/widget/accelerator_handler.h"
@@ -65,6 +66,32 @@ class NavigationNotificationObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
};
+class DOMOperationObserver : public NotificationObserver {
+ public:
+ explicit DOMOperationObserver(TabContents* tab_contents) {
+ registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
+ Source<TabContents>(tab_contents));
+ RunMessageLoop();
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::DOM_OPERATION_RESPONSE);
+ Details<DomOperationNotificationDetails> dom_op_details(details);
+ response_ = dom_op_details->json();
+ MessageLoopForUI::current()->Quit();
+ }
+
+ std::string response() const { return response_; }
+
+ private:
+ NotificationRegistrar registrar_;
+ std::string response_;
+
+ DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
+};
+
} // namespace
void RunMessageLoop() {
@@ -98,42 +125,68 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
WaitForNavigations(controller, number_of_navigations);
}
-JavaScriptRunner::JavaScriptRunner(WebContents* web_contents,
- const std::wstring& frame_xpath,
- const std::wstring& jscript)
- : web_contents_(web_contents),
- frame_xpath_(frame_xpath),
- jscript_(jscript) {
- NotificationService::current()->
- AddObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
- Source<WebContents>(web_contents));
+Value* ExecuteJavaScript(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& original_script) {
+ // TODO(jcampan): we should make the domAutomationController not require an
+ // automation id.
+ std::wstring script = L"window.domAutomationController.setAutomationId(0);" +
+ original_script;
+ tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(frame_xpath,
+ script);
+ DOMOperationObserver dom_op_observer(tab_contents);
+ std::string json = dom_op_observer.response();
+ // Wrap |json| in an array before deserializing because valid JSON has an
+ // array or an object as the root.
+ json.insert(0, "[");
+ json.append("]");
+
+ scoped_ptr<Value> root_val(JSONReader::Read(json, true));
+ if (!root_val->IsType(Value::TYPE_LIST))
+ return NULL;
+
+ ListValue* list = static_cast<ListValue*>(root_val.get());
+ Value* result;
+ if (!list || !list->GetSize() ||
+ !list->Remove(0, &result)) // Remove gives us ownership of the value.
+ return NULL;
+
+ return result;
}
-void JavaScriptRunner::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- Details<DomOperationNotificationDetails> dom_op_details(details);
- result_ = dom_op_details->json();
- // The Jasonified response has quotes, remove them.
- if (result_.length() > 1 && result_[0] == '"')
- result_ = result_.substr(1, result_.length() - 2);
-
- NotificationService::current()->
- RemoveObserver(this, NotificationType::DOM_OPERATION_RESPONSE,
- Source<WebContents>(web_contents_));
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+bool ExecuteJavaScriptAndExtractInt(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ int* result) {
+ DCHECK(result);
+ scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ if (!value.get())
+ return false;
+
+ return value->GetAsInteger(result);
}
-std::string JavaScriptRunner::Run() {
- // The DOMAutomationController requires an automation ID, even though we are
- // not using it in this case.
- web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(
- frame_xpath_, L"window.domAutomationController.setAutomationId(0);");
+bool ExecuteJavaScriptAndExtractBool(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ bool* result) {
+ DCHECK(result);
+ scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ if (!value.get())
+ return false;
- web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(frame_xpath_,
- jscript_);
- ui_test_utils::RunMessageLoop();
- return result_;
+ return value->GetAsBoolean(result);
}
+bool ExecuteJavaScriptAndExtractString(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ std::string* result) {
+ DCHECK(result);
+ scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ if (!value.get())
+ return false;
+
+ return value->GetAsString(result);
+}
} // namespace ui_test_utils
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index 863c758..3c166e8 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -13,7 +13,8 @@
class Browser;
class GURL;
class NavigationController;
-class WebContents;
+class Value;
+class TabContents;
// A collections of functions designed for use with InProcessBrowserTest.
namespace ui_test_utils {
@@ -43,38 +44,32 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
int number_of_navigations);
-// This class enables you to send JavaScript as a string from the browser to the
-// renderer for execution in a frame of your choice.
-class JavaScriptRunner : public NotificationObserver {
- public:
- // Constructor. |web_contents| is a pointer to the WebContents you want to run
- // the JavaScript code in. |frame_xpath| is a path to the frame to run it in.
- // |jscript| is a string containing the JavaScript code to run, for example:
- // "window.domAutomationController.send(alert('hello world'));". The
- // JavaScript code will execute when Run is called. Note: In order for the
- // domAutomationController to work, you must call EnableDOMAutomation() in
- // your test class first.
- JavaScriptRunner(WebContents* web_contents,
- const std::wstring& frame_xpath,
- const std::wstring& jscript);
-
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Executes the JavaScript code passed in to the constructor. See also comment
- // about EnableDOMAutomation in the constructor.
- std::string Run();
-
- private:
- WebContents* web_contents_;
- std::wstring frame_xpath_;
- std::wstring jscript_;
- std::string result_;
-
- DISALLOW_COPY_AND_ASSIGN(JavaScriptRunner);
-};
-
+// Executes the passed |script| in the frame pointed to by |frame_xpath| (use
+// empty string for main frame) and returns the value the evaluation of the
+// script returned. The caller owns the returned value.
+Value* ExecuteJavaScript(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script);
+
+// The following methods executes the passed |script| in the frame pointed to by
+// |frame_xpath| (use empty string for main frame) and sets |result| to the
+// value returned by the script evaluation.
+// They return true on success, false if the script evaluation failed or did not
+// evaluate to the expected type.
+// Note: In order for the domAutomationController to work, you must call
+// EnableDOMAutomation() in your test first.
+bool ExecuteJavaScriptAndExtractInt(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ int* result);
+bool ExecuteJavaScriptAndExtractBool(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ bool* result);
+bool ExecuteJavaScriptAndExtractString(TabContents* tab_contents,
+ const std::wstring& frame_xpath,
+ const std::wstring& script,
+ std::string* result);
}
#endif // CHROME_TEST_UI_TEST_UTILS_H_