From 17c4f3c7c289c840f8b285f7834ab7007f85e35e Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Sat, 4 Jul 2009 16:36:25 +0000 Subject: 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 --- .../1.0.0.0/toolstrip1.html | 45 +++++----------------- .../1.0.0.0/toolstrip2.html | 21 ---------- chrome/test/in_process_browser_test.cc | 1 + chrome/test/in_process_browser_test.h | 4 ++ chrome/test/ui_test_utils.cc | 26 +++++++------ chrome/test/ui_test_utils.h | 10 ++--- 6 files changed, 34 insertions(+), 73 deletions(-) (limited to 'chrome/test') 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 @@ - - -
-
- 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 @@ - - -
- -
- 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(tab_contents)); + Source(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(ExecuteJavaScript(tab_contents, frame_xpath, script)); + scoped_ptr 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(ExecuteJavaScript(tab_contents, frame_xpath, script)); + scoped_ptr 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(ExecuteJavaScript(tab_contents, frame_xpath, script)); + scoped_ptr 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); -- cgit v1.1