OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium 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 #ifndef TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 5 #ifndef TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
6 #define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 6 #define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 20 matching lines...) Expand all Loading... |
31 int Alert(FPDF_WIDESTRING message, | 31 int Alert(FPDF_WIDESTRING message, |
32 FPDF_WIDESTRING title, | 32 FPDF_WIDESTRING title, |
33 int type, | 33 int type, |
34 int icon) override { | 34 int icon) override { |
35 alerts_.push_back( | 35 alerts_.push_back( |
36 {GetPlatformWString(message), GetPlatformWString(title), type, icon}); | 36 {GetPlatformWString(message), GetPlatformWString(title), type, icon}); |
37 return 0; | 37 return 0; |
38 } | 38 } |
39 | 39 |
40 int SetTimer(int msecs, TimerCallback fn) override { | 40 int SetTimer(int msecs, TimerCallback fn) override { |
41 expiry_to_timer_map_.insert(std::pair<int, Timer>( | 41 int id = fail_next_timer_ ? 0 : ++next_timer_id_; |
42 msecs + fake_elapsed_msecs_, {++next_timer_id_, msecs, fn})); | 42 expiry_to_timer_map_.insert( |
43 return next_timer_id_; | 43 std::pair<int, Timer>(msecs + fake_elapsed_msecs_, {id, msecs, fn})); |
| 44 fail_next_timer_ = false; |
| 45 return id; |
44 } | 46 } |
45 | 47 |
46 void KillTimer(int id) override { | 48 void KillTimer(int id) override { |
47 for (auto iter = expiry_to_timer_map_.begin(); | 49 for (auto iter = expiry_to_timer_map_.begin(); |
48 iter != expiry_to_timer_map_.end(); ++iter) { | 50 iter != expiry_to_timer_map_.end(); ++iter) { |
49 if (iter->second.id == id) { | 51 if (iter->second.id == id) { |
50 expiry_to_timer_map_.erase(iter); | 52 expiry_to_timer_map_.erase(iter); |
51 break; | 53 break; |
52 } | 54 } |
53 } | 55 } |
(...skipping 12 matching lines...) Expand all Loading... |
66 Timer t = iter->second; | 68 Timer t = iter->second; |
67 expiry_to_timer_map_.erase(iter); | 69 expiry_to_timer_map_.erase(iter); |
68 expiry_to_timer_map_.insert( | 70 expiry_to_timer_map_.insert( |
69 std::pair<int, Timer>(fake_elapsed_msecs_ + t.interval, t)); | 71 std::pair<int, Timer>(fake_elapsed_msecs_ + t.interval, t)); |
70 t.fn(t.id); // Fire timer. | 72 t.fn(t.id); // Fire timer. |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
74 const std::vector<AlertRecord>& GetAlerts() const { return alerts_; } | 76 const std::vector<AlertRecord>& GetAlerts() const { return alerts_; } |
75 | 77 |
| 78 void SetFailNextTimer() { fail_next_timer_ = true; } |
| 79 |
76 protected: | 80 protected: |
77 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. | 81 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. |
| 82 bool fail_next_timer_ = false; |
78 int next_timer_id_ = 0; | 83 int next_timer_id_ = 0; |
79 int fake_elapsed_msecs_ = 0; | 84 int fake_elapsed_msecs_ = 0; |
80 std::vector<AlertRecord> alerts_; | 85 std::vector<AlertRecord> alerts_; |
81 }; | 86 }; |
82 | 87 |
83 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 88 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
OLD | NEW |