OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Executor implementation unit tests. | 5 // Executor implementation unit tests. |
6 | 6 |
7 // MockWin32 must not be included after atlwin, which is included by some | 7 // MockWin32 must not be included after atlwin, which is included by some |
8 // headers in here, so we need to put it at the top: | 8 // headers in here, so we need to put it at the top: |
9 #include "ceee/testing/utils/mock_win32.h" // NOLINT | 9 #include "ceee/testing/utils/mock_win32.h" // NOLINT |
10 | 10 |
11 #include <wininet.h> | 11 #include <wininet.h> |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "ceee/ie/broker/cookie_api_module.h" | 15 #include "ceee/ie/broker/cookie_api_module.h" |
16 #include "ceee/ie/broker/common_api_module.h" | 16 #include "ceee/ie/broker/common_api_module.h" |
17 #include "ceee/ie/broker/tab_api_module.h" | 17 #include "ceee/ie/broker/tab_api_module.h" |
18 #include "ceee/ie/broker/window_api_module.h" | 18 #include "ceee/ie/broker/window_api_module.h" |
19 #include "ceee/ie/common/ie_util.h" | 19 #include "ceee/ie/common/ie_util.h" |
20 #include "ceee/ie/common/mock_ie_tab_interfaces.h" | 20 #include "ceee/ie/common/mock_ie_tab_interfaces.h" |
21 #include "ceee/ie/plugin/bho/executor.h" | 21 #include "ceee/ie/plugin/bho/executor.h" |
| 22 #include "ceee/ie/plugin/bho/infobar_manager.h" |
22 #include "ceee/ie/testing/mock_broker_and_friends.h" | 23 #include "ceee/ie/testing/mock_broker_and_friends.h" |
23 #include "ceee/ie/testing/mock_frame_event_handler_host.h" | 24 #include "ceee/ie/testing/mock_frame_event_handler_host.h" |
24 #include "ceee/common/initializing_coclass.h" | 25 #include "ceee/common/initializing_coclass.h" |
25 #include "ceee/testing/utils/mock_com.h" | 26 #include "ceee/testing/utils/mock_com.h" |
26 #include "ceee/testing/utils/mshtml_mocks.h" | 27 #include "ceee/testing/utils/mshtml_mocks.h" |
27 #include "ceee/testing/utils/mock_static.h" | 28 #include "ceee/testing/utils/mock_static.h" |
28 #include "ceee/testing/utils/mock_window_utils.h" | 29 #include "ceee/testing/utils/mock_window_utils.h" |
29 #include "ceee/testing/utils/test_utils.h" | 30 #include "ceee/testing/utils/test_utils.h" |
30 #include "ceee/testing/utils/instance_count_mixin.h" | 31 #include "ceee/testing/utils/instance_count_mixin.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 HRESULT Initialize(StrictMock<TestingMockExecutorCreatorTeardown>** self) { | 74 HRESULT Initialize(StrictMock<TestingMockExecutorCreatorTeardown>** self) { |
74 // Yes, this seems fishy, but it is called from InitializingCoClass | 75 // Yes, this seems fishy, but it is called from InitializingCoClass |
75 // which does it on the class we pass it as a template, so we are OK. | 76 // which does it on the class we pass it as a template, so we are OK. |
76 *self = static_cast<StrictMock<TestingMockExecutorCreatorTeardown>*>(this); | 77 *self = static_cast<StrictMock<TestingMockExecutorCreatorTeardown>*>(this); |
77 return S_OK; | 78 return S_OK; |
78 } | 79 } |
79 | 80 |
80 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, Teardown, HRESULT(long)); | 81 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, Teardown, HRESULT(long)); |
81 }; | 82 }; |
82 | 83 |
| 84 class MockInfobarManager : public infobar_api::InfobarManager { |
| 85 public: |
| 86 MockInfobarManager() : InfobarManager(kGoodWindow) {} |
| 87 MOCK_METHOD4(Show, HRESULT(infobar_api::InfobarType, int, |
| 88 const std::wstring&, bool)); |
| 89 MOCK_METHOD1(Hide, HRESULT(infobar_api::InfobarType)); |
| 90 MOCK_METHOD0(HideAll, void()); |
| 91 }; |
| 92 |
83 TEST(ExecutorCreator, ProperTearDownOnDestruction) { | 93 TEST(ExecutorCreator, ProperTearDownOnDestruction) { |
84 StrictMock<TestingMockExecutorCreatorTeardown>* executor_creator = NULL; | 94 StrictMock<TestingMockExecutorCreatorTeardown>* executor_creator = NULL; |
85 CComPtr<ICeeeExecutorCreator> executor_creator_keeper; | 95 CComPtr<ICeeeExecutorCreator> executor_creator_keeper; |
86 ASSERT_HRESULT_SUCCEEDED(StrictMock<TestingMockExecutorCreatorTeardown>:: | 96 ASSERT_HRESULT_SUCCEEDED(StrictMock<TestingMockExecutorCreatorTeardown>:: |
87 CreateInitialized(&executor_creator, &executor_creator_keeper)); | 97 CreateInitialized(&executor_creator, &executor_creator_keeper)); |
88 EXPECT_CALL(*executor_creator, Teardown(42L)).WillOnce(Return(S_OK)); | 98 EXPECT_CALL(*executor_creator, Teardown(42L)).WillOnce(Return(S_OK)); |
89 // The Release of the last reference should call FinalRelease. | 99 // The Release of the last reference should call FinalRelease. |
90 } | 100 } |
91 | 101 |
92 // Mock object for some functions used for hooking. | 102 // Mock object for some functions used for hooking. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 HRESULT Initialize(TestingExecutor** self) { | 318 HRESULT Initialize(TestingExecutor** self) { |
309 *self = this; | 319 *self = this; |
310 return S_OK; | 320 return S_OK; |
311 } | 321 } |
312 static void set_tab_windows(std::vector<HWND> tab_windows) { | 322 static void set_tab_windows(std::vector<HWND> tab_windows) { |
313 tab_windows_ = tab_windows; | 323 tab_windows_ = tab_windows; |
314 } | 324 } |
315 void set_id(HWND hwnd) { | 325 void set_id(HWND hwnd) { |
316 hwnd_ = hwnd; | 326 hwnd_ = hwnd; |
317 } | 327 } |
| 328 void InitializeInfobarManager(MockInfobarManager** manager) { |
| 329 ASSERT_TRUE(manager != NULL); |
| 330 *manager = new MockInfobarManager(); |
| 331 infobar_manager_.reset(*manager); |
| 332 } |
| 333 void TerminateInfobarManager() { |
| 334 infobar_manager_.reset(NULL); |
| 335 } |
318 static BOOL MockEnumChildWindows(HWND, WNDENUMPROC, LPARAM p) { | 336 static BOOL MockEnumChildWindows(HWND, WNDENUMPROC, LPARAM p) { |
319 std::vector<HWND>* tab_windows = reinterpret_cast<std::vector<HWND>*>(p); | 337 std::vector<HWND>* tab_windows = reinterpret_cast<std::vector<HWND>*>(p); |
320 *tab_windows = tab_windows_; | 338 *tab_windows = tab_windows_; |
321 return TRUE; | 339 return TRUE; |
322 } | 340 } |
323 static void set_cookie_data(const std::wstring& cookie_data) { | 341 static void set_cookie_data(const std::wstring& cookie_data) { |
324 cookie_data_ = cookie_data; | 342 cookie_data_ = cookie_data; |
325 } | 343 } |
326 static BOOL MockInternetGetCookieExW(LPCWSTR, LPCWSTR, LPWSTR data, | 344 static BOOL MockInternetGetCookieExW(LPCWSTR, LPCWSTR, LPWSTR data, |
327 LPDWORD size, DWORD, LPVOID) { | 345 LPDWORD size, DWORD, LPVOID) { |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 testing::LogDisabler no_dchecks; | 1094 testing::LogDisabler no_dchecks; |
1077 | 1095 |
1078 executor_->set_cookie_store_is_registered(false); | 1096 executor_->set_cookie_store_is_registered(false); |
1079 EXPECT_EQ(S_FALSE, executor_->CookieStoreIsRegistered()); | 1097 EXPECT_EQ(S_FALSE, executor_->CookieStoreIsRegistered()); |
1080 EXPECT_HRESULT_SUCCEEDED(executor_->RegisterCookieStore()); | 1098 EXPECT_HRESULT_SUCCEEDED(executor_->RegisterCookieStore()); |
1081 EXPECT_EQ(S_OK, executor_->CookieStoreIsRegistered()); | 1099 EXPECT_EQ(S_OK, executor_->CookieStoreIsRegistered()); |
1082 EXPECT_HRESULT_SUCCEEDED(executor_->RegisterCookieStore()); | 1100 EXPECT_HRESULT_SUCCEEDED(executor_->RegisterCookieStore()); |
1083 EXPECT_EQ(S_OK, executor_->CookieStoreIsRegistered()); | 1101 EXPECT_EQ(S_OK, executor_->CookieStoreIsRegistered()); |
1084 } | 1102 } |
1085 | 1103 |
1086 // TODO(vadimb@google.com): Add unit tests for infobar APIs. | 1104 TEST_F(ExecutorTests, ShowInfobar) { |
| 1105 testing::LogDisabler no_dchecks; |
| 1106 CComBSTR url(L"/infobar/test.html"); |
| 1107 CComBSTR empty_url(L""); |
| 1108 CComBSTR extension_id(L"abcdefjh"); |
| 1109 |
| 1110 // Calling when manager has not been initialized. |
| 1111 EXPECT_HRESULT_FAILED(executor_->ShowInfobar(url, NULL)); |
| 1112 |
| 1113 // Initializing the manager and calling it with different parameters. |
| 1114 MockInfobarManager* manager; |
| 1115 executor_->InitializeInfobarManager(&manager); |
| 1116 |
| 1117 EXPECT_CALL(*manager, Show(infobar_api::TOP_INFOBAR, _, |
| 1118 std::wstring(url.m_str), true)). |
| 1119 WillOnce(Return(S_OK)); |
| 1120 EXPECT_CALL(mock_window_utils_, GetTopLevelParent(_)). |
| 1121 WillRepeatedly(Return(kGoodWindow)); |
| 1122 CeeeWindowHandle window_handle; |
| 1123 |
| 1124 EXPECT_HRESULT_SUCCEEDED(executor_->ShowInfobar(url, &window_handle)); |
| 1125 EXPECT_EQ(reinterpret_cast<CeeeWindowHandle>(kGoodWindow), window_handle); |
| 1126 |
| 1127 EXPECT_CALL(*manager, HideAll()).Times(1); |
| 1128 EXPECT_HRESULT_SUCCEEDED(executor_->ShowInfobar(empty_url, &window_handle)); |
| 1129 EXPECT_EQ(0, window_handle); |
| 1130 |
| 1131 EXPECT_CALL(*manager, Show(infobar_api::TOP_INFOBAR, _, |
| 1132 std::wstring(url.m_str), true)). |
| 1133 WillOnce(Return(E_FAIL)); |
| 1134 EXPECT_HRESULT_FAILED(executor_->ShowInfobar(url, &window_handle)); |
| 1135 EXPECT_EQ(0, window_handle); |
| 1136 |
| 1137 EXPECT_CALL(*manager, HideAll()).Times(1); |
| 1138 EXPECT_HRESULT_SUCCEEDED(executor_->OnTopFrameBeforeNavigate(url)); |
| 1139 |
| 1140 EXPECT_HRESULT_SUCCEEDED(executor_->SetExtensionId(extension_id)); |
| 1141 std::wstring full_url(L"chrome-extension://"); |
| 1142 full_url += extension_id.m_str; |
| 1143 full_url += url.m_str; |
| 1144 EXPECT_CALL(*manager, Show(infobar_api::TOP_INFOBAR, _, full_url, true)). |
| 1145 WillOnce(Return(S_OK)); |
| 1146 EXPECT_HRESULT_SUCCEEDED(executor_->ShowInfobar(url, &window_handle)); |
| 1147 |
| 1148 // Have to destroy the manager before LogDisabler from this test goes out of |
| 1149 // scope. |
| 1150 EXPECT_CALL(user32_, IsWindow(NULL)).WillRepeatedly(Return(FALSE)); |
| 1151 executor_->TerminateInfobarManager(); |
| 1152 } |
1087 | 1153 |
1088 } // namespace | 1154 } // namespace |
OLD | NEW |