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 // Window API implementation unit tests. | 5 // Window 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 <iepmapi.h> | 11 #include <iepmapi.h> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/scoped_comptr_win.h" | |
15 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "base/win/scoped_comptr.h" |
16 #include "ceee/common/process_utils_win.h" | 16 #include "ceee/common/process_utils_win.h" |
17 #include "ceee/ie/broker/chrome_postman.h" | 17 #include "ceee/ie/broker/chrome_postman.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/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" |
24 #include "ceee/testing/utils/test_utils.h" | 24 #include "ceee/testing/utils/test_utils.h" |
25 #include "chrome/browser/extensions/extension_event_names.h" | 25 #include "chrome/browser/extensions/extension_event_names.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 EXPECT_CALL(user32_, IsWindow(NotNull())).WillRepeatedly(Return(TRUE)); | 268 EXPECT_CALL(user32_, IsWindow(NotNull())).WillRepeatedly(Return(TRUE)); |
269 EXPECT_CALL(user32_, GetClassName(NotNull(), NotNull(), Gt(0))). | 269 EXPECT_CALL(user32_, GetClassName(NotNull(), NotNull(), Gt(0))). |
270 WillRepeatedly(DoAll(CopyStringToArgument<1>(kClassName), | 270 WillRepeatedly(DoAll(CopyStringToArgument<1>(kClassName), |
271 Return(arraysize(kClassName)))); | 271 Return(arraysize(kClassName)))); |
272 } | 272 } |
273 StrictMock<testing::MockUser32> user32_; | 273 StrictMock<testing::MockUser32> user32_; |
274 // The executor classes are already strict from their base class impl. | 274 // The executor classes are already strict from their base class impl. |
275 testing::MockWindowExecutor* mock_window_executor_; | 275 testing::MockWindowExecutor* mock_window_executor_; |
276 testing::MockTabExecutor* mock_tab_executor_; | 276 testing::MockTabExecutor* mock_tab_executor_; |
277 // To control the life span of the executors. | 277 // To control the life span of the executors. |
278 ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; | 278 base::win::ScopedComPtr<ICeeeWindowExecutor> mock_window_executor_keeper_; |
279 ScopedComPtr<ICeeeTabExecutor> mock_tab_executor_keeper_; | 279 base::win::ScopedComPtr<ICeeeTabExecutor> mock_tab_executor_keeper_; |
280 | 280 |
281 // Lifespan controlled by Singleton template. | 281 // Lifespan controlled by Singleton template. |
282 StrictMock<testing::MockExecutorsManager>* executors_manager_; | 282 StrictMock<testing::MockExecutorsManager>* executors_manager_; |
283 private: | 283 private: |
284 class MockChromePostman : public ChromePostman { | 284 class MockChromePostman : public ChromePostman { |
285 public: | 285 public: |
286 MOCK_METHOD2(PostMessage, void(BSTR, BSTR)); | 286 MOCK_METHOD2(PostMessage, void(BSTR, BSTR)); |
287 }; | 287 }; |
288 // We should never get to the postman, we mock all the calls getting there. | 288 // We should never get to the postman, we mock all the calls getting there. |
289 // So we simply instantiate it strict and it will register itself as the | 289 // So we simply instantiate it strict and it will register itself as the |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 EXPECT_CALL(mock_ie_create, IEIsProtectedModeURL(_)). | 731 EXPECT_CALL(mock_ie_create, IEIsProtectedModeURL(_)). |
732 WillRepeatedly(Return(S_FALSE)); | 732 WillRepeatedly(Return(S_FALSE)); |
733 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). | 733 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). |
734 WillOnce(Return(REGDB_E_CLASSNOTREG)); | 734 WillOnce(Return(REGDB_E_CLASSNOTREG)); |
735 invocation.Execute(args_list, kRequestId); | 735 invocation.Execute(args_list, kRequestId); |
736 | 736 |
737 invocation.AllocateNewResult(kRequestId); | 737 invocation.AllocateNewResult(kRequestId); |
738 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; | 738 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; |
739 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance(&browser); | 739 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance(&browser); |
740 DCHECK(browser != NULL); | 740 DCHECK(browser != NULL); |
741 ScopedComPtr<IWebBrowser2> browser_keeper(browser); | 741 base::win::ScopedComPtr<IWebBrowser2> browser_keeper(browser); |
742 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). | 742 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). |
743 WillRepeatedly(DoAll(SetArgumentPointee<4>(browser_keeper.get()), | 743 WillRepeatedly(DoAll(SetArgumentPointee<4>(browser_keeper.get()), |
744 AddRef(browser_keeper.get()), Return(S_OK))); | 744 AddRef(browser_keeper.get()), Return(S_OK))); |
745 | 745 |
746 EXPECT_CALL(*browser, get_HWND(NotNull())).WillRepeatedly(DoAll( | 746 EXPECT_CALL(*browser, get_HWND(NotNull())).WillRepeatedly(DoAll( |
747 SetArgumentPointee<0>(0), Return(S_OK))); | 747 SetArgumentPointee<0>(0), Return(S_OK))); |
748 EXPECT_CALL(*invocation.invocation_result_, UpdateWindowRect(_, _)). | 748 EXPECT_CALL(*invocation.invocation_result_, UpdateWindowRect(_, _)). |
749 WillOnce(Return(false)); | 749 WillOnce(Return(false)); |
750 invocation.Execute(args_list, kRequestId); | 750 invocation.Execute(args_list, kRequestId); |
751 | 751 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 { &args3, about_blank, false }, | 796 { &args3, about_blank, false }, |
797 { &empty_args, about_blank, false }, | 797 { &empty_args, about_blank, false }, |
798 }; | 798 }; |
799 | 799 |
800 typedef StrictMock<MockWindowInvocation<window_api::CreateWindowFunc>> | 800 typedef StrictMock<MockWindowInvocation<window_api::CreateWindowFunc>> |
801 MockCreateWindowFunc; | 801 MockCreateWindowFunc; |
802 | 802 |
803 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; | 803 CComObject<StrictMock<testing::MockIWebBrowser2>>* browser; |
804 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance(&browser); | 804 CComObject<StrictMock<testing::MockIWebBrowser2>>::CreateInstance(&browser); |
805 DCHECK(browser != NULL); | 805 DCHECK(browser != NULL); |
806 ScopedComPtr<IWebBrowser2> browser_keeper(browser); | 806 base::win::ScopedComPtr<IWebBrowser2> browser_keeper(browser); |
807 MockIeWindowCreation mock_ie_create; | 807 MockIeWindowCreation mock_ie_create; |
808 // TODO(mad@chromium.org): Test behavior with protected on too. | 808 // TODO(mad@chromium.org): Test behavior with protected on too. |
809 EXPECT_CALL(mock_ie_create, IEIsProtectedModeURL(_)). | 809 EXPECT_CALL(mock_ie_create, IEIsProtectedModeURL(_)). |
810 WillRepeatedly(Return(S_FALSE)); | 810 WillRepeatedly(Return(S_FALSE)); |
811 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). | 811 EXPECT_CALL(mock_ie_create, CoCreateInstance(_, _, _, _, _)). |
812 WillRepeatedly(DoAll(SetArgumentPointee<4>(browser_keeper.get()), | 812 WillRepeatedly(DoAll(SetArgumentPointee<4>(browser_keeper.get()), |
813 AddRef(browser_keeper.get()), Return(S_OK))); | 813 AddRef(browser_keeper.get()), Return(S_OK))); |
814 EXPECT_CALL(*browser, get_HWND(NotNull())).WillRepeatedly(DoAll( | 814 EXPECT_CALL(*browser, get_HWND(NotNull())).WillRepeatedly(DoAll( |
815 SetArgumentPointee<0>(0), Return(S_OK))); | 815 SetArgumentPointee<0>(0), Return(S_OK))); |
816 EXPECT_CALL(*browser, Navigate(_, _, _, _, _)).WillRepeatedly(Return(S_OK)); | 816 EXPECT_CALL(*browser, Navigate(_, _, _, _, _)).WillRepeatedly(Return(S_OK)); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 kWindow2, values[i].populate)).WillOnce(Return(true)); | 1036 kWindow2, values[i].populate)).WillOnce(Return(true)); |
1037 EXPECT_CALL(*invocation.invocation_result_, CallRealPostResult()).Times(1); | 1037 EXPECT_CALL(*invocation.invocation_result_, CallRealPostResult()).Times(1); |
1038 MockIterativeWindowApiResult::ResetCounters(); | 1038 MockIterativeWindowApiResult::ResetCounters(); |
1039 invocation.Execute(*values[i].value, kRequestId); | 1039 invocation.Execute(*values[i].value, kRequestId); |
1040 EXPECT_EQ(MockIterativeWindowApiResult::error_counter(), 0); | 1040 EXPECT_EQ(MockIterativeWindowApiResult::error_counter(), 0); |
1041 EXPECT_EQ(MockIterativeWindowApiResult::success_counter(), ie_hwnds.size()); | 1041 EXPECT_EQ(MockIterativeWindowApiResult::success_counter(), ie_hwnds.size()); |
1042 } | 1042 } |
1043 } | 1043 } |
1044 | 1044 |
1045 } // namespace | 1045 } // namespace |
OLD | NEW |