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 <utility> | 10 #include <utility> |
| 11 #include <vector> |
10 | 12 |
11 #include "embedder_test.h" | 13 #include "embedder_test.h" |
| 14 #include "test_support.h" |
12 | 15 |
13 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { | 16 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { |
14 public: | 17 public: |
| 18 struct ReceivedAlert { |
| 19 ReceivedAlert(FPDF_WIDESTRING message_in, |
| 20 FPDF_WIDESTRING title_in, |
| 21 int type_in, |
| 22 int icon_in) |
| 23 : type(type_in), icon(icon_in) { |
| 24 message = GetWideString(message_in); |
| 25 title = GetWideString(title_in); |
| 26 } |
| 27 |
| 28 std::wstring message; |
| 29 std::wstring title; |
| 30 int type; |
| 31 int icon; |
| 32 }; |
| 33 |
| 34 int Alert(FPDF_WIDESTRING message, |
| 35 FPDF_WIDESTRING title, |
| 36 int type, |
| 37 int icon) override { |
| 38 alerts_.push_back(ReceivedAlert(message, title, type, icon)); |
| 39 return 0; |
| 40 } |
| 41 |
15 int SetTimer(int msecs, TimerCallback fn) override { | 42 int SetTimer(int msecs, TimerCallback fn) override { |
16 expiry_to_timer_map_.insert(std::pair<int, Timer>( | 43 expiry_to_timer_map_.insert(std::pair<int, Timer>( |
17 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn))); | 44 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn))); |
18 return next_timer_id_; | 45 return next_timer_id_; |
19 } | 46 } |
20 | 47 |
21 void KillTimer(int id) override { | 48 void KillTimer(int id) override { |
22 for (auto iter = expiry_to_timer_map_.begin(); | 49 for (auto iter = expiry_to_timer_map_.begin(); |
23 iter != expiry_to_timer_map_.end(); ++iter) { | 50 iter != expiry_to_timer_map_.end(); ++iter) { |
24 if (iter->second.first == id) { | 51 if (iter->second.first == id) { |
(...skipping 12 matching lines...) Expand all Loading... |
37 } | 64 } |
38 Timer t = iter->second; | 65 Timer t = iter->second; |
39 if (t.first > imaginary_elapsed_msecs_) { | 66 if (t.first > imaginary_elapsed_msecs_) { |
40 break; | 67 break; |
41 } | 68 } |
42 expiry_to_timer_map_.erase(iter); | 69 expiry_to_timer_map_.erase(iter); |
43 t.second(t.first); // Fire timer. | 70 t.second(t.first); // Fire timer. |
44 } | 71 } |
45 } | 72 } |
46 | 73 |
| 74 const std::vector<ReceivedAlert>& GetAlerts() const { return alerts_; } |
| 75 |
47 protected: | 76 protected: |
48 using Timer = std::pair<int, TimerCallback>; // ID, callback pair. | 77 using Timer = std::pair<int, TimerCallback>; // ID, callback pair. |
49 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. | 78 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. |
50 int next_timer_id_ = 0; | 79 int next_timer_id_ = 0; |
51 int imaginary_elapsed_msecs_ = 0; | 80 int imaginary_elapsed_msecs_ = 0; |
| 81 std::vector<ReceivedAlert> alerts_; |
52 }; | 82 }; |
53 | 83 |
54 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 84 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
OLD | NEW |