diff options
author | mad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-08 18:27:23 +0000 |
---|---|---|
committer | mad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-08 18:27:23 +0000 |
commit | 5d67aee68bd072db2bbeef3e1f8508425d96af72 (patch) | |
tree | 0aba7dfab8edfc4051e3d50e2bded6541501f5b8 /ceee | |
parent | 460c3f128621f6ce0f2d0752958d14f2ef12960b (diff) | |
download | chromium_src-5d67aee68bd072db2bbeef3e1f8508425d96af72.zip chromium_src-5d67aee68bd072db2bbeef3e1f8508425d96af72.tar.gz chromium_src-5d67aee68bd072db2bbeef3e1f8508425d96af72.tar.bz2 |
Fixed failing unittests.
Some tests were explicitly setting the last error that an expected mock method would have set in the real world, but some code in the mean time can reset it to zero, so we now set the error code as part of the mocked expectation using testing::Invoke.
BUG=None
Test=Make sure the unit tests always succeed.
Review URL: http://codereview.chromium.org/4646002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/ie/plugin/bho/executor_unittest.cc | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ceee/ie/plugin/bho/executor_unittest.cc b/ceee/ie/plugin/bho/executor_unittest.cc index e260fd3..d68f2d0 100644 --- a/ceee/ie/plugin/bho/executor_unittest.cc +++ b/ceee/ie/plugin/bho/executor_unittest.cc @@ -46,6 +46,7 @@ using testing::NotNull; using testing::Return; using testing::SetArgumentPointee; using testing::StrictMock; +using testing::WithoutArgs; const int kGoodWindowId = 42; const HWND kGoodWindow = reinterpret_cast<HWND>(kGoodWindowId); @@ -127,6 +128,11 @@ class TestingExecutorCreator : public CeeeExecutorCreator { using CeeeExecutorCreator::GetMsgProc; }; +template<int error_code> +void SetFakeLastError() { + ::SetLastError(error_code); +} + TEST(ExecutorCreator, CreateExecutor) { testing::LogDisabler no_dchecks; @@ -143,8 +149,8 @@ TEST(ExecutorCreator, CreateExecutor) { EXPECT_CALL(mock_hooking, SetWindowsHookEx(WH_GETMESSAGE, _, _, 42L)). WillRepeatedly(Return(reinterpret_cast<HHOOK>(1))); EXPECT_CALL(mock_hooking, PostThreadMessage(42L, _, 0, 0)). - WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_ACCESS); + WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError<ERROR_INVALID_ACCESS>)), Return(FALSE))); EXPECT_HRESULT_FAILED(executor_creator.CreateWindowExecutor(42L, 0L)); ::SetLastError(ERROR_SUCCESS); @@ -462,8 +468,8 @@ TEST_F(ExecutorTests, GetWindow) { EXPECT_CALL(mock_window_utils_, GetTopLevelParent(kGoodWindow)). WillRepeatedly(Return(kGoodWindow)); EXPECT_CALL(user32_, GetWindowRect(kGoodWindow, NotNull())). - WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_ACCESS); + WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError<ERROR_INVALID_ACCESS>)), Return(FALSE))); common_api::WindowInfo window_info; EXPECT_HRESULT_FAILED(executor_->GetWindow(FALSE, &window_info)); EXPECT_EQ(NULL, window_info.tab_list); @@ -938,18 +944,20 @@ TEST_F(ExecutorTests, GetCookieValue) { // Failure to get cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) - .WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_PARAMETER); + .WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError<ERROR_INVALID_PARAMETER>)), Return(FALSE))); CComBSTR value; EXPECT_HRESULT_FAILED(executor_->CallGetCookieValue(url, name, &value)); EXPECT_EQ((BSTR)NULL, value); + ::SetLastError(ERROR_SUCCESS); // Nonexistent cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) - .WillOnce(Return(FALSE)); - ::SetLastError(ERROR_NO_MORE_ITEMS); + .WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError<ERROR_NO_MORE_ITEMS>)), Return(FALSE))); EXPECT_EQ(S_FALSE, executor_->CallGetCookieValue(url, name, &value)); EXPECT_EQ((BSTR)NULL, value); + ::SetLastError(ERROR_SUCCESS); // Malformed cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) |