diff options
author | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
---|---|---|
committer | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
commit | 5a7bdf208c28c210b39cff63d1cf91302b02821b (patch) | |
tree | 5ff484561562f78b29d2670168a9e3b40b48dcab /ceee/ie/testing | |
parent | 26a54a5e0f4603c8fda2fe51789d331125993c9a (diff) | |
download | chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.zip chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.gz chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.bz2 |
Checking in the initial version of CEEE (Chrome Extensions Execution
Environment), an optional feature of Chrome Frame that acts as an
adapter layer for a subset of the Chrome Extension APIs. This enables
extensions that stick to the supported subset of APIs to work in the
context of Chrome Frame with minimal or sometimes no changes.
See http://www.chromium.org/developers/design-documents/ceee for an
overview of the design of CEEE.
TEST=unit tests (run ceee/smoke_tests.bat as an administrator on Windows)
BUG=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee/ie/testing')
21 files changed, 1453 insertions, 0 deletions
diff --git a/ceee/ie/testing/ie_unittest_main.cc b/ceee/ie/testing/ie_unittest_main.cc new file mode 100644 index 0000000..2317472 --- /dev/null +++ b/ceee/ie/testing/ie_unittest_main.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Main function for common unittests. +#include <atlbase.h> +#include <atlcom.h> +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/logging.h" +#include "ceee/testing/utils/gflag_utils.h" +#include "chrome/common/url_constants.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "toolband.h" // NOLINT + +// Stub for unittesting. +namespace ceee_module_util { + +LONG LockModule() { + return 0; +} +LONG UnlockModule() { + return 0; +} +void Lock() { +} +void Unlock() { +} +void AddRefModuleWorkerThread() { +} +void ReleaseModuleWorkerThread() { +} + +// Fires an event to the broker, so that the call can be made with an +// instance of a broker proxy that was CoCreated in the worker thread. +void FireEventToBroker(const std::string& event_name, + const std::string& event_args) { + // Must get some work done so that the function can be mocked. + // Otherwise, it would be too short to be side stepped... + if (event_name == event_args) { + CHECK(event_name == event_args); + } else { + CHECK(event_name != event_args); + } +} + +} // namespace ceee_module_util + + +// We're testing ATL code that requires a module object. +class ObligatoryModule: public CAtlDllModuleT<ObligatoryModule> { + public: + DECLARE_LIBID(LIBID_ToolbandLib); +}; + +ObligatoryModule g_obligatory_atl_module; + +// Run these tests under page heap. +const DWORD kGFlags = FLG_USER_STACK_TRACE_DB | FLG_HEAP_PAGE_ALLOCS; + +int main(int argc, char **argv) { + // Disabled, bb2560934. + // if (!IsDebuggerPresent()) + // testing::RelaunchWithGFlags(kTestGFlags); + + base::AtExitManager at_exit; + CommandLine::Init(argc, argv); + + // Needs to be called before we can use GURL. + chrome::RegisterChromeSchemes(); + + testing::InitGoogleMock(&argc, argv); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/ceee/ie/testing/mediumtest_ie_common.cc b/ceee/ie/testing/mediumtest_ie_common.cc new file mode 100644 index 0000000..1b2fd45 --- /dev/null +++ b/ceee/ie/testing/mediumtest_ie_common.cc @@ -0,0 +1,267 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// A common test fixture for testing against a captive shell browser +// control instance - which is as close to habitating the belly of the IE +// beast as can be done with a modicum of safety and sanitation. +#include "ceee/ie/testing/mediumtest_ie_common.h" + +#include <atlcrack.h> +#include <atlsync.h> +#include <atlwin.h> +#include <exdisp.h> +#include <exdispid.h> +#include <mshtmdid.h> + +#include "base/logging.h" +#include "base/file_path.h" +#include "base/path_service.h" +#include "base/base_paths_win.h" +#include "base/utf_string_conversions.h" +#include "gtest/gtest.h" +#include "googleurl/src/gurl.h" +#include "net/base/net_util.h" +#include "ceee/common/com_utils.h" +#include "ceee/common/initializing_coclass.h" +#include "ceee/testing/utils/test_utils.h" +#include "ceee/testing/utils/instance_count_mixin.h" + + +namespace testing { + +// A test resource that's a simple single-resource page. +const wchar_t* kSimplePage = L"simple_page.html"; +// A test resource that's a frameset referencing the two frames below. +const wchar_t* kTwoFramesPage = L"two_frames.html"; +const wchar_t* kFrameOne = L"frame_one.html"; +const wchar_t* kFrameTwo = L"frame_two.html"; +// Another test resource that's a frameset referencing the two frames below. +const wchar_t* kAnotherTwoFramesPage = L"another_two_frames.html"; +const wchar_t* kAnotherFrameOne = L"another_frame_one.html"; +const wchar_t* kAnotherFrameTwo = L"another_frame_two.html"; + +// A test resource that's a top-level frameset with two nested iframes +// the inner one of which refers frame_one.html. +const wchar_t* kDeepFramesPage = L"deep_frames.html"; +const wchar_t* kLevelOneFrame = L"level_one_frame.html"; +const wchar_t* kLevelTwoFrame = L"level_two_frame.html"; + +// A test resource that have javascript generate frames that look orphan. +const wchar_t* kOrphansPage = L"orphans.html"; + +std::set<READYSTATE> BrowserEventSinkBase::seen_states_; + +// Constructs a res: url to the test resource in our module. +std::wstring GetTestUrl(const wchar_t* resource_name) { + FilePath path; + EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); + path = path.Append(FILE_PATH_LITERAL("ceee")) + .Append(FILE_PATH_LITERAL("ie")) + .Append(FILE_PATH_LITERAL("testing")) + .Append(FILE_PATH_LITERAL("test_data")) + .Append(resource_name); + + return UTF8ToWide(net::FilePathToFileURL(path).spec()); +} + +// Returns the path to our temp folder. +std::wstring GetTempPath() { + FilePath temp; + EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &temp)); + + return temp.value(); +} + +_ATL_FUNC_INFO handler_type_idispatch_ = + { CC_STDCALL, VT_EMPTY, 1, { VT_DISPATCH } }; +_ATL_FUNC_INFO handler_type_idispatch_variantptr_ = + { CC_STDCALL, VT_EMPTY, 2, { VT_DISPATCH, VT_BYREF | VT_VARIANT } }; + + +void BrowserEventSinkBase::GetDescription(std::string* description) const { + description->clear(); + description->append("TestBrowserEventSink"); +} + +HRESULT BrowserEventSinkBase::Initialize(IWebBrowser2* browser) { + browser_ = browser; + HRESULT hr = DispEventAdvise(browser_); + if (SUCCEEDED(hr)) { + hr = AtlAdvise(browser_, + GetUnknown(), + IID_IPropertyNotifySink, + &prop_notify_cookie_); + } + + return hr; +} + +void BrowserEventSinkBase::TearDown() { + EXPECT_HRESULT_SUCCEEDED(DispEventUnadvise(browser_)); + EXPECT_HRESULT_SUCCEEDED(AtlUnadvise(browser_, + IID_IPropertyNotifySink, + prop_notify_cookie_)); +} + +STDMETHODIMP BrowserEventSinkBase::OnChanged(DISPID changed_property) { + ATLTRACE("OnChanged(%d)\n", changed_property); + + READYSTATE ready_state = READYSTATE_UNINITIALIZED; + browser_->get_ReadyState(&ready_state); + ATLTRACE("READYSTATE: %d\n", ready_state); + seen_states_.insert(ready_state); + + return S_OK; +} + +STDMETHODIMP BrowserEventSinkBase::OnRequestEdit(DISPID changed_property) { + ATLTRACE("OnRequestEdit(%d)\n", changed_property); + return S_OK; +} + +STDMETHODIMP_(void) BrowserEventSinkBase::OnNavigateComplete( + IDispatch* browser_disp, VARIANT* url_var) { +} + +STDMETHODIMP_(void) BrowserEventSinkBase::OnDocumentComplete( + IDispatch* browser_disp, VARIANT* url) { +} + +void ShellBrowserTestBase::SetUpTestCase() { + // CoInitialize(NULL) serves two purposes here: + // 1. if we're running in a non-initialized apartment, it initializes it. + // 2. we need to be in an STA to use the shell browser, and if we're + // for whatever reason running in an MTA, it will fail. + ASSERT_HRESULT_SUCCEEDED(::CoInitialize(NULL)); + ASSERT_TRUE(AtlAxWinInit()); +} + +void ShellBrowserTestBase::TearDownTestCase() { + EXPECT_TRUE(AtlAxWinTerm()); + ::CoUninitialize(); +} + +void ShellBrowserTestBase::SetUp() { + ASSERT_TRUE(Create(HWND_MESSAGE) != NULL); + + // Create the webbrowser control and get the AX host. + ASSERT_HRESULT_SUCCEEDED( + AtlAxCreateControl(CComBSTR(CLSID_WebBrowser), + m_hWnd, + NULL, + &host_)); + + // Get the control's top-level IWebBrowser. + CComPtr<IUnknown> control; + ASSERT_HRESULT_SUCCEEDED(AtlAxGetControl(m_hWnd, &control)); + ASSERT_HRESULT_SUCCEEDED(control->QueryInterface(&browser_)); + + ASSERT_HRESULT_SUCCEEDED(CreateEventSink(browser_)); +} + +void ShellBrowserTestBase::TearDown() { + // Navigating the browser to a folder creates a non-webbrowser document, + // which shakes off all our frame handlers. + EXPECT_TRUE(NavigateBrowser(GetTempPath())); + + // Tear down the rest of our stuff. + if (event_sink_) + event_sink_->TearDown(); + + event_sink_keeper_.Release(); + host_.Release(); + browser_.Release(); + + // Should have retained no objects past this point. + EXPECT_EQ(0, InstanceCountMixinBase::all_instance_count()); + if (InstanceCountMixinBase::all_instance_count() > 0) { + InstanceCountMixinBase::LogLeakedInstances(); + } + + // Finally blow away the host window. + if (IsWindow()) + DestroyWindow(); +} + +bool ShellBrowserTestBase::NavigateBrowser(const std::wstring& url) { + CComVariant empty; + HRESULT hr = browser_->Navigate2(&CComVariant(url.c_str()), + &empty, &empty, + &empty, &empty); + EXPECT_HRESULT_SUCCEEDED(hr); + if (FAILED(hr)) + return false; + + return WaitForReadystateComplete(); +} + +bool ShellBrowserTestBase::WaitForReadystateComplete() { + return WaitForReadystate(READYSTATE_COMPLETE); +} + +bool ShellBrowserTestBase::WaitForReadystateLoading() { + return WaitForReadystate(READYSTATE_LOADING); +} + +bool ShellBrowserTestBase::WaitForReadystateWithTimerId( + READYSTATE waiting_for, UINT_PTR timer_id) { + while (true) { + if (!browser_ || !event_sink_) + return false; + + // Is the browser in the required state now? + READYSTATE ready_state = READYSTATE_UNINITIALIZED; + HRESULT hr = browser_->get_ReadyState(&ready_state); + if (FAILED(hr)) + return false; + + if (ready_state == waiting_for) { + event_sink_->remove_state(waiting_for); + return true; + } + + // Has the state been seen? + if (event_sink_->has_state(waiting_for)) { + event_sink_->remove_state(waiting_for); + return true; + } + + MSG msg = {}; + if (!GetMessage(&msg, 0, 0, 0)) { + // WM_QUIT. + return false; + } + + if (msg.message == WM_TIMER && + msg.hwnd == NULL && + msg.wParam == timer_id) { + // Timeout. + return false; + } + + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } +} + +bool ShellBrowserTestBase::WaitForReadystate(READYSTATE waiting_for) { + if (!event_sink_) + return false; + + // Clear the seen states. + event_sink_->clear_states(); + + // Bound the wait by setting a timer. + UINT_PTR timer_id = ::SetTimer(NULL, + 0, + wait_timeout_ms_, + NULL); + EXPECT_NE(0, timer_id); + bool ret = WaitForReadystateWithTimerId(waiting_for, timer_id); + EXPECT_TRUE(::KillTimer(NULL, timer_id)); + + return ret; +} + +} // namespace testing diff --git a/ceee/ie/testing/mediumtest_ie_common.h b/ceee/ie/testing/mediumtest_ie_common.h new file mode 100644 index 0000000..048e620 --- /dev/null +++ b/ceee/ie/testing/mediumtest_ie_common.h @@ -0,0 +1,204 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// A common test fixture for testing against a captive shell browser +// control instance - which is as close to habitating the belly of the IE +// beast as can be done with a modicum of safety and sanitation. +#ifndef CEEE_IE_TESTING_MEDIUMTEST_IE_COMMON_H_ +#define CEEE_IE_TESTING_MEDIUMTEST_IE_COMMON_H_ + +#include <atlbase.h> +#include <atlcrack.h> +#include <atlwin.h> +#include <exdisp.h> +#include <exdispid.h> +#include <mshtmdid.h> + +#include <set> +#include <string> + +#include "base/logging.h" +#include "base/file_path.h" +#include "base/path_service.h" +#include "base/base_paths_win.h" +#include "gtest/gtest.h" +#include "ceee/common/com_utils.h" +#include "ceee/common/initializing_coclass.h" +#include "ceee/testing/utils/test_utils.h" +#include "ceee/testing/utils/instance_count_mixin.h" + +namespace testing { + +// A test resource that's a simple single-resource page. +extern const wchar_t* kSimplePage; +// A test resource that's a frameset referencing the two frames below. +extern const wchar_t* kTwoFramesPage; +extern const wchar_t* kFrameOne; +extern const wchar_t* kFrameTwo; + +// Another copy of above on new URLs. +extern const wchar_t* kAnotherTwoFramesPage; +extern const wchar_t* kAnotherFrameOne; +extern const wchar_t* kAnotherFrameTwo; + +// A test resource that's a top-level frameset with two nested iframes +// the inner one of which refers frame_one.html. +extern const wchar_t* kDeepFramesPage; +extern const wchar_t* kLevelOneFrame; +extern const wchar_t* kLevelTwoFrame; + +// A test resource that have javascript generate frames that look orphan. +extern const wchar_t* kOrphansPage; + +// Constructs a file: url to the test file our source directory. +std::wstring GetTestUrl(const wchar_t* resource_name); + +// Returns the path to our temp folder. +std::wstring GetTempPath(); + +extern _ATL_FUNC_INFO handler_type_idispatch_; +extern _ATL_FUNC_INFO handler_type_idispatch_variantptr_; + +// Base class that implements the rudiments of sinking events from +// an IWebBrowser. +class BrowserEventSinkBase + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<BrowserEventSinkBase>, + public InstanceCountMixin<BrowserEventSinkBase>, + public IDispEventSimpleImpl<0, + BrowserEventSinkBase, + &DIID_DWebBrowserEvents2>, + public IPropertyNotifySink { + public: + BEGIN_COM_MAP(BrowserEventSinkBase) + COM_INTERFACE_ENTRY(IPropertyNotifySink) + END_COM_MAP() + + BEGIN_SINK_MAP(BrowserEventSinkBase) + SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_NAVIGATECOMPLETE2, + OnNavigateComplete, &handler_type_idispatch_variantptr_) + SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, + OnDocumentComplete, &handler_type_idispatch_variantptr_) + END_SINK_MAP() + + DECLARE_PROTECT_FINAL_CONSTRUCT(); + + BrowserEventSinkBase() : prop_notify_cookie_(-1) { + } + + virtual void GetDescription(std::string* description) const; + HRESULT Initialize(IWebBrowser2* browser); + + void TearDown(); + + // @name IPropertyNotifySink implementation. + // @{ + STDMETHOD(OnChanged)(DISPID changed_property); + STDMETHOD(OnRequestEdit)(DISPID changed_property); + // @} + + // @name DWebBrowserEvents event handler implementation. + // Override these as needed. + // @{ + STDMETHOD_(void, OnNavigateComplete)(IDispatch* browser_disp, + VARIANT* url_var); + STDMETHOD_(void, OnDocumentComplete)(IDispatch* browser_disp, VARIANT* url); + + static bool has_state(READYSTATE state) { + return seen_states_.find(state) != seen_states_.end(); + } + static void add_state(READYSTATE state) { + seen_states_.insert(state); + } + static void remove_state(READYSTATE state) { + seen_states_.erase(state); + } + static void clear_states() { + seen_states_.clear(); + } + + private: + // This bitset records the readystate values seen in OnChange. + // The point of this is to make the WaitForReadyState function + // below work in the case where the browser takes multiple + // readystate changes while processing a single event. This + // will occur in the refresh case, where the top-level browser + // and individual document objects transition from COMPLETE to + // LOADING and then back to COMPLETE on processing a single event. + static std::set<READYSTATE> seen_states_; + + // Advise cookie for property notify sink. + DWORD prop_notify_cookie_; + + CComPtr<IWebBrowser2> browser_; +}; + +// Test fixture base class. +class ShellBrowserTestBase + : public testing::Test, + public CWindowImpl<ShellBrowserTestBase> { + public: + // Default timeout for pumping events. + static const UINT kWaitTimeoutMs = 2000; + + ShellBrowserTestBase() + : wait_timeout_ms_(kWaitTimeoutMs) { + } + + static void SetUpTestCase(); + static void TearDownTestCase(); + + void SetUp(); + void TearDown(); + + // Navigates the browser to the given URL and waits for + // the top-level browser's readystate to reach complete. + bool NavigateBrowser(const std::wstring& url); + + // Wait for the top-level browser's readystate to reach + // READYSTATE_COMPLETE, READYSTATE_LOADING or wait_for, + // respectively. + bool WaitForReadystateComplete(); + bool WaitForReadystateLoading(); + bool WaitForReadystate(READYSTATE wait_for); + + BEGIN_MSG_MAP_EX(BrowserEventTest) + END_MSG_MAP() + + protected: + bool WaitForReadystateWithTimerId(READYSTATE waiting_for, UINT_PTR timer_id); + virtual HRESULT CreateEventSink(IWebBrowser2* browser) = 0; + + // Timeout for pumping messages in WaitForReadyState. + UINT wait_timeout_ms_; + + CComPtr<IUnknown> host_; + CComPtr<IWebBrowser2> browser_; + + BrowserEventSinkBase* event_sink_; + CComPtr<IUnknown> event_sink_keeper_; +}; + +template <class EventSinkImpl> +class ShellBrowserTestImpl: public ShellBrowserTestBase { + public: + protected: + virtual HRESULT CreateEventSink(IWebBrowser2* browser) { + EventSinkImpl* sink; + HRESULT hr = EventSinkImpl::CreateInitialized(&sink, + browser, + &event_sink_keeper_); + event_sink_ = sink; + return hr; + } + + // Handy accessor to retrieve the event sink by actual type. + EventSinkImpl* event_sink() const { + return static_cast<EventSinkImpl*>(event_sink_); + } +}; + +} // namespace testing + +#endif // CEEE_IE_TESTING_MEDIUMTEST_IE_COMMON_H_ diff --git a/ceee/ie/testing/mediumtest_ie_main.cc b/ceee/ie/testing/mediumtest_ie_main.cc new file mode 100644 index 0000000..b79fe46 --- /dev/null +++ b/ceee/ie/testing/mediumtest_ie_main.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Main function for large IE tests. +#include <atlbase.h> +#include <atlcom.h> +#include "base/at_exit.h" +#include "base/command_line.h" +#include "ceee/testing/utils/gflag_utils.h" +#include "ceee/testing/utils/nt_internals.h" +#include "chrome/common/url_constants.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + + +// Stub for unittesting. +namespace ceee_module_util { + +LONG LockModule() { + return 0; +} +LONG UnlockModule() { + return 0; +} +void Lock() { +} +void Unlock() { +} +void AddRefModuleWorkerThread() { +} +void ReleaseModuleWorkerThread() { +} +void FireEventToBroker(const std::string& event_name, + const std::string& event_args) { +} + +} // namespace ceee_module_util + + +// We're testing some ATL code that requires a module object. +class ObligatoryModule: public CAtlDllModuleT<ObligatoryModule> { +}; + +ObligatoryModule g_obligatory_atl_module; + +const DWORD kTestGFlags = FLG_USER_STACK_TRACE_DB | + FLG_ENABLE_HANDLE_EXCEPTIONS | + FLG_ENABLE_CLOSE_EXCEPTIONS | + FLG_HEAP_VALIDATE_PARAMETERS; + +int main(int argc, char **argv) { + // Disabled, bb2560934. + // if (!IsDebuggerPresent()) + // testing::RelaunchWithGFlags(kTestGFlags); + + testing::InitGoogleMock(&argc, argv); + testing::InitGoogleTest(&argc, argv); + + // Obligatory Chrome base initialization. + CommandLine::Init(argc, argv); + base::AtExitManager at_exit_manager; + + // Needs to be called before we can use GURL. + chrome::RegisterChromeSchemes(); + + return RUN_ALL_TESTS(); +} diff --git a/ceee/ie/testing/mock_broker_and_friends.h b/ceee/ie/testing/mock_broker_and_friends.h new file mode 100644 index 0000000..7c02845 --- /dev/null +++ b/ceee/ie/testing/mock_broker_and_friends.h @@ -0,0 +1,359 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Mock implementation of Broker and related objects. +#ifndef CEEE_IE_TESTING_MOCK_BROKER_AND_FRIENDS_H_ +#define CEEE_IE_TESTING_MOCK_BROKER_AND_FRIENDS_H_ + +#include <string> + +#include "ceee/ie/broker/api_dispatcher.h" +#include "ceee/ie/plugin/bho/cookie_events_funnel.h" +#include "ceee/ie/plugin/bho/tab_events_funnel.h" +#include "ceee/ie/plugin/bho/webnavigation_events_funnel.h" +#include "ceee/ie/plugin/bho/webrequest_events_funnel.h" +#include "gmock/gmock.h" +#include "ceee/common/initializing_coclass.h" +#include "ceee/testing/utils/instance_count_mixin.h" + +#include "broker_lib.h" // NOLINT +#include "toolband.h" // NOLINT + +namespace testing { + +class MockBrokerImpl : public ICeeeBroker { + public: + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, Execute, HRESULT(BSTR, BSTR*)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, FireEvent, HRESULT(BSTR, BSTR)); +}; + +class MockBrokerRegistrarImpl : public ICeeeBrokerRegistrar { + public: + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, RegisterWindowExecutor, + HRESULT(long, IUnknown*)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, UnregisterExecutor, HRESULT(long)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, RegisterTabExecutor, + HRESULT(long, IUnknown*)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, SetTabIdForHandle, + HRESULT(long, CeeeWindowHandle)); +}; + +class MockBroker + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockBroker>, + public InstanceCountMixin<MockBroker>, + public StrictMock<MockBrokerRegistrarImpl>, + public StrictMock<MockBrokerImpl> { + public: + BEGIN_COM_MAP(MockBroker) + COM_INTERFACE_ENTRY(ICeeeBrokerRegistrar) + COM_INTERFACE_ENTRY(ICeeeBroker) + END_COM_MAP() + + HRESULT Initialize(MockBroker** self) { + *self = this; + return S_OK; + } +}; + +class MockExecutorIUnknown + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockExecutorIUnknown>, + public InstanceCountMixin<MockExecutorIUnknown>, + public IObjectWithSiteImpl<MockExecutorIUnknown> { + public: + BEGIN_COM_MAP(MockExecutorIUnknown) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockExecutorIUnknown** self) { + *self = this; + return S_OK; + } +}; + +class MockCeeeWindowExecutorImpl : public ICeeeWindowExecutor { + public: + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, Initialize, HRESULT(CeeeWindowHandle)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, GetWindow, + HRESULT(BOOL, CeeeWindowInfo*)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetTabs, HRESULT(BSTR*)); + MOCK_METHOD5_WITH_CALLTYPE(__stdcall, UpdateWindow, HRESULT(long, long, + long, long, CeeeWindowInfo*)); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, RemoveWindow, HRESULT()); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, GetTabIndex, HRESULT(CeeeWindowHandle, + long*)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, MoveTab, HRESULT(CeeeWindowHandle, + long)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, RemoveTab, HRESULT(CeeeWindowHandle)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SelectTab, HRESULT(CeeeWindowHandle)); +}; + +class MockWindowExecutor + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockWindowExecutor>, + public InstanceCountMixin<MockWindowExecutor>, + public IObjectWithSiteImpl<MockWindowExecutor>, + public StrictMock<MockCeeeWindowExecutorImpl> { + public: + BEGIN_COM_MAP(MockWindowExecutor) + COM_INTERFACE_ENTRY(ICeeeWindowExecutor) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockWindowExecutor** self) { + *self = this; + return S_OK; + } +}; + +class MockCeeeTabExecutorImpl : public ICeeeTabExecutor { + public: + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, Initialize, HRESULT(CeeeWindowHandle)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetTabInfo, + HRESULT(CeeeTabInfo*)); + MOCK_METHOD3_WITH_CALLTYPE(__stdcall, Navigate, HRESULT(BSTR, long, BSTR)); + MOCK_METHOD4_WITH_CALLTYPE(__stdcall, InsertCode, HRESULT( + BSTR, BSTR, BOOL, CeeeTabCodeType)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, PopupizeFrameWindow, HRESULT(long)); +}; + +class MockTabExecutor + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockTabExecutor>, + public InstanceCountMixin<MockTabExecutor>, + public IObjectWithSiteImpl<MockTabExecutor>, + public StrictMock<MockCeeeTabExecutorImpl> { + public: + BEGIN_COM_MAP(MockTabExecutor) + COM_INTERFACE_ENTRY(ICeeeTabExecutor) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockTabExecutor** self) { + *self = this; + return S_OK; + } +}; + +class MockTabEventsFunnel : public TabEventsFunnel { + public: + MOCK_METHOD4(OnMoved, HRESULT(HWND tab, int window_id, int from_index, + int to_index)); + MOCK_METHOD1(OnRemoved, HRESULT(HWND tab)); + MOCK_METHOD2(OnSelectionChanged, HRESULT(HWND tab, int window_id)); + MOCK_METHOD3(OnCreated, HRESULT(HWND tab, BSTR url, bool completed)); + MOCK_METHOD3(OnUpdated, HRESULT(HWND tab, BSTR url, + READYSTATE ready_state)); + MOCK_METHOD2(OnTabUnmapped, HRESULT(HWND tab, int tab_id)); +}; + +class MockCeeeCookieExecutorImpl : public ICeeeCookieExecutor { + public: + MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetCookie, + HRESULT(BSTR, BSTR, CeeeCookieInfo*)); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, RegisterCookieStore, HRESULT()); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, CookieStoreIsRegistered, HRESULT()); +}; + +class MockCookieExecutor + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockCookieExecutor>, + public InstanceCountMixin<MockCookieExecutor>, + public IObjectWithSiteImpl<MockCookieExecutor>, + public StrictMock<MockCeeeCookieExecutorImpl> { + public: + BEGIN_COM_MAP(MockCookieExecutor) + COM_INTERFACE_ENTRY(ICeeeCookieExecutor) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockCookieExecutor** self) { + *self = this; + return S_OK; + } +}; + +class MockCookieEventsFunnel : public CookieEventsFunnel { + public: + MOCK_METHOD2(OnChanged, HRESULT(bool removed, + const cookie_api::CookieInfo& cookie)); +}; + +class MockCeeeInfobarExecutorImpl : public ICeeeInfobarExecutor { + public: + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetExtensionId, HRESULT(BSTR)); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, ShowInfobar, + HRESULT(BSTR, CeeeWindowHandle*)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, OnTopFrameBeforeNavigate, + HRESULT(BSTR)); +}; + +class MockInfobarExecutor + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockInfobarExecutor>, + public InstanceCountMixin<MockInfobarExecutor>, + public IObjectWithSiteImpl<MockInfobarExecutor>, + public StrictMock<MockCeeeInfobarExecutorImpl> { + public: + BEGIN_COM_MAP(MockInfobarExecutor) + COM_INTERFACE_ENTRY(ICeeeInfobarExecutor) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockInfobarExecutor** self) { + *self = this; + return S_OK; + } +}; + +class MockTabInfobarExecutor + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<MockTabInfobarExecutor>, + public InstanceCountMixin<MockTabInfobarExecutor>, + public IObjectWithSiteImpl<MockTabInfobarExecutor>, + public StrictMock<MockCeeeTabExecutorImpl>, + public StrictMock<MockCeeeInfobarExecutorImpl> { + public: + BEGIN_COM_MAP(MockTabInfobarExecutor) + COM_INTERFACE_ENTRY(ICeeeTabExecutor) + COM_INTERFACE_ENTRY(ICeeeInfobarExecutor) + COM_INTERFACE_ENTRY(IObjectWithSite) + END_COM_MAP() + + HRESULT Initialize(MockTabInfobarExecutor** self) { + *self = this; + return S_OK; + } +}; + +class MockApiDispatcher : public ApiDispatcher { + public: + MOCK_METHOD2(HandleApiRequest, void(BSTR, BSTR*)); + MOCK_METHOD2(RegisterInvocation, void(const char* function_name, + InvocationFactory factory)); + MOCK_METHOD3(RegisterEphemeralEventHandler, + void(const char*, EphemeralEventHandler, InvocationResult*)); + MOCK_METHOD3(GetExecutor, void(HWND, REFIID, void**)); + MOCK_METHOD2(FireEvent, void(BSTR event_name, BSTR event_args)); + + MOCK_CONST_METHOD1(GetTabHandleFromId, HWND(int)); + MOCK_CONST_METHOD1(GetWindowHandleFromId, HWND(int)); + MOCK_CONST_METHOD1(GetTabIdFromHandle, int(HWND)); + MOCK_CONST_METHOD1(GetWindowIdFromHandle, int(HWND)); +}; + +// A mock class for an API invocation class that derives from ApiResultCreator, +// defined in ceee\ie\broker\api_dispatcher.h. This class enables the injection +// of a mock API result instance when the API is invoked. +template<class ResultType, class MockResultType, class BaseClass> +class MockApiInvocation : public BaseClass { + public: + MockApiInvocation() : request_id_(kRequestId) {} + + // Calls the ContinueExecution method of the base class, using the mock + // invocation result and mock API dispatcher. + HRESULT CallContinueExecution(const std::string& input_args) { + HRESULT hr = ContinueExecution(input_args, invocation_result_.get(), + GetDispatcher()); + + // NOTE: the ContinueExecution method has already deleted the invocation + // result if its return is not S_FALSE. In that case, we have to release + // the pointer so that we don't delete the same object twice. + if (hr != S_FALSE) + invocation_result_.release(); + + return hr; + } + + // We need to create the results before we get asked for one + // so that we can set expectations on it. And we need to allocate them + // because the callers of CreateApiResult take ownership of the memory. + void AllocateNewResult(int request_id) { + request_id_ = request_id; + invocation_result_.reset(new StrictMock<MockResultType>(request_id)); + } + virtual ResultType* CreateApiResult(int request_id) { + EXPECT_EQ(request_id, request_id_); + EXPECT_NE(static_cast<ResultType*>(NULL), invocation_result_.get()); + return invocation_result_.release(); // The caller becomes the owner. + } + virtual ApiDispatcher* GetDispatcher() { + return &mock_api_dispatcher_; + } + + // public so that the tests can set expectations on them. + scoped_ptr<StrictMock<MockResultType> > invocation_result_; + StrictMock<MockApiDispatcher> mock_api_dispatcher_; + + private: + int request_id_; +}; + +class MockWebNavigationEventsFunnel : public WebNavigationEventsFunnel { + public: + MOCK_METHOD5(OnBeforeNavigate, HRESULT(CeeeWindowHandle tab_handle, + BSTR url, + int frame_id, + int request_id, + const base::Time& time_stamp)); + MOCK_METHOD4(OnBeforeRetarget, HRESULT(CeeeWindowHandle source_tab_handle, + BSTR source_url, + BSTR target_url, + const base::Time& time_stamp)); + MOCK_METHOD6(OnCommitted, HRESULT(CeeeWindowHandle tab_handle, + BSTR url, + int frame_id, + const char* transition_type, + const char* transition_qualifiers, + const base::Time& time_stamp)); + MOCK_METHOD4(OnCompleted, HRESULT(CeeeWindowHandle tab_handle, + BSTR url, + int frame_id, + const base::Time& time_stamp)); + MOCK_METHOD4(OnDOMContentLoaded, HRESULT(CeeeWindowHandle tab_handle, + BSTR url, + int frame_id, + const base::Time& time_stamp)); + MOCK_METHOD5(OnErrorOccurred, HRESULT(CeeeWindowHandle tab_handle, + BSTR url, + int frame_id, + BSTR error, + const base::Time& time_stamp)); +}; + +class MockWebRequestEventsFunnel : public WebRequestEventsFunnel { + public: + MOCK_METHOD5(OnBeforeRedirect, HRESULT(int request_id, + const wchar_t* url, + DWORD status_code, + const wchar_t* redirect_url, + const base::Time& time_stamp)); + MOCK_METHOD6(OnBeforeRequest, HRESULT(int request_id, + const wchar_t* url, + const char* method, + CeeeWindowHandle tab_handle, + const char* type, + const base::Time& time_stamp)); + MOCK_METHOD4(OnCompleted, HRESULT(int request_id, + const wchar_t* url, + DWORD status_code, + const base::Time& time_stamp)); + MOCK_METHOD4(OnErrorOccurred, HRESULT(int request_id, + const wchar_t* url, + const wchar_t* error, + const base::Time& time_stamp)); + MOCK_METHOD4(OnHeadersReceived, HRESULT(int request_id, + const wchar_t* url, + DWORD status_code, + const base::Time& time_stamp)); + MOCK_METHOD4(OnRequestSent, HRESULT(int request_id, + const wchar_t* url, + const char* ip, + const base::Time& time_stamp)); +}; + +} // namespace testing + +#endif // CEEE_IE_TESTING_MOCK_BROKER_AND_FRIENDS_H_ diff --git a/ceee/ie/testing/mock_browser_and_friends.h b/ceee/ie/testing/mock_browser_and_friends.h new file mode 100644 index 0000000..76db63c --- /dev/null +++ b/ceee/ie/testing/mock_browser_and_friends.h @@ -0,0 +1,113 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Implementation of TestBrowser and related objects. +#ifndef CEEE_IE_TESTING_MOCK_BROWSER_AND_FRIENDS_H_ +#define CEEE_IE_TESTING_MOCK_BROWSER_AND_FRIENDS_H_ + +#include <string> + +#include "gmock/gmock.h" +#include "ceee/common/initializing_coclass.h" +#include "ceee/testing/utils/instance_count_mixin.h" +#include "ceee/testing/utils/mock_com.h" +#include "ceee/testing/utils/test_utils.h" + +namespace testing { + +class MockIOleWindow : public IOleWindow { + public: + // Simple IOleWindow implementation here, no need for a MockXxxImpl. + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetWindow, HRESULT(HWND* window)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, ContextSensitiveHelp, HRESULT(BOOL)); +}; + +class TestBrowserSite + : public CComObjectRootEx<CComSingleThreadModel>, + public InstanceCountMixin<TestBrowserSite>, + public InitializingCoClass<TestBrowserSite>, + public IServiceProviderImpl<TestBrowserSite>, + public StrictMock<MockIOleWindow> { + public: + BEGIN_COM_MAP(TestBrowserSite) + COM_INTERFACE_ENTRY(IServiceProvider) + COM_INTERFACE_ENTRY(IOleWindow) + END_COM_MAP() + + BEGIN_SERVICE_MAP(TestDumbSite) + if (browser_ && (guidService == SID_SWebBrowserApp || + guidService == SID_SShellBrowser)) { + return browser_->QueryInterface(riid, ppvObject); + } + END_SERVICE_MAP() + + HRESULT Initialize(TestBrowserSite** self) { + *self = this; + return S_OK; + } + + public: + CComPtr<IDispatch> browser_; +}; + +class TestBrowser + : public CComObjectRootEx<CComSingleThreadModel>, + public InstanceCountMixin<TestBrowser>, + public InitializingCoClass<TestBrowser>, + public StrictMock<IWebBrowser2MockImpl>, + public IConnectionPointImpl<TestBrowser, &DIID_DWebBrowserEvents2>, + public IConnectionPointContainerImpl<TestBrowser> { + public: + typedef IConnectionPointImpl<TestBrowser, &DIID_DWebBrowserEvents2> + WebBrowserEvents; + + BEGIN_COM_MAP(TestBrowser) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(IWebBrowser) + COM_INTERFACE_ENTRY(IWebBrowserApp) + COM_INTERFACE_ENTRY(IWebBrowser2) + COM_INTERFACE_ENTRY(IConnectionPointContainer) + END_COM_MAP() + + BEGIN_CONNECTION_POINT_MAP(TestBrowser) + CONNECTION_POINT_ENTRY(DIID_DWebBrowserEvents2) + END_CONNECTION_POINT_MAP() + + // Override from IConnectionPointContainerImpl. + STDMETHOD(FindConnectionPoint)(REFIID iid, IConnectionPoint** cp) { + typedef IConnectionPointContainerImpl<TestBrowser> CPC; + + if (iid == DIID_DWebBrowserEvents2 && no_events_) + return CONNECT_E_NOCONNECTION; + + return CPC::FindConnectionPoint(iid, cp); + } + + void FireOnNavigateComplete(IDispatch* browser, VARIANT *url) { + CComVariant args[] = { 0, browser }; + args[0].vt = VT_BYREF | VT_BSTR; + args[0].pvarVal = url; + + testing::FireEvent(static_cast<WebBrowserEvents*>(this), + DISPID_NAVIGATECOMPLETE2, + arraysize(args), + args); + } + + TestBrowser() : no_events_(false) { + } + + HRESULT Initialize(TestBrowser** self) { + *self = this; + return S_OK; + } + + public: + // If true, won't return the WebBrowserEvents connection point. + bool no_events_; +}; + +} // namespace testing + +#endif // CEEE_IE_TESTING_MOCK_BROWSER_AND_FRIENDS_H_ diff --git a/ceee/ie/testing/mock_chrome_frame_host.h b/ceee/ie/testing/mock_chrome_frame_host.h new file mode 100644 index 0000000..8ef07ff --- /dev/null +++ b/ceee/ie/testing/mock_chrome_frame_host.h @@ -0,0 +1,62 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Mock implementation of ChromeFrameHost. +#ifndef CEEE_IE_TESTING_MOCK_CHROME_FRAME_HOST_H_ +#define CEEE_IE_TESTING_MOCK_CHROME_FRAME_HOST_H_ + +#include <string> +#include "ceee/ie/common/chrome_frame_host.h" +#include "gmock/gmock.h" +#include "ceee/common/initializing_coclass.h" +#include "ceee/testing/utils/instance_count_mixin.h" + +namespace testing { + +class IChromeFrameHostMockImpl : public IChromeFrameHost { + public: + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, SetAsChromeFrameMaster, void()); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetChromeProfileName, + void(const wchar_t* chrome_profile_name)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetUrl, HRESULT(BSTR url)); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, StartChromeFrame, HRESULT()); + MOCK_METHOD2_WITH_CALLTYPE(__stdcall, PostMessage, + HRESULT(BSTR message, BSTR target)); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, TearDown, HRESULT()); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetEventSink, + void(IChromeFrameHostEvents* event_sink)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, InstallExtension, + HRESULT(BSTR crx_path)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, LoadExtension, + HRESULT(BSTR extension_dir)); + MOCK_METHOD0_WITH_CALLTYPE(__stdcall, GetEnabledExtensions, HRESULT()); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetExtensionApisToAutomate, + HRESULT(BSTR* enabled_functions)); + MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetSessionId, HRESULT(int*)); +}; + +// A mock implementation of ChromeFrameHost. +class MockChromeFrameHost + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<StrictMock<MockChromeFrameHost> >, + public InstanceCountMixin<MockChromeFrameHost>, + public StrictMock<IChromeFrameHostMockImpl> { + public: + BEGIN_COM_MAP(MockChromeFrameHost) + COM_INTERFACE_ENTRY_IID(IID_IChromeFrameHost, IChromeFrameHost) + END_COM_MAP() + + HRESULT Initialize() { + return S_OK; + } + + HRESULT Initialize(MockChromeFrameHost** self) { + *self = this; + return S_OK; + } +}; + +} // namespace testing + +#endif // CEEE_IE_TESTING_MOCK_CHROME_FRAME_HOST_H_ diff --git a/ceee/ie/testing/mock_frame_event_handler_host.h b/ceee/ie/testing/mock_frame_event_handler_host.h new file mode 100644 index 0000000..18e9572 --- /dev/null +++ b/ceee/ie/testing/mock_frame_event_handler_host.h @@ -0,0 +1,81 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Mock implementation of ChromeFrameHost. +#ifndef CEEE_IE_TESTING_MOCK_FRAME_EVENT_HANDLER_HOST_H_ +#define CEEE_IE_TESTING_MOCK_FRAME_EVENT_HANDLER_HOST_H_ + +#include <string> + +#include "ceee/common/initializing_coclass.h" +#include "ceee/ie/plugin/bho/frame_event_handler.h" +#include "ceee/ie/plugin/scripting/content_script_native_api.h" +#include "ceee/testing/utils/instance_count_mixin.h" +#include "gmock/gmock.h" + +namespace testing { + +class IFrameEventHandlerHostMockImpl : public IFrameEventHandlerHost { + public: + MOCK_METHOD3(AttachBrowser, HRESULT(IWebBrowser2* browser, + IWebBrowser2* parent_browser, + IFrameEventHandler* handler)); + MOCK_METHOD3(DetachBrowser, HRESULT(IWebBrowser2* browser, + IWebBrowser2* parent_browser, + IFrameEventHandler* handler)); + MOCK_METHOD1(GetTopLevelBrowser, HRESULT(IWebBrowser2** browser)); + MOCK_METHOD1(GetReadyState, HRESULT(READYSTATE* ready_state)); + MOCK_METHOD1(OnReadyStateChanged, HRESULT(READYSTATE ready_state)); + MOCK_METHOD3(GetMatchingUserScriptsCssContent, + HRESULT(const GURL& url, bool require_all_frames, + std::string* css_content)); + MOCK_METHOD4(GetMatchingUserScriptsJsContent, + HRESULT(const GURL& url, + UserScript::RunLocation location, + bool require_all_frames, + UserScriptsLibrarian::JsFileList* js_file_list)); + MOCK_METHOD1(GetExtensionId, HRESULT(std::wstring* extension_id)); + MOCK_METHOD1(GetExtensionPath, HRESULT(std::wstring* extension_path)); + MOCK_METHOD1(GetExtensionPortMessagingProvider, + HRESULT(IExtensionPortMessagingProvider** messaging_provider)); + MOCK_METHOD4(InsertCode, HRESULT(BSTR, BSTR, BOOL, CeeeTabCodeType)); +}; + +class IExtensionPortMessagingProviderMockImpl + : public IExtensionPortMessagingProvider { + public: + MOCK_METHOD1(CloseAll, void(IContentScriptNativeApi* instance)); + MOCK_METHOD4(OpenChannelToExtension, + HRESULT(IContentScriptNativeApi* instance, + const std::string& extension, + const std::string& channel_name, + int cookie)); + MOCK_METHOD2(PostMessage, HRESULT(int port_id, const std::string& message)); +}; + +template<class BaseClass> +class MockFrameEventHandlerHostBase + : public CComObjectRootEx<CComSingleThreadModel>, + public InitializingCoClass<BaseClass>, + public InstanceCountMixin<BaseClass>, + public StrictMock<IFrameEventHandlerHostMockImpl>, + public StrictMock<IExtensionPortMessagingProviderMockImpl> { + public: + BEGIN_COM_MAP(MockFrameEventHandlerHostBase) + COM_INTERFACE_ENTRY_IID(IID_IFrameEventHandlerHost, IFrameEventHandlerHost) + END_COM_MAP() +}; + +class MockFrameEventHandlerHost + : public MockFrameEventHandlerHostBase<MockFrameEventHandlerHost> { + public: + HRESULT Initialize(MockFrameEventHandlerHost** self) { + *self = this; + return S_OK; + } +}; + +} // namespace testing + +#endif // CEEE_IE_TESTING_MOCK_FRAME_EVENT_HANDLER_HOST_H_ diff --git a/ceee/ie/testing/precompile.cc b/ceee/ie/testing/precompile.cc new file mode 100644 index 0000000..975a615 --- /dev/null +++ b/ceee/ie/testing/precompile.cc @@ -0,0 +1,6 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Precompile generator file. +#include "ceee/ie/testing/precompile.h" diff --git a/ceee/ie/testing/precompile.h b/ceee/ie/testing/precompile.h new file mode 100644 index 0000000..ef85751 --- /dev/null +++ b/ceee/ie/testing/precompile.h @@ -0,0 +1,19 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Precompile header for IE CEEE unittests. + +#ifndef CEEE_IE_TESTING_PRECOMPILE_H_ +#define CEEE_IE_TESTING_PRECOMPILE_H_ + +#include <atlbase.h> +#include <atlcom.h> +#include <atlstr.h> + +#include "ceee/testing/utils/mock_com.h" +#include "ceee/testing/utils/test_utils.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +#endif // CEEE_IE_TESTING_PRECOMPILE_H_ diff --git a/ceee/ie/testing/test_data/another_frame_one.html b/ceee/ie/testing/test_data/another_frame_one.html new file mode 100644 index 0000000..a97a903 --- /dev/null +++ b/ceee/ie/testing/test_data/another_frame_one.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Another Frame One</title></head> +<body> +<h1>Another Frame One</h1> +</body> +</html> diff --git a/ceee/ie/testing/test_data/another_frame_two.html b/ceee/ie/testing/test_data/another_frame_two.html new file mode 100644 index 0000000..fbd64e6 --- /dev/null +++ b/ceee/ie/testing/test_data/another_frame_two.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Another Frame Two</title></head> +<body> +<h1>Another Frame Two</h1> +</body> +</html> diff --git a/ceee/ie/testing/test_data/another_two_frames.html b/ceee/ie/testing/test_data/another_two_frames.html new file mode 100644 index 0000000..339f133 --- /dev/null +++ b/ceee/ie/testing/test_data/another_two_frames.html @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Another two frames in a frameset</title></head> +<frameset cols="50%,50%"> + <frame src="another_frame_one.html" /> + <frame src="another_frame_two.html" /> +</frameset> +</html> diff --git a/ceee/ie/testing/test_data/deep_frames.html b/ceee/ie/testing/test_data/deep_frames.html new file mode 100644 index 0000000..a89090c --- /dev/null +++ b/ceee/ie/testing/test_data/deep_frames.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Deep frames</title></head> +<frameset cols="50%,50%"> + <frame src="level_one_frame.html" name="deep_frames" /> +</frameset> +</html> diff --git a/ceee/ie/testing/test_data/frame_one.html b/ceee/ie/testing/test_data/frame_one.html new file mode 100644 index 0000000..3bba64e --- /dev/null +++ b/ceee/ie/testing/test_data/frame_one.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Frame One</title></head> +<body> +<h1>Frame One</h1> +</body> +</html> diff --git a/ceee/ie/testing/test_data/frame_two.html b/ceee/ie/testing/test_data/frame_two.html new file mode 100644 index 0000000..e4bdd8c --- /dev/null +++ b/ceee/ie/testing/test_data/frame_two.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Frame Two</title></head> +<body> +<h1>Frame Two</h1> +</body> +</html> diff --git a/ceee/ie/testing/test_data/level_one_frame.html b/ceee/ie/testing/test_data/level_one_frame.html new file mode 100644 index 0000000..4422375 --- /dev/null +++ b/ceee/ie/testing/test_data/level_one_frame.html @@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Level One Frame</title></head> +<body> + <h1>Level One Frame</h1> + <iframe width="100%" height="400px" src="level_two_frame.html" + name="level_one" /> +</body> +</html> diff --git a/ceee/ie/testing/test_data/level_two_frame.html b/ceee/ie/testing/test_data/level_two_frame.html new file mode 100644 index 0000000..0c84867 --- /dev/null +++ b/ceee/ie/testing/test_data/level_two_frame.html @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Level Two Frame</title></head> +<body> + <h1>Level Two Frame</h1> + <iframe width="100%" height="400px" src="frame_one.html" name="level_two"/> +</body> +</html> diff --git a/ceee/ie/testing/test_data/orphans.html b/ceee/ie/testing/test_data/orphans.html new file mode 100644 index 0000000..65fcf10 --- /dev/null +++ b/ceee/ie/testing/test_data/orphans.html @@ -0,0 +1,72 @@ +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> + <head> + <script> +var isIECache = "unset"; +function isIE() { + if (isIECache == "unset") { + isIECache = 0; + try { + if (navigator.appName == "Microsoft Internet Explorer") { + var a = navigator.userAgent, b = /MSIE ([0-9]{1,}[.0-9]{0,})/; + if (b.exec(a) != null) { + rv = parseFloat(RegExp.$1); + if (rv > 0) + isIECache = rv; + } + } + } catch (c) { + } + } + return isIECache; +} + +function ie7Mode() { + if (isIE()) + if (document.compatMode == "BackCompat") + return true; + else if (isIE() < 8) + return true; + else if (document.documentMode > 0 && document.documentMode < 8) + return true; + return false; +} + +function go() { + var temp_frame = document.createElement("iframe"); + temp_frame.src="#BlaBlaBla"; + var j = document.getElementById("segmentDiv"); + j.appendChild(temp_frame); + var inner_content = null; + if (temp_frame.contentDocument) { + inner_content = temp_frame.contentDocument; + } else if (temp_frame.contentWindow) { + inner_content = temp_frame.contentWindow; + } + if (inner_content) { + var inner_document = null; + if (ie7Mode()) + inner_document = inner_content.window.document; + else { + inner_content.open(); + inner_content.close(); + inner_document = inner_content; + } + inner_document.write('<html><body><div id="iframeDIV" ></div></body></html>'); + inner_document.close(); + + inner_document.getElementById("iframeDIV").innerHTML = '<iframe src="./frame_one.html"></iframe>'; + } else { + alert('no content!'); + } +} + </script> + </head> + <body> + <div id="segmentDiv"></div> + <script> go(); </script> + </body> +</html> diff --git a/ceee/ie/testing/test_data/simple_page.html b/ceee/ie/testing/test_data/simple_page.html new file mode 100644 index 0000000..74fd506 --- /dev/null +++ b/ceee/ie/testing/test_data/simple_page.html @@ -0,0 +1,12 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Simple Page</title></head> +<body> +<h1>This is the simplest possible page.</h1> +</body> +</html> diff --git a/ceee/ie/testing/test_data/two_frames.html b/ceee/ie/testing/test_data/two_frames.html new file mode 100644 index 0000000..dd8b0c4 --- /dev/null +++ b/ceee/ie/testing/test_data/two_frames.html @@ -0,0 +1,13 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<!-- Copyright (c) 2010 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<html> +<head><title>Two frames in a frameset</title></head> +<frameset cols="50%,50%"> + <frame src="frame_one.html" /> + <frame src="frame_two.html" /> +</frameset> +</html> |