summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-05 01:36:33 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-05 01:36:33 +0000
commitac51ee9169f4e65c3fe76754821fc0864520a612 (patch)
treef9af15fbdcecaa76766c64c23fdc74b2049ab40a /chrome/test
parentd928a845b0831a17b34e1ac0325517a49b00bcec (diff)
downloadchromium_src-ac51ee9169f4e65c3fe76754821fc0864520a612.zip
chromium_src-ac51ee9169f4e65c3fe76754821fc0864520a612.tar.gz
chromium_src-ac51ee9169f4e65c3fe76754821fc0864520a612.tar.bz2
Get rid of ExternalTabAutomationProxy by switching the extension UI
tests over to ExternalTabUITest. BUG=27326 TEST=ui_tests.exe Review URL: http://codereview.chromium.org/468013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc305
-rw-r--r--chrome/test/automation/automation_proxy_uitest.h172
2 files changed, 95 insertions, 382 deletions
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index 4a9dcdd..561173f 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -29,7 +29,6 @@
#include "chrome/test/ui/ui_test.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request_unittest.h"
-#include "testing/gmock/include/gmock/gmock.h"
#define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
#include "testing/gmock_mutant.h"
#include "views/event.h"
@@ -653,289 +652,53 @@ TEST_F(AutomationProxyTest, BlockedPopupTest) {
// TODO(port): Remove HWND if possible
#if defined(OS_WIN)
-static const wchar_t class_name[] = L"External_Tab_UI_Test_Class";
-static const wchar_t window_title[] = L"External Tab Tester";
-AutomationProxyForExternalTab::AutomationProxyForExternalTab(
- int execution_timeout)
+const char simple_data_url[] =
+ "data:text/html,<html><head><title>External tab test</title></head>"
+ "<body>A simple page for testing a floating/invisible tab<br></div>"
+ "</body></html>";
+
+ExternalTabUITestMockClient::ExternalTabUITestMockClient(int execution_timeout)
: AutomationProxy(execution_timeout),
- messages_received_(0),
- navigate_complete_(false),
- quit_after_(QUIT_INVALID),
- host_window_class_(NULL),
host_window_(NULL) {
}
-AutomationProxyForExternalTab::~AutomationProxyForExternalTab() {
- DestroyHostWindow();
- UnregisterClassW(host_window_class_, NULL);
-}
-
-gfx::NativeWindow AutomationProxyForExternalTab::CreateHostWindow() {
- DCHECK(!IsWindow(host_window_));
- if (!host_window_class_) {
- WNDCLASSEX wnd_class = {0};
- wnd_class.cbSize = sizeof(wnd_class);
- wnd_class.style = CS_HREDRAW | CS_VREDRAW;
- wnd_class.lpfnWndProc = DefWindowProc;
- wnd_class.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wnd_class.lpszClassName = class_name;
- host_window_class_ = reinterpret_cast<const wchar_t*>(
- RegisterClassEx(&wnd_class));
- if (!host_window_class_) {
- NOTREACHED() << "RegisterClassEx failed. Error: " << GetLastError();
- return false;
- }
- }
-
- unsigned long style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
- host_window_ = CreateWindow(host_window_class_, window_title, style,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL,
- NULL, NULL, NULL);
- if (!host_window_) {
- NOTREACHED() << "CreateWindow failed. Error: " << GetLastError();
- return false;
- }
-
- ShowWindow(host_window_, SW_SHOW);
- return host_window_;
+void ExternalTabUITestMockClient::ReplyStarted(
+ const IPC::AutomationURLResponse* response,
+ int tab_handle, int request_id) {
+ AutomationProxy::Send(new AutomationMsg_RequestStarted(0, tab_handle,
+ request_id, *response));
}
-scoped_refptr<TabProxy> AutomationProxyForExternalTab::CreateTabWithHostWindow(
- bool is_incognito, const GURL& initial_url,
- gfx::NativeWindow* container_wnd, gfx::NativeWindow* tab_wnd) {
- DCHECK(container_wnd);
- DCHECK(tab_wnd);
-
- CreateHostWindow();
- EXPECT_NE(FALSE, ::IsWindow(host_window_));
-
- RECT client_area = {0};
- GetClientRect(host_window_, &client_area);
-
- const IPC::ExternalTabSettings settings = {
- host_window_,
- gfx::Rect(client_area),
- WS_CHILD | WS_VISIBLE,
- is_incognito,
- false,
- false,
- initial_url
- };
-
- scoped_refptr<TabProxy> tab(CreateExternalTab(settings, container_wnd,
- tab_wnd));
-
- EXPECT_TRUE(tab != NULL);
- EXPECT_NE(FALSE, ::IsWindow(*container_wnd));
- EXPECT_NE(FALSE, ::IsWindow(*tab_wnd));
- return tab;
-}
-
-void AutomationProxyForExternalTab::DestroyHostWindow() {
- if (host_window_) {
- DestroyWindow(host_window_);
- host_window_ = NULL;
- }
-}
-
-bool AutomationProxyForExternalTab::WaitForNavigation(int timeout_ms) {
- set_quit_after(AutomationProxyForExternalTab::QUIT_AFTER_NAVIGATION);
- return RunMessageLoop(timeout_ms, NULL);
-}
-
-bool AutomationProxyForExternalTab::WaitForMessage(int timeout_ms) {
- set_quit_after(AutomationProxyForExternalTab::QUIT_AFTER_MESSAGE);
- return RunMessageLoop(timeout_ms, NULL);
-}
-
-bool AutomationProxyForExternalTab::WaitForTabCleanup(TabProxy* tab,
- int timeout_ms) {
- DCHECK(tab);
- base::Time end_time =
- base::Time::Now() + TimeDelta::FromMilliseconds(timeout_ms);
- while (base::Time::Now() < end_time) {
- const int kWaitInterval = 50;
- DWORD wait_result = MsgWaitForMultipleObjects(0, NULL, FALSE, kWaitInterval,
- QS_ALLINPUT);
- if (!tab->is_valid())
- break;
- if (WAIT_OBJECT_0 == wait_result) {
- MSG msg = {0};
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- }
-
- return !tab->is_valid();
+void ExternalTabUITestMockClient::ReplyData(
+ const std::string* data, int tab_handle, int request_id) {
+ AutomationProxy::Send(new AutomationMsg_RequestData(0, tab_handle,
+ request_id, *data));
}
-bool AutomationProxyForExternalTab::RunMessageLoop(
- int timeout_ms,
- gfx::NativeWindow window_to_monitor) {
- // If there's no host window then the abort or this loop will be stuck
- // in GetMessage
- if (!IsWindow(host_window_))
- return false;
-
- // Allow the renderers to connect.
- const int kTimerIdQuit = 100;
- const int kTimerIdProcessPendingMessages = 101;
-
- if (!window_to_monitor)
- window_to_monitor = host_window_;
-
- UINT_PTR quit_timer = ::SetTimer(host_window_, kTimerIdQuit,
- timeout_ms, NULL);
- UINT_PTR pump_timer = ::SetTimer(host_window_,
- kTimerIdProcessPendingMessages, 50, NULL);
-
- MSG msg;
- bool quit = false;
- do {
- BOOL ok = ::GetMessage(&msg, NULL, 0, 0);
- if (!ok || ok == -1)
- break;
-
- if (msg.message == WM_TIMER && msg.hwnd == host_window_) {
- switch (msg.wParam) {
- case kTimerIdProcessPendingMessages:
- MessageLoop::current()->RunAllPending();
- break;
- case kTimerIdQuit:
- quit = true;
- break;
- default:
- NOTREACHED() << "invalid timer id";
- break;
- }
- } else if ((msg.message == WM_QUIT) || (msg.message == kQuitLoopMessage)) {
- quit = true;
- } else {
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- } while (!quit && ::IsWindow(window_to_monitor));
-
- KillTimer(host_window_, quit_timer);
- KillTimer(host_window_, pump_timer);
- quit_after_ = QUIT_INVALID;
- return true;
+void ExternalTabUITestMockClient::ReplyEOF(int tab_handle, int request_id) {
+ AutomationProxy::Send(new AutomationMsg_RequestEnd(0, tab_handle,
+ request_id,
+ URLRequestStatus()));
}
-void AutomationProxyForExternalTab::OnMessageReceived(const IPC::Message& msg) {
- IPC_BEGIN_MESSAGE_MAP(AutomationProxyForExternalTab, msg)
- IPC_MESSAGE_HANDLER(AutomationMsg_DidNavigate, OnDidNavigate)
- IPC_MESSAGE_HANDLER(AutomationMsg_ForwardMessageToExternalHost,
- OnForwardMessageToExternalHost)
- IPC_END_MESSAGE_MAP()
+void ExternalTabUITestMockClient::Reply404(int tab_handle, int request_id) {
+ const IPC::AutomationURLResponse notfound = {"", "HTTP/1.1 404\r\n\r\n"};
+ ReplyStarted(&notfound, tab_handle, request_id);
+ ReplyEOF(tab_handle, request_id);
}
-void AutomationProxyForExternalTab::OnDidNavigate(
- int tab_handle,
- const IPC::NavigationInfo& nav_info) {
- navigate_complete_ = true;
- if (QUIT_AFTER_NAVIGATION == quit_after_)
- QuitLoop();
-}
+void ExternalTabUITestMockClient::InvalidateHandle(
+ const IPC::Message& message) {
+ void* iter = NULL;
+ int handle;
+ ASSERT_TRUE(message.ReadInt(&iter, &handle));
-void AutomationProxyForExternalTab::OnForwardMessageToExternalHost(
- int handle,
- const std::string& message,
- const std::string& origin,
- const std::string& target) {
- messages_received_++;
- message_ = message;
- origin_ = origin;
- target_ = target;
-
- if (QUIT_AFTER_MESSAGE == quit_after_)
- QuitLoop();
+ // Call base class
+ AutomationProxy::InvalidateHandle(message);
+ HandleClosed(handle);
}
-const char simple_data_url[] =
- "data:text/html,<html><head><title>External tab test</title></head>"
- "<body>A simple page for testing a floating/invisible tab<br></div>"
- "</body></html>";
-
-// We have to derive from AutomationProxy in order to hook up
-// OnMessageReceived callbacks.
-class ExternalTabUITestMockClient : public AutomationProxy {
- public:
- explicit ExternalTabUITestMockClient(int execution_timeout)
- : AutomationProxy(execution_timeout),
- host_window_(NULL) {
- }
-
- MOCK_METHOD2(OnDidNavigate, void(int tab_handle,
- const IPC::NavigationInfo& nav_info));
- MOCK_METHOD4(OnForwardMessageToExternalHost, void(int handle,
- const std::string& message, const std::string& origin,
- const std::string& target));
- MOCK_METHOD3(OnRequestStart, void(int tab_handle, int request_id,
- const IPC::AutomationURLRequest& request));
- MOCK_METHOD3(OnRequestRead, void(int tab_handle, int request_id,
- int bytes_to_read));
- MOCK_METHOD3(OnRequestEnd, void(int tab_handle, int request_id,
- const URLRequestStatus& status));
- MOCK_METHOD3(OnSetCookieAsync, void(int tab_handle, const GURL& url,
- const std::string& cookie));
-
-
- MOCK_METHOD1(HandleClosed, void(int handle));
-
-
- // Action helpers for OnRequest* incoming messages. Create the message and
- // delegate sending to the base class. Apparently we do not have wrappers
- // in AutomationProxy for these messages.
- void ReplyStarted(const IPC::AutomationURLResponse* response,
- int tab_handle, int request_id) {
- AutomationProxy::Send(new AutomationMsg_RequestStarted(0, tab_handle,
- request_id, *response));
- }
-
- void ReplyData(const std::string* data, int tab_handle, int request_id) {
- AutomationProxy::Send(new AutomationMsg_RequestData(0, tab_handle,
- request_id, *data));
- }
-
- void ReplyEOF(int tab_handle, int request_id) {
- AutomationProxy::Send(new AutomationMsg_RequestEnd(0, tab_handle,
- request_id,
- URLRequestStatus()));
- }
-
- void Reply404(int tab_handle, int request_id) {
- const IPC::AutomationURLResponse notfound = {"", "HTTP/1.1 404\r\n\r\n"};
- ReplyStarted(&notfound, tab_handle, request_id);
- ReplyEOF(tab_handle, request_id);
- }
-
- // Test setup helpers
- scoped_refptr<TabProxy> CreateHostWindowAndTab(
- const IPC::ExternalTabSettings& settings);
- scoped_refptr<TabProxy> CreateTabWithUrl(const GURL& initial_url);
- void DestroyHostWindow();
-
- static const IPC::ExternalTabSettings default_settings;
- protected:
- HWND host_window_;
-
- // Simple dispatcher to above OnXXX methods.
- virtual void OnMessageReceived(const IPC::Message& msg);
- virtual void InvalidateHandle(const IPC::Message& message) {
- void* iter = NULL;
- int handle;
- ASSERT_TRUE(message.ReadInt(&iter, &handle));
-
- // Call base class
- AutomationProxy::InvalidateHandle(message);
- HandleClosed(handle);
- }
-};
-
// Most of the time we need external tab with these settings.
const IPC::ExternalTabSettings ExternalTabUITestMockClient::default_settings = {
NULL, gfx::Rect(), // will be replaced by CreateHostWindowAndTab
@@ -995,8 +758,14 @@ scoped_refptr<TabProxy> ExternalTabUITestMockClient::CreateTabWithUrl(
void ExternalTabUITestMockClient::DestroyHostWindow() {
::DestroyWindow(host_window_);
+ host_window_ = NULL;
}
+bool ExternalTabUITestMockClient::HostWindowExists() {
+ return (host_window_ != NULL) && ::IsWindow(host_window_);
+}
+
+
// Handy macro
#define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\
CreateFunctor(loop, &TimedMessageLoopRunner::Quit))
diff --git a/chrome/test/automation/automation_proxy_uitest.h b/chrome/test/automation/automation_proxy_uitest.h
index 7fa1a2b..0701c47 100644
--- a/chrome/test/automation/automation_proxy_uitest.h
+++ b/chrome/test/automation/automation_proxy_uitest.h
@@ -14,24 +14,11 @@
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "googleurl/src/gurl.h"
+#include "testing/gmock/include/gmock/gmock.h"
class TabProxy;
class ExternalTabUITestMockClient;
-class ExternalTabUITest : public UITest {
- public:
- // Override UITest's CreateAutomationProxy to provide the unit test
- // with our special implementation of AutomationProxy.
- // This function is called from within UITest::LaunchBrowserAndServer.
- virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
- protected:
- // Filtered Inet will override automation callbacks for network resources.
- virtual bool ShouldFilterInet() {
- return false;
- }
- ExternalTabUITestMockClient* mock_;
-};
-
// Base class for automation proxy testing.
class AutomationProxyVisibleTest : public UITest {
protected:
@@ -40,114 +27,71 @@ class AutomationProxyVisibleTest : public UITest {
}
};
-// Automation proxy UITest that allows tests to override the automation
-// proxy used by the UITest base class.
-template <class AutomationProxyClass>
-class CustomAutomationProxyTest : public AutomationProxyVisibleTest {
- protected:
- CustomAutomationProxyTest() {
- }
-
- // Override UITest's CreateAutomationProxy to provide our the unit test
- // with our special implementation of AutomationProxy.
- // This function is called from within UITest::LaunchBrowserAndServer.
- virtual AutomationProxy* CreateAutomationProxy(int execution_timeout) {
- AutomationProxyClass* proxy = new AutomationProxyClass(execution_timeout);
- return proxy;
- }
-};
-
-// A single-use AutomationProxy implementation that's good
-// for a single navigation and a single ForwardMessageToExternalHost
-// message. Once the ForwardMessageToExternalHost message is received
-// the class posts a quit message to the thread on which the message
-// was received.
-class AutomationProxyForExternalTab : public AutomationProxy {
+// Used to implement external tab UI tests.
+//
+// We have to derive from AutomationProxy in order to hook up
+// OnMessageReceived callbacks.
+class ExternalTabUITestMockClient : public AutomationProxy {
public:
- // Allows us to reuse this mock for multiple tests. This is done
- // by setting a state to trigger posting of Quit message to the
- // wait loop.
- enum QuitAfter {
- QUIT_INVALID,
- QUIT_AFTER_NAVIGATION,
- QUIT_AFTER_MESSAGE,
- };
-
- explicit AutomationProxyForExternalTab(int execution_timeout);
- ~AutomationProxyForExternalTab();
-
- int messages_received() const {
- return messages_received_;
- }
-
- const std::string& message() const {
- return message_;
- }
-
- const std::string& origin() const {
- return origin_;
- }
-
- const std::string& target() const {
- return target_;
- }
-
- // Creates and sisplays a top-level window, that can be used as a parent
- // to the external tab.window.
- gfx::NativeWindow CreateHostWindow();
- scoped_refptr<TabProxy> CreateTabWithHostWindow(bool is_incognito,
- const GURL& initial_url, gfx::NativeWindow* container_wnd,
- gfx::NativeWindow* tab_wnd);
+ explicit ExternalTabUITestMockClient(int execution_timeout);
+
+ MOCK_METHOD2(OnDidNavigate, void(int tab_handle,
+ const IPC::NavigationInfo& nav_info));
+ MOCK_METHOD4(OnForwardMessageToExternalHost, void(int handle,
+ const std::string& message, const std::string& origin,
+ const std::string& target));
+ MOCK_METHOD3(OnRequestStart, void(int tab_handle, int request_id,
+ const IPC::AutomationURLRequest& request));
+ MOCK_METHOD3(OnRequestRead, void(int tab_handle, int request_id,
+ int bytes_to_read));
+ MOCK_METHOD3(OnRequestEnd, void(int tab_handle, int request_id,
+ const URLRequestStatus& status));
+ MOCK_METHOD3(OnSetCookieAsync, void(int tab_handle, const GURL& url,
+ const std::string& cookie));
+
+ MOCK_METHOD1(HandleClosed, void(int handle));
+
+ // Action helpers for OnRequest* incoming messages. Create the message and
+ // delegate sending to the base class. Apparently we do not have wrappers
+ // in AutomationProxy for these messages.
+ void ReplyStarted(const IPC::AutomationURLResponse* response,
+ int tab_handle, int request_id);
+ void ReplyData(const std::string* data, int tab_handle, int request_id);
+ void ReplyEOF(int tab_handle, int request_id);
+ void Reply404(int tab_handle, int request_id);
+
+ // Test setup helpers
+ scoped_refptr<TabProxy> CreateHostWindowAndTab(
+ const IPC::ExternalTabSettings& settings);
+ scoped_refptr<TabProxy> CreateTabWithUrl(const GURL& initial_url);
+
+ // Destroys the host window.
void DestroyHostWindow();
+ // Returns true if the host window exists.
+ bool HostWindowExists();
- // Wait for the event to happen or timeout
- bool WaitForNavigation(int timeout_ms);
- bool WaitForMessage(int timeout_ms);
- bool WaitForTabCleanup(TabProxy* tab, int timeout_ms);
-
- // Enters a message loop that processes window messages as well
- // as calling MessageLoop::current()->RunAllPending() to process any
- // incoming IPC messages. The timeout_ms parameter is the maximum
- // time the loop will run. To end the loop earlier, post a quit message to
- // the thread.
- bool RunMessageLoop(int timeout_ms, gfx::NativeWindow window_to_monitor);
-
+ static const IPC::ExternalTabSettings default_settings;
protected:
-#if defined(OS_WIN)
- static const int kQuitLoopMessage = WM_APP + 11;
- // Quit the message loop
- void QuitLoop() {
- DCHECK(IsWindow(host_window_));
- // We could post WM_QUIT but lets keep it out of accidental usage
- // by anyone else peeking it.
- PostMessage(host_window_, kQuitLoopMessage, 0, 0);
- }
-#endif // defined(OS_WIN)
-
- // Internal state to flag posting of a quit message to the loop
- void set_quit_after(QuitAfter q) {
- quit_after_ = q;
- }
+ gfx::NativeWindow host_window_;
+ // Simple dispatcher to above OnXXX methods.
virtual void OnMessageReceived(const IPC::Message& msg);
+ virtual void InvalidateHandle(const IPC::Message& message);
+};
- void OnDidNavigate(int tab_handle, const IPC::NavigationInfo& nav_info);
- void OnForwardMessageToExternalHost(int handle,
- const std::string& message,
- const std::string& origin,
- const std::string& target);
-
+// Base your external tab UI tests on this.
+class ExternalTabUITest : public UITest {
+ public:
+ // Override UITest's CreateAutomationProxy to provide the unit test
+ // with our special implementation of AutomationProxy.
+ // This function is called from within UITest::LaunchBrowserAndServer.
+ virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
protected:
- bool navigate_complete_;
- int messages_received_;
- std::string message_, origin_, target_;
- QuitAfter quit_after_;
- const wchar_t* host_window_class_;
- gfx::NativeWindow host_window_;
+ // Filtered Inet will override automation callbacks for network resources.
+ virtual bool ShouldFilterInet() {
+ return false;
+ }
+ ExternalTabUITestMockClient* mock_;
};
-// A test harness for testing external tabs.
-typedef CustomAutomationProxyTest<AutomationProxyForExternalTab>
- ExternalTabTestType;
-
#endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_UITEST_H_