diff options
author | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-26 22:38:31 +0000 |
---|---|---|
committer | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-26 22:38:31 +0000 |
commit | 8c730e05b504197010e204a5690fc8a8a43cb140 (patch) | |
tree | 74d5b634a2f7635075e77060a82d11bdd431794a /ceee | |
parent | bb461530cb42d050c91bacc9ec1a6a48100c6be7 (diff) | |
download | chromium_src-8c730e05b504197010e204a5690fc8a8a43cb140.zip chromium_src-8c730e05b504197010e204a5690fc8a8a43cb140.tar.gz chromium_src-8c730e05b504197010e204a5690fc8a8a43cb140.tar.bz2 |
IE CEEE: Validate tab IDs passed into all chrome.tabs.* APIs that take a tab ID as input before
trying to convert them to tab handles.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/5309004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/ie/broker/api_dispatcher.cc | 9 | ||||
-rw-r--r-- | ceee/ie/broker/api_dispatcher.h | 12 | ||||
-rw-r--r-- | ceee/ie/broker/executors_manager.cc | 20 | ||||
-rw-r--r-- | ceee/ie/broker/executors_manager.h | 12 | ||||
-rw-r--r-- | ceee/ie/broker/executors_manager_unittest.cc | 26 | ||||
-rw-r--r-- | ceee/ie/broker/tab_api_module.cc | 34 | ||||
-rw-r--r-- | ceee/ie/broker/tab_api_module_unittest.cc | 45 | ||||
-rw-r--r-- | ceee/ie/testing/mock_broker_and_friends.h | 1 |
8 files changed, 159 insertions, 0 deletions
diff --git a/ceee/ie/broker/api_dispatcher.cc b/ceee/ie/broker/api_dispatcher.cc index e1ecec0..9e30ee5 100644 --- a/ceee/ie/broker/api_dispatcher.cc +++ b/ceee/ie/broker/api_dispatcher.cc @@ -149,6 +149,10 @@ void ApiDispatcher::GetExecutor(HWND window, REFIID iid, void** executor) { window << ". In thread: " << thread_id << ". " << com::LogHr(hr); } +bool ApiDispatcher::IsTabIdValid(int tab_id) const { + return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> + IsTabIdValid(tab_id); +} HWND ApiDispatcher::GetTabHandleFromId(int tab_id) const { return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> @@ -164,6 +168,11 @@ HWND ApiDispatcher::GetWindowHandleFromId(int window_id) const { return reinterpret_cast<HWND>(window_id); } +bool ApiDispatcher::IsTabHandleValid(HWND tab_handle) const { + return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> + IsTabHandleValid(tab_handle); +} + int ApiDispatcher::GetTabIdFromHandle(HWND tab_handle) const { return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> GetTabIdFromHandle(tab_handle); diff --git a/ceee/ie/broker/api_dispatcher.h b/ceee/ie/broker/api_dispatcher.h index d9fabde..6f6a86a 100644 --- a/ceee/ie/broker/api_dispatcher.h +++ b/ceee/ie/broker/api_dispatcher.h @@ -217,6 +217,12 @@ class ApiDispatcher { // @param executor Where to return the requested executor interface pointer. virtual void GetExecutor(HWND window, REFIID iid, void** executor); + // Return whether a tab ID is valid. + // + // @param tab_id The tab identifier. + // @return True if the tab ID exists in the tab ID map. + virtual bool IsTabIdValid(int tab_id) const; + // Return a tab handle associated with the id. // // @param tab_id The tab identifier. @@ -238,6 +244,12 @@ class ApiDispatcher { // found). virtual HWND GetWindowHandleFromId(int window_id) const; + // Return whether a tab handle is valid. + // + // @param tab_handle The tab handle. + // @return True if the tab handle exists in the tab handle map. + virtual bool IsTabHandleValid(HWND tab_handle) const; + // Return a tab id associated with the HWND. // // @param tab_handle The tab HWND. diff --git a/ceee/ie/broker/executors_manager.cc b/ceee/ie/broker/executors_manager.cc index da84aea..bb4df24 100644 --- a/ceee/ie/broker/executors_manager.cc +++ b/ceee/ie/broker/executors_manager.cc @@ -463,6 +463,16 @@ void ExecutorsManager::DeleteTabHandle(HWND handle) { windows_events_funnel().OnRemoved(frame_window); } +bool ExecutorsManager::IsTabIdValid(int tab_id) { + AutoLock lock(lock_); + TabIdMap::const_iterator it = tab_id_map_.find(tab_id); +#ifdef DEBUG + return it != tab_id_map_.end() && it->second != INVALID_HANDLE_VALUE; +#else + return it != tab_id_map_.end(); +#endif +} + HWND ExecutorsManager::GetTabHandleFromId(int tab_id) { AutoLock lock(lock_); TabIdMap::const_iterator it = tab_id_map_.find(tab_id); @@ -476,6 +486,16 @@ HWND ExecutorsManager::GetTabHandleFromId(int tab_id) { return it->second; } +bool ExecutorsManager::IsTabHandleValid(HWND tab_handle) { + AutoLock lock(lock_); + HandleMap::const_iterator it = handle_map_.find(tab_handle); +#ifdef DEBUG + return it != handle_map_.end() && it->second != kInvalidChromeSessionId; +#else + return it != handle_map_.end(); +#endif +} + int ExecutorsManager::GetTabIdFromHandle(HWND tab_handle) { AutoLock lock(lock_); HandleMap::const_iterator it = handle_map_.find(tab_handle); diff --git a/ceee/ie/broker/executors_manager.h b/ceee/ie/broker/executors_manager.h index 67bb890..a51e2da 100644 --- a/ceee/ie/broker/executors_manager.h +++ b/ceee/ie/broker/executors_manager.h @@ -79,6 +79,12 @@ class ExecutorsManager { // Terminates the usage of the map by freeing our resources. virtual HRESULT Terminate(); + // Return whether a tab ID is valid. + // + // @param tab_id The tab identifier. + // @return True if the tab ID exists in the tab ID map. + virtual bool IsTabIdValid(int tab_id); + // Return a tab handle associated with the id. // // @param tab_id The tab identifier. @@ -86,6 +92,12 @@ class ExecutorsManager { // found). virtual HWND GetTabHandleFromId(int tab_id); + // Return whether a tab handle is valid. + // + // @param tab_handle The tab handle. + // @return True if the tab handle exists in the tab handle map. + virtual bool IsTabHandleValid(HWND tab_handle); + // Return a tab ID associated with the HWND. // // @param tab_handle The tab HWND. diff --git a/ceee/ie/broker/executors_manager_unittest.cc b/ceee/ie/broker/executors_manager_unittest.cc index 2ade8ac..c698610 100644 --- a/ceee/ie/broker/executors_manager_unittest.cc +++ b/ceee/ie/broker/executors_manager_unittest.cc @@ -697,8 +697,10 @@ TEST_F(ExecutorsManagerTests, SetTabIdForHandle) { EXPECT_CALL(mock_common, IsIeFrameClass(kFrameWindow)). WillRepeatedly(Return(true)); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId)); @@ -706,28 +708,38 @@ TEST_F(ExecutorsManagerTests, SetTabIdForHandle) { EXPECT_CALL(executors_manager.mock_window_events_funnel_, OnCreated(kFrameWindow)).Times(1); executors_manager.SetTabIdForHandle(kTabWindowId, kTabWindow); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kTabWindowId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(kTabWindow, executors_manager.GetTabHandleFromId(kTabWindowId)); // Tab IDs or handles can only be mapped once. executors_manager.SetTabIdForHandle(kTabWindowId, kTabWindow2); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow2)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow2)); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kTabWindowId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(kTabWindow, executors_manager.GetTabHandleFromId(kTabWindowId)); executors_manager.SetTabIdForHandle(kTabWindowId2, kTabWindow); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kTabWindowId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(kTabWindow, executors_manager.GetTabHandleFromId(kTabWindowId)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId2)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId2)); executors_manager.SetTabIdForHandle(kTabWindowId2, kTabWindow2); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow2)); EXPECT_EQ(kTabWindowId2, executors_manager.GetTabIdFromHandle(kTabWindow2)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId2)); EXPECT_EQ(kTabWindow2, executors_manager.GetTabHandleFromId(kTabWindowId2)); } @@ -766,15 +778,19 @@ TEST_F(ExecutorsManagerTests, DeleteTabHandle) { // Test deletion of a nonexistent window. executors_manager.DeleteTabHandle(kTabWindow); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId)); EXPECT_CALL(executors_manager.mock_window_events_funnel_, OnCreated(kFrameWindow)).Times(1); executors_manager.SetTabIdForHandle(kTabWindowId, kTabWindow); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kTabWindowId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(kTabWindow, executors_manager.GetTabHandleFromId(kTabWindowId)); @@ -782,8 +798,10 @@ TEST_F(ExecutorsManagerTests, DeleteTabHandle) { EXPECT_CALL(executors_manager.mock_window_events_funnel_, OnRemoved(kFrameWindow)).Times(1); executors_manager.DeleteTabHandle(kTabWindow); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId)); // Test deletion of a nonexistent window when another one exists. @@ -791,12 +809,16 @@ TEST_F(ExecutorsManagerTests, DeleteTabHandle) { OnCreated(kFrameWindow)).Times(1); executors_manager.SetTabIdForHandle(kTabWindowId2, kTabWindow2); executors_manager.DeleteTabHandle(kTabWindow); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId)); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow2)); EXPECT_EQ(kTabWindowId2, executors_manager.GetTabIdFromHandle(kTabWindow2)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId2)); EXPECT_EQ(kTabWindow2, executors_manager.GetTabHandleFromId(kTabWindowId2)); } @@ -815,8 +837,10 @@ TEST_F(ExecutorsManagerTests, DeleteTabHandleWithToolBandId) { OnCreated(kFrameWindow)).Times(1); executors_manager.SetTabIdForHandle(kTabWindowId, kTabWindow); executors_manager.SetTabToolBandIdForHandle(kTabWindowId2, kTabWindow); + EXPECT_TRUE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kTabWindowId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_TRUE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(kTabWindow, executors_manager.GetTabHandleFromId(kTabWindowId)); EXPECT_EQ(kTabWindow, @@ -825,8 +849,10 @@ TEST_F(ExecutorsManagerTests, DeleteTabHandleWithToolBandId) { EXPECT_CALL(executors_manager.mock_window_events_funnel_, OnRemoved(kFrameWindow)).Times(1); executors_manager.DeleteTabHandle(kTabWindow); + EXPECT_FALSE(executors_manager.IsTabHandleValid(kTabWindow)); EXPECT_EQ(kInvalidChromeSessionId, executors_manager.GetTabIdFromHandle(kTabWindow)); + EXPECT_FALSE(executors_manager.IsTabIdValid(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, executors_manager.GetTabHandleFromId(kTabWindowId)); EXPECT_EQ(INVALID_HANDLE_VALUE, diff --git a/ceee/ie/broker/tab_api_module.cc b/ceee/ie/broker/tab_api_module.cc index 322b087..be0ba72 100644 --- a/ceee/ie/broker/tab_api_module.cc +++ b/ceee/ie/broker/tab_api_module.cc @@ -390,6 +390,12 @@ void GetTab::Execute(const ListValue& args, int request_id) { ApiDispatcher* dispatcher = GetDispatcher(); DCHECK(dispatcher != NULL); + if (!dispatcher->IsTabIdValid(tab_id)) { + result->PostError(ExtensionErrorUtils::FormatErrorMessage( + ext::kTabNotFoundError, base::IntToString(tab_id))); + return; + } + HWND tab_window = dispatcher->GetTabHandleFromId(tab_id); if (!result->IsTabWindowClass(tab_window)) { result->PostError(ExtensionErrorUtils::FormatErrorMessage( @@ -607,6 +613,13 @@ void UpdateTab::Execute(const ListValue& args, int request_id) { ApiDispatcher* dispatcher = GetDispatcher(); DCHECK(dispatcher != NULL); + + if (!dispatcher->IsTabIdValid(tab_id)) { + result->PostError(ExtensionErrorUtils::FormatErrorMessage( + ext::kTabNotFoundError, base::IntToString(tab_id))); + return; + } + HWND tab_window = dispatcher->GetTabHandleFromId(tab_id); if (!result->IsTabWindowClass(tab_window)) { result->PostError(ExtensionErrorUtils::FormatErrorMessage( @@ -699,6 +712,13 @@ void RemoveTab::Execute(const ListValue& args, int request_id) { ApiDispatcher* dispatcher = GetDispatcher(); DCHECK(dispatcher != NULL); + + if (!dispatcher->IsTabIdValid(tab_id)) { + result->PostError(ExtensionErrorUtils::FormatErrorMessage( + ext::kTabNotFoundError, base::IntToString(tab_id))); + return; + } + HWND tab_window = dispatcher->GetTabHandleFromId(tab_id); if (!result->IsTabWindowClass(tab_window)) { result->PostError(ExtensionErrorUtils::FormatErrorMessage( @@ -1049,6 +1069,13 @@ void MoveTab::Execute(const ListValue& args, int request_id) { ApiDispatcher* dispatcher = GetDispatcher(); DCHECK(dispatcher != NULL); + + if (!dispatcher->IsTabIdValid(tab_id)) { + result->PostError(ExtensionErrorUtils::FormatErrorMessage( + ext::kTabNotFoundError, base::IntToString(tab_id))); + return; + } + HWND tab_window = dispatcher->GetTabHandleFromId(tab_id); if (!result->IsTabWindowClass(tab_window)) { result->PostError(ExtensionErrorUtils::FormatErrorMessage( @@ -1143,6 +1170,13 @@ ApiDispatcher::InvocationResult* TabsInsertCode::ExecuteImpl( ApiDispatcher* dispatcher = GetDispatcher(); DCHECK(dispatcher != NULL); + + if (!dispatcher->IsTabIdValid(*tab_id)) { + result->PostError(ExtensionErrorUtils::FormatErrorMessage( + ext::kTabNotFoundError, base::IntToString(*tab_id))); + return NULL; + } + HWND tab_window = dispatcher->GetTabHandleFromId(*tab_id); if (!TabApiResult::IsTabWindowClass(tab_window)) { result->PostError(ExtensionErrorUtils::FormatErrorMessage( diff --git a/ceee/ie/broker/tab_api_module_unittest.cc b/ceee/ie/broker/tab_api_module_unittest.cc index 9c4a158..a7072c7 100644 --- a/ceee/ie/broker/tab_api_module_unittest.cc +++ b/ceee/ie/broker/tab_api_module_unittest.cc @@ -534,6 +534,8 @@ TEST_F(TabApiTests, GetTab) { EXPECT_CALL(*invocation.invocation_result_, CreateTabValue(kGoodTabWindowId, _)).WillOnce(Return(true)); EXPECT_CALL(*invocation.invocation_result_, PostResult()).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -541,9 +543,18 @@ TEST_F(TabApiTests, GetTab) { // No more successful calls. invocation.AllocateNewResult(kRequestId); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(false)); + invocation.Execute(good_args, kRequestId); + + invocation.AllocateNewResult(kRequestId); + EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kBadWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kBadWindowId)).WillOnce(Return(kBadWindow)); invocation.Execute(bad_window, kRequestId); + invocation.AllocateNewResult(kRequestId); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); invocation.Execute(ListValue(), kRequestId); @@ -833,6 +844,8 @@ TEST_F(TabApiTests, UpdateTab) { EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); invocation.Execute(empty_list, kRequestId); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(_)) + .WillRepeatedly(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kBadWindowId)).WillRepeatedly(Return(kBadWindow)); EXPECT_CALL(invocation.mock_api_dispatcher_, @@ -945,6 +958,8 @@ TEST_F(TabApiTests, RemoveTabExecute) { list_args.Append(Value::CreateIntegerValue(kGoodTabWindowId)); EXPECT_CALL(*invocation.invocation_result_, PostError(_)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(list_args, kRequestId); @@ -958,6 +973,8 @@ TEST_F(TabApiTests, RemoveTabExecute) { GetExecutor(kGoodFrameWindow, _, NotNull())). WillOnce(SetArgumentPointee<2>(static_cast<void*>(NULL))); EXPECT_CALL(*invocation.invocation_result_, PostError(_)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(list_args, kRequestId); @@ -969,6 +986,8 @@ TEST_F(TabApiTests, RemoveTabExecute) { EXPECT_CALL(*mock_window_executor_, RemoveTab(kGoodTabWindowHandle)). WillOnce(Return(E_FAIL)); EXPECT_CALL(*invocation.invocation_result_, PostError(_)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(list_args, kRequestId); @@ -981,6 +1000,8 @@ TEST_F(TabApiTests, RemoveTabExecute) { StrEq(ext_event_names::kOnTabRemoved), RemoveTab::ContinueExecution, invocation.invocation_result_.get())); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); // This will cause the invocation result to be released at the end of the @@ -1259,6 +1280,8 @@ TEST_F(TabApiTests, MoveTab) { EXPECT_TRUE(good_args.Insert(0, Value::CreateIntegerValue(kGoodTabWindowId))); EXPECT_CALL(window_utils, IsWindowClass(kGoodTabWindow, _)). WillOnce(Return(false)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); @@ -1270,6 +1293,8 @@ TEST_F(TabApiTests, MoveTab) { WillRepeatedly(Return(true)); EXPECT_TRUE(good_args.Insert(1, Value::CreateNullValue())); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -1279,6 +1304,8 @@ TEST_F(TabApiTests, MoveTab) { good_args.Remove(1, NULL); good_args_dict->SetInteger(ext::kWindowIdKey, kBadWindowId); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -1288,6 +1315,8 @@ TEST_F(TabApiTests, MoveTab) { good_args_dict->Remove(ext::kWindowIdKey, NULL); good_args_dict->SetBoolean(ext::kIndexKey, false); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -1300,6 +1329,8 @@ TEST_F(TabApiTests, MoveTab) { EXPECT_CALL(invocation.mock_api_dispatcher_, GetExecutor(kGoodFrameWindow, _, _)). WillOnce(SetArgumentPointee<2>(static_cast<void*>(NULL))); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); @@ -1313,6 +1344,8 @@ TEST_F(TabApiTests, MoveTab) { MoveTab(reinterpret_cast<CeeeWindowHandle>(kGoodTabWindow), kTabIndex)). WillOnce(Return(E_FAIL)); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -1326,6 +1359,8 @@ TEST_F(TabApiTests, MoveTab) { CreateTabValue(kGoodTabWindowId, kTabIndex)). WillOnce(Return(true)); EXPECT_CALL(*invocation.invocation_result_, PostResult()).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.Execute(good_args, kRequestId); @@ -1391,6 +1426,8 @@ TEST_F(TabApiTests, TabsInsertCode) { WillOnce(Return(false)); invocation.AllocateNewResult(kRequestId); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); EXPECT_EQ(NULL, invocation.CallExecuteImpl( @@ -1404,6 +1441,8 @@ TEST_F(TabApiTests, TabsInsertCode) { WillOnce(SetArgumentPointee<2>(static_cast<void*>(NULL))); invocation.AllocateNewResult(kRequestId); EXPECT_CALL(*invocation.invocation_result_, PostError(_)).Times(1); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); EXPECT_EQ(NULL, invocation.CallExecuteImpl( @@ -1414,6 +1453,8 @@ TEST_F(TabApiTests, TabsInsertCode) { EXPECT_CALL(*mock_tab_executor_, InsertCode(_, _, false, kCeeeTabCodeTypeCss)). WillOnce(Return(E_FAIL)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.AllocateNewResult(kRequestId); @@ -1427,6 +1468,8 @@ TEST_F(TabApiTests, TabsInsertCode) { EXPECT_CALL(*mock_tab_executor_, InsertCode(_, _, false, kCeeeTabCodeTypeCss)). WillRepeatedly(Return(S_OK)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.AllocateNewResult(kRequestId); @@ -1439,6 +1482,8 @@ TEST_F(TabApiTests, TabsInsertCode) { good_args_dict->SetBoolean(ext::kAllFramesKey, true); EXPECT_CALL(*mock_tab_executor_, InsertCode(_, _, true, kCeeeTabCodeTypeJs)).WillOnce(Return(S_OK)); + EXPECT_CALL(invocation.mock_api_dispatcher_, IsTabIdValid(kGoodTabWindowId)). + WillOnce(Return(true)); EXPECT_CALL(invocation.mock_api_dispatcher_, GetTabHandleFromId(kGoodTabWindowId)).WillOnce(Return(kGoodTabWindow)); invocation.AllocateNewResult(kRequestId); diff --git a/ceee/ie/testing/mock_broker_and_friends.h b/ceee/ie/testing/mock_broker_and_friends.h index 0fffb28..5658a48 100644 --- a/ceee/ie/testing/mock_broker_and_friends.h +++ b/ceee/ie/testing/mock_broker_and_friends.h @@ -272,6 +272,7 @@ class MockApiDispatcher : public ApiDispatcher { MOCK_METHOD3(GetExecutor, void(HWND, REFIID, void**)); MOCK_METHOD2(FireEvent, void(BSTR event_name, BSTR event_args)); + MOCK_CONST_METHOD1(IsTabIdValid, bool(int)); MOCK_CONST_METHOD1(GetTabHandleFromId, HWND(int)); MOCK_CONST_METHOD1(GetTabHandleFromToolBandId, HWND(int)); MOCK_CONST_METHOD1(GetWindowHandleFromId, HWND(int)); |