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 // Tab API implementation unit tests. | 5 // Tab API implementation unit tests. |
6 | 6 |
7 // MockWin32 can't be included after ChromeFrameHost because of an include | 7 // MockWin32 can't be included after ChromeFrameHost because of an include |
8 // incompatibility with atlwin.h. | 8 // incompatibility with atlwin.h. |
9 #include "ceee/testing/utils/mock_win32.h" // NOLINT | 9 #include "ceee/testing/utils/mock_win32.h" // NOLINT |
10 | 10 |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/scoped_comptr_win.h" | 13 #include "base/win/scoped_comptr.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "ceee/common/initializing_coclass.h" | 15 #include "ceee/common/initializing_coclass.h" |
16 #include "ceee/ie/broker/api_dispatcher.h" | 16 #include "ceee/ie/broker/api_dispatcher.h" |
17 #include "ceee/ie/broker/chrome_postman.h" | 17 #include "ceee/ie/broker/chrome_postman.h" |
18 #include "ceee/ie/broker/tab_api_module.h" | 18 #include "ceee/ie/broker/tab_api_module.h" |
19 #include "ceee/ie/common/ie_util.h" | 19 #include "ceee/ie/common/ie_util.h" |
20 #include "ceee/ie/testing/mock_broker_and_friends.h" | 20 #include "ceee/ie/testing/mock_broker_and_friends.h" |
21 #include "ceee/testing/utils/instance_count_mixin.h" | 21 #include "ceee/testing/utils/instance_count_mixin.h" |
22 #include "ceee/testing/utils/mock_com.h" | 22 #include "ceee/testing/utils/mock_com.h" |
23 #include "ceee/testing/utils/mock_window_utils.h" | 23 #include "ceee/testing/utils/mock_window_utils.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 private: | 182 private: |
183 class MockChromePostman : public ChromePostman { | 183 class MockChromePostman : public ChromePostman { |
184 public: | 184 public: |
185 MOCK_METHOD2(PostMessage, void(BSTR, BSTR)); | 185 MOCK_METHOD2(PostMessage, void(BSTR, BSTR)); |
186 }; | 186 }; |
187 // We should never get to the postman, we mock all the calls getting there. | 187 // We should never get to the postman, we mock all the calls getting there. |
188 // So we simply instantiate it strict and it will register itself as the | 188 // So we simply instantiate it strict and it will register itself as the |
189 // one and only singleton to use all the time. | 189 // one and only singleton to use all the time. |
190 CComObjectStackEx< StrictMock< MockChromePostman > > postman_; | 190 CComObjectStackEx< StrictMock< MockChromePostman > > postman_; |
191 // To control the life span of the tab executor. | 191 // To control the life span of the tab executor. |
192 ScopedComPtr<ICeeeTabExecutor> mock_tab_executor_keeper_; | 192 base::win::ScopedComPtr<ICeeeTabExecutor> mock_tab_executor_keeper_; |
193 ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; | 193 base::win::ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; |
194 }; | 194 }; |
195 | 195 |
196 TEST_F(TabApiTests, CreateTabValueErrorHandling) { | 196 TEST_F(TabApiTests, CreateTabValueErrorHandling) { |
197 testing::LogDisabler no_dchecks; | 197 testing::LogDisabler no_dchecks; |
198 | 198 |
199 // Window with no thread. | 199 // Window with no thread. |
200 StrictMock<testing::MockWindowUtils> window_utils; | 200 StrictMock<testing::MockWindowUtils> window_utils; |
201 EXPECT_CALL(window_utils, WindowHasNoThread(kGoodTabWindow)). | 201 EXPECT_CALL(window_utils, WindowHasNoThread(kGoodTabWindow)). |
202 WillOnce(Return(true)); | 202 WillOnce(Return(true)); |
203 | 203 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 invocation.Execute(ListValue(), kRequestId); | 763 invocation.Execute(ListValue(), kRequestId); |
764 | 764 |
765 invocation.AllocateNewResult(kRequestId); | 765 invocation.AllocateNewResult(kRequestId); |
766 EXPECT_CALL(*invocation.invocation_result_, | 766 EXPECT_CALL(*invocation.invocation_result_, |
767 GetSpecifiedOrCurrentFrameWindow(_, _)). | 767 GetSpecifiedOrCurrentFrameWindow(_, _)). |
768 WillRepeatedly(Return(kGoodFrameWindow)); | 768 WillRepeatedly(Return(kGoodFrameWindow)); |
769 | 769 |
770 // Failing Executor. | 770 // Failing Executor. |
771 // The executor classes are already strict from their base class impl. | 771 // The executor classes are already strict from their base class impl. |
772 testing::MockWindowExecutor* mock_window_executor; | 772 testing::MockWindowExecutor* mock_window_executor; |
773 ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; | 773 base::win::ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; |
774 EXPECT_HRESULT_SUCCEEDED(testing::MockWindowExecutor::CreateInitialized( | 774 EXPECT_HRESULT_SUCCEEDED(testing::MockWindowExecutor::CreateInitialized( |
775 &mock_window_executor, mock_window_executor_keeper_.Receive())); | 775 &mock_window_executor, mock_window_executor_keeper_.Receive())); |
776 EXPECT_CALL(invocation.mock_api_dispatcher_, | 776 EXPECT_CALL(invocation.mock_api_dispatcher_, |
777 GetExecutor(kGoodFrameWindow, _, NotNull())). | 777 GetExecutor(kGoodFrameWindow, _, NotNull())). |
778 WillRepeatedly(DoAll(SetArgumentPointee<2>( | 778 WillRepeatedly(DoAll(SetArgumentPointee<2>( |
779 mock_window_executor_keeper_.get()), | 779 mock_window_executor_keeper_.get()), |
780 AddRef(mock_window_executor_keeper_.get()))); | 780 AddRef(mock_window_executor_keeper_.get()))); |
781 EXPECT_CALL(*mock_window_executor, GetTabs(NotNull())). | 781 EXPECT_CALL(*mock_window_executor, GetTabs(NotNull())). |
782 WillOnce(Return(E_FAIL)); | 782 WillOnce(Return(E_FAIL)); |
783 EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); | 783 EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 | 1114 |
1115 // Navigate Fails. | 1115 // Navigate Fails. |
1116 invocation.AllocateNewResult(kRequestId); | 1116 invocation.AllocateNewResult(kRequestId); |
1117 EXPECT_CALL(*invocation.invocation_result_, | 1117 EXPECT_CALL(*invocation.invocation_result_, |
1118 GetSpecifiedOrCurrentFrameWindow(_, _)). | 1118 GetSpecifiedOrCurrentFrameWindow(_, _)). |
1119 WillOnce(Return(kGoodFrameWindow)); | 1119 WillOnce(Return(kGoodFrameWindow)); |
1120 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; | 1120 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; |
1121 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance( | 1121 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance( |
1122 &browser); | 1122 &browser); |
1123 DCHECK(browser != NULL); | 1123 DCHECK(browser != NULL); |
1124 ScopedComPtr<IWebBrowser2> browser_keeper(browser); | 1124 base::win::ScopedComPtr<IWebBrowser2> browser_keeper(browser); |
1125 if (pre_vista) { | 1125 if (pre_vista) { |
1126 EXPECT_CALL(mock_ie_util, GetWebBrowserForTopLevelIeHwnd( | 1126 EXPECT_CALL(mock_ie_util, GetWebBrowserForTopLevelIeHwnd( |
1127 kGoodFrameWindow, _, NotNull())).WillRepeatedly(DoAll( | 1127 kGoodFrameWindow, _, NotNull())).WillRepeatedly(DoAll( |
1128 CopyInterfaceToArgument<2>(browser_keeper.get()), Return(S_OK))); | 1128 CopyInterfaceToArgument<2>(browser_keeper.get()), Return(S_OK))); |
1129 EXPECT_CALL(*browser, Navigate(_, _, _, _, _)).WillOnce(Return(E_FAIL)); | 1129 EXPECT_CALL(*browser, Navigate(_, _, _, _, _)).WillOnce(Return(E_FAIL)); |
1130 } else { | 1130 } else { |
1131 AlwaysMockGetTabExecutor(&invocation.mock_api_dispatcher_, kGoodTabWindow); | 1131 AlwaysMockGetTabExecutor(&invocation.mock_api_dispatcher_, kGoodTabWindow); |
1132 EXPECT_CALL(*mock_tab_executor_, Navigate(_, _, _)). | 1132 EXPECT_CALL(*mock_tab_executor_, Navigate(_, _, _)). |
1133 WillOnce(Return(E_FAIL)); | 1133 WillOnce(Return(E_FAIL)); |
1134 } | 1134 } |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 EXPECT_EQ(TabApiResult::IsTabFromSameOrUnspecifiedFrameWindow( | 1556 EXPECT_EQ(TabApiResult::IsTabFromSameOrUnspecifiedFrameWindow( |
1557 input_dict, &other_saved_window, NULL, &mock_api_dispatcher), S_FALSE); | 1557 input_dict, &other_saved_window, NULL, &mock_api_dispatcher), S_FALSE); |
1558 tab_window = NULL; | 1558 tab_window = NULL; |
1559 EXPECT_EQ(TabApiResult::IsTabFromSameOrUnspecifiedFrameWindow( | 1559 EXPECT_EQ(TabApiResult::IsTabFromSameOrUnspecifiedFrameWindow( |
1560 input_dict, &other_saved_window, &tab_window, &mock_api_dispatcher), | 1560 input_dict, &other_saved_window, &tab_window, &mock_api_dispatcher), |
1561 S_FALSE); | 1561 S_FALSE); |
1562 EXPECT_EQ(kGoodTabWindow, tab_window); | 1562 EXPECT_EQ(kGoodTabWindow, tab_window); |
1563 } | 1563 } |
1564 | 1564 |
1565 } // namespace | 1565 } // namespace |
OLD | NEW |