OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "chrome/browser/undo/undo_manager.h" | 6 #include "chrome/browser/undo/undo_manager.h" |
7 #include "chrome/browser/undo/undo_manager_observer.h" | 7 #include "chrome/browser/undo/undo_manager_observer.h" |
8 #include "chrome/browser/undo/undo_operation.h" | 8 #include "chrome/browser/undo/undo_operation.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 int undo_operation_count_; | 30 int undo_operation_count_; |
31 int redo_operation_count_; | 31 int redo_operation_count_; |
32 }; | 32 }; |
33 | 33 |
34 // TestUndoOperation ----------------------------------------------------------- | 34 // TestUndoOperation ----------------------------------------------------------- |
35 | 35 |
36 class TestUndoOperation : public UndoOperation { | 36 class TestUndoOperation : public UndoOperation { |
37 public: | 37 public: |
38 explicit TestUndoOperation(TestUndoService* undo_service); | 38 explicit TestUndoOperation(TestUndoService* undo_service); |
39 virtual ~TestUndoOperation(); | 39 ~TestUndoOperation() override; |
40 | 40 |
41 // UndoOperation: | 41 // UndoOperation: |
42 virtual void Undo() override; | 42 void Undo() override; |
43 virtual int GetUndoLabelId() const override; | 43 int GetUndoLabelId() const override; |
44 virtual int GetRedoLabelId() const override; | 44 int GetRedoLabelId() const override; |
45 | 45 |
46 private: | 46 private: |
47 TestUndoService* undo_service_; | 47 TestUndoService* undo_service_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(TestUndoOperation); | 49 DISALLOW_COPY_AND_ASSIGN(TestUndoOperation); |
50 }; | 50 }; |
51 | 51 |
52 TestUndoOperation::TestUndoOperation(TestUndoService* undo_service) | 52 TestUndoOperation::TestUndoOperation(TestUndoService* undo_service) |
53 : undo_service_(undo_service) { | 53 : undo_service_(undo_service) { |
54 } | 54 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 // TestObserver ---------------------------------------------------------------- | 98 // TestObserver ---------------------------------------------------------------- |
99 | 99 |
100 class TestObserver : public UndoManagerObserver { | 100 class TestObserver : public UndoManagerObserver { |
101 public: | 101 public: |
102 TestObserver() : state_change_count_(0) {} | 102 TestObserver() : state_change_count_(0) {} |
103 // Returns the number of state change callbacks | 103 // Returns the number of state change callbacks |
104 int state_change_count() { return state_change_count_; } | 104 int state_change_count() { return state_change_count_; } |
105 | 105 |
106 virtual void OnUndoManagerStateChange() override { ++state_change_count_; } | 106 void OnUndoManagerStateChange() override { ++state_change_count_; } |
107 | 107 |
108 private: | 108 private: |
109 int state_change_count_; | 109 int state_change_count_; |
110 | 110 |
111 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 111 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
112 }; | 112 }; |
113 | 113 |
114 // Tests ----------------------------------------------------------------------- | 114 // Tests ----------------------------------------------------------------------- |
115 | 115 |
116 TEST(UndoServiceTest, AddUndoActions) { | 116 TEST(UndoServiceTest, AddUndoActions) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 undo_service.undo_manager_.Redo(); | 256 undo_service.undo_manager_.Redo(); |
257 int callback_count_after_redo = observer.state_change_count(); | 257 int callback_count_after_redo = observer.state_change_count(); |
258 EXPECT_GT(callback_count_after_redo, callback_count_after_undo); | 258 EXPECT_GT(callback_count_after_redo, callback_count_after_undo); |
259 | 259 |
260 undo_service.undo_manager_.RemoveObserver(&observer); | 260 undo_service.undo_manager_.RemoveObserver(&observer); |
261 undo_service.undo_manager_.Undo(); | 261 undo_service.undo_manager_.Undo(); |
262 EXPECT_EQ(callback_count_after_redo, observer.state_change_count()); | 262 EXPECT_EQ(callback_count_after_redo, observer.state_change_count()); |
263 } | 263 } |
264 | 264 |
265 } // namespace | 265 } // namespace |
OLD | NEW |