Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Unified Diff: chrome/test/automation/automation_proxy_uitest.h

Issue 468013: Get rid of ExternalTabAutomationProxy by switching the extension UI... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_uitest.cc ('k') | chrome/test/automation/automation_proxy_uitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/automation/automation_proxy_uitest.h
===================================================================
--- chrome/test/automation/automation_proxy_uitest.h (revision 33689)
+++ chrome/test/automation/automation_proxy_uitest.h (working copy)
@@ -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 @@
}
};
-// 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 ExternalTabUITestMockClient(int execution_timeout);
- explicit AutomationProxyForExternalTab(int execution_timeout);
- ~AutomationProxyForExternalTab();
+ 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));
- int messages_received() const {
- return messages_received_;
- }
+ MOCK_METHOD1(HandleClosed, void(int handle));
- const std::string& message() const {
- return message_;
- }
+ // 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);
- const std::string& origin() const {
- return origin_;
- }
+ // Test setup helpers
+ scoped_refptr<TabProxy> CreateHostWindowAndTab(
+ const IPC::ExternalTabSettings& settings);
+ scoped_refptr<TabProxy> CreateTabWithUrl(const GURL& initial_url);
- 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);
+ // 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)
+ gfx::NativeWindow host_window_;
- // Internal state to flag posting of a quit message to the loop
- void set_quit_after(QuitAfter q) {
- quit_after_ = q;
- }
-
+ // 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_
« no previous file with comments | « chrome/browser/extensions/extension_uitest.cc ('k') | chrome/test/automation/automation_proxy_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698