Chromium Code Reviews| Index: components/undo/undo_manager_test.cc |
| diff --git a/components/undo/undo_manager_test.cc b/components/undo/undo_manager_test.cc |
| index eea15985faba36256d53fbfd6007254b66cda3fb..03dc138b711cfcdcd52ff85609b688d3f1513609 100644 |
| --- a/components/undo/undo_manager_test.cc |
| +++ b/components/undo/undo_manager_test.cc |
| @@ -13,6 +13,53 @@ |
| namespace { |
| +std::vector<UndoOperation*> ConvertToRawPtrVector( |
| + const std::vector<std::unique_ptr<UndoOperation>>& args) { |
| + std::vector<UndoOperation*> args_rawptrs; |
| + for (auto i = args.begin(); i != args.end(); ++i) |
| + args_rawptrs.push_back(i->get()); |
| + return args_rawptrs; |
| +} |
| + |
| +} // namespace |
| + |
| +// UndoManagerTestApi ---------------------------------------------------------- |
| + |
| +class UndoManagerTestApi { |
| + public: |
| + // Returns all UndoOperations that are awaiting Undo or Redo. |
| + static std::vector<UndoOperation*> GetAllUndoOperations( |
| + const UndoManager& undo_manager); |
| +}; |
|
sky
2017/01/24 18:15:52
private: DISALLOW_IMPLICIT_CONSTRUCTORS
ke.he
2017/01/25 15:03:51
Done.
|
| + |
| +std::vector<UndoOperation*> UndoManagerTestApi::GetAllUndoOperations( |
| + const UndoManager& undo_manager) { |
| + std::vector<UndoOperation*> result; |
| + for (size_t i = 0; i < undo_manager.undo_actions_.size(); ++i) { |
| + const std::vector<UndoOperation*> operations = |
| + ConvertToRawPtrVector(undo_manager.undo_actions_[i]->undo_operations()); |
| + result.insert(result.end(), operations.begin(), operations.end()); |
| + } |
| + for (size_t i = 0; i < undo_manager.redo_actions_.size(); ++i) { |
| + const std::vector<UndoOperation*> operations = |
| + ConvertToRawPtrVector(undo_manager.redo_actions_[i]->undo_operations()); |
| + result.insert(result.end(), operations.begin(), operations.end()); |
| + } |
| + // Ensure that if an Undo is in progress the UndoOperations part of that |
| + // UndoGroup are included in the returned set. This will ensure that any |
| + // changes (such as renumbering) will be applied to any potentially |
| + // unprocessed UndoOperations. |
| + if (undo_manager.undo_in_progress_action_) { |
| + const std::vector<UndoOperation*> operations = ConvertToRawPtrVector( |
| + undo_manager.undo_in_progress_action_->undo_operations()); |
| + result.insert(result.end(), operations.begin(), operations.end()); |
| + } |
| + |
| + return result; |
| +} |
| + |
| +namespace { |
| + |
| class TestUndoOperation; |
| // TestUndoService ------------------------------------------------------------- |
| @@ -231,7 +278,7 @@ TEST(UndoServiceTest, GetAllUndoOperations) { |
| ASSERT_EQ(1U, undo_service.undo_manager_.redo_count()); |
| std::vector<UndoOperation*> all_operations = |
| - undo_service.undo_manager_.GetAllUndoOperations(); |
| + UndoManagerTestApi::GetAllUndoOperations(undo_service.undo_manager_); |
| EXPECT_EQ(4U, all_operations.size()); |
| } |