summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-04 16:36:25 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-04 16:36:25 +0000
commit17c4f3c7c289c840f8b285f7834ab7007f85e35e (patch)
treee21af5a41aba26623cf56d6fe2412c34a32daafc /chrome/test
parentcd659ee5e9e02a3fdf261fb9ebdf25801661b5fa (diff)
downloadchromium_src-17c4f3c7c289c840f8b285f7834ab7007f85e35e.zip
chromium_src-17c4f3c7c289c840f8b285f7834ab7007f85e35e.tar.gz
chromium_src-17c4f3c7c289c840f8b285f7834ab7007f85e35e.tar.bz2
Add an ExtensionBrowserTest base class that allows in-process browser tests of extensions using ExtensionsService directly, rather than TestExtensionLoaded. Use it to re-enable some old browser tests that had been disabled.
Review URL: http://codereview.chromium.org/150213 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19930 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html45
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip2.html21
-rw-r--r--chrome/test/in_process_browser_test.cc1
-rw-r--r--chrome/test/in_process_browser_test.h4
-rw-r--r--chrome/test/ui_test_utils.cc26
-rw-r--r--chrome/test/ui_test_utils.h10
6 files changed, 34 insertions, 73 deletions
diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
index d36de21..d0a1f21 100644
--- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
@@ -1,41 +1,16 @@
-<style>
-body {
- overflow: hidden;
- margin: 0 0 0 0;
-}
-
-/* TODO: put the background style into body when
- https://bugs.webkit.org/show_bug.cgi?id=18445 is fixed. */
-.content {
- background: -webkit-gradient(linear, left top, left bottom, from(rgb(222, 234, 248)), to(rgb(237, 244, 252)));
- padding: 1;
- white-space: nowrap;
-}
-</style>
-<body>
-<div class="content">
<script>
- // ExtensionViewTest depends on this alert, even though it doesn't work in
- // the real browser.
- alert('Sir, I exist');
- console.log('Sir, I exist');
+// This function is called from the C++ browser test. It does a basic sanity
+// test that we can call extension APIs.
+function testTabsAPI() {
+ console.log(chrome.tabs);
- chromium.onconnect.addListener(function (port) {
- port.onmessage.addListener(doOnMessage);
- port.postMessage('extension onconnect: ' + port.tab.url);
+ chrome.tabs.getAllInWindow(null, function(tabs) {
+ window.domAutomationController.send(tabs.length == 1);
});
-
- function doOnMessage(msg, port) {
- if (!port.didRespond) {
- port.postMessage('extension msg ack: ' + msg);
- port.didRespond = true;
- }
- }
+}
</script>
<select>
-<option>one</option>
-<option>two</option>
-<option>three</option>
+ <option>one</option>
+ <option>two</option>
+ <option>three</option>
</select>
-</div>
-</body>
diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip2.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip2.html
index 23a2edf..568a6da 100644
--- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip2.html
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip2.html
@@ -1,22 +1 @@
-<style>
-body {
- overflow: hidden;
- margin: 0 0 0 0;
-}
-
-/* TODO: put the background style into body when
- https://bugs.webkit.org/show_bug.cgi?id=18445 is fixed. */
-.content {
- background: -webkit-gradient(linear, left top, left bottom, from(rgb(222, 234, 248)), to(rgb(237, 244, 252)));
- padding: 1;
- white-space: nowrap;
-}
-</style>
-<body>
-<div class="content">
-<script>
- alert(window.extension.getTestString());
-</script>
<button onclick="window.open('http://www.google.com', 'mywindow', 'width=640, height=480');">HTML button</button>
-</div>
-</body>
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index e698e27..bbfdb64 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -218,6 +218,7 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
kInitialTimeoutInMS);
RunTestOnMainThread();
+ CleanUpOnMainThread();
BrowserList::const_iterator browser = BrowserList::begin();
for (; browser != BrowserList::end(); ++browser)
diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h
index 27f5bff..64bf1ea 100644
--- a/chrome/test/in_process_browser_test.h
+++ b/chrome/test/in_process_browser_test.h
@@ -62,6 +62,10 @@ class InProcessBrowserTest : public testing::Test {
// Override this to add command line flags specific to your test.
virtual void SetUpCommandLine(CommandLine* command_line) {}
+ // Override this to add any custom cleanup code that needs to be done on the
+ // main thread before the browser is torn down.
+ virtual void CleanUpOnMainThread() {}
+
// Allows subclasses to configure the host mapper. By default this blocks
// requests to google.com as Chrome pings that on startup and we don't want to
// do that during testing.
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index ffe7a2e..ac55380 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -75,9 +75,9 @@ class NavigationNotificationObserver : public NotificationObserver {
class DOMOperationObserver : public NotificationObserver {
public:
- explicit DOMOperationObserver(TabContents* tab_contents) {
+ explicit DOMOperationObserver(RenderViewHost* render_view_host) {
registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
- Source<TabContents>(tab_contents));
+ Source<RenderViewHost>(render_view_host));
RunMessageLoop();
}
@@ -230,16 +230,15 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
WaitForNavigations(controller, number_of_navigations);
}
-Value* ExecuteJavaScript(TabContents* tab_contents,
+Value* ExecuteJavaScript(RenderViewHost* render_view_host,
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);
+ render_view_host->ExecuteJavascriptInWebFrame(frame_xpath, script);
+ DOMOperationObserver dom_op_observer(render_view_host);
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.
@@ -259,36 +258,39 @@ Value* ExecuteJavaScript(TabContents* tab_contents,
return result;
}
-bool ExecuteJavaScriptAndExtractInt(TabContents* tab_contents,
+bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
int* result) {
DCHECK(result);
- scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ scoped_ptr<Value> value(ExecuteJavaScript(render_view_host, frame_xpath,
+ script));
if (!value.get())
return false;
return value->GetAsInteger(result);
}
-bool ExecuteJavaScriptAndExtractBool(TabContents* tab_contents,
+bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
bool* result) {
DCHECK(result);
- scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ scoped_ptr<Value> value(ExecuteJavaScript(render_view_host, frame_xpath,
+ script));
if (!value.get())
return false;
return value->GetAsBoolean(result);
}
-bool ExecuteJavaScriptAndExtractString(TabContents* tab_contents,
+bool ExecuteJavaScriptAndExtractString(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
std::string* result) {
DCHECK(result);
- scoped_ptr<Value> value(ExecuteJavaScript(tab_contents, frame_xpath, script));
+ scoped_ptr<Value> value(ExecuteJavaScript(render_view_host, frame_xpath,
+ script));
if (!value.get())
return false;
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index 2554a7d..bdae24c 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -14,8 +14,8 @@ class Browser;
class DownloadManager;
class GURL;
class NavigationController;
+class RenderViewHost;
class Value;
-class TabContents;
// A collections of functions designed for use with InProcessBrowserTest.
namespace ui_test_utils {
@@ -48,7 +48,7 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
// 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,
+Value* ExecuteJavaScript(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script);
@@ -59,15 +59,15 @@ Value* ExecuteJavaScript(TabContents* tab_contents,
// 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,
+bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
int* result);
-bool ExecuteJavaScriptAndExtractBool(TabContents* tab_contents,
+bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
bool* result);
-bool ExecuteJavaScriptAndExtractString(TabContents* tab_contents,
+bool ExecuteJavaScriptAndExtractString(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& script,
std::string* result);