Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: testing/embedder_test_timer_handling_delegate.h

Issue 1424743006: Make JS app.setTimeOut() work again. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samples/pdfium_test.cc ('k') | testing/resources/bug_551248.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 9 #include <utility>
10 #include <vector>
10 11
11 #include "embedder_test.h" 12 #include "embedder_test.h"
12 13
13 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { 14 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate {
14 public: 15 public:
16 struct ReceivedAlert {
17 ReceivedAlert(FPDF_WIDESTRING message_in,
18 FPDF_WIDESTRING title_in,
19 int type_in,
20 int icon_in)
21 : message(message_in), title(title_in), type(type_in), icon(icon_in) {}
22
23 FPDF_WIDESTRING message;
Tom Sepez 2015/11/04 23:01:11 maybe make these the std::wstrings() so the copy h
24 FPDF_WIDESTRING title;
25 int type;
26 int icon;
27 };
28
29 int Alert(FPDF_WIDESTRING message,
30 FPDF_WIDESTRING title,
31 int type,
32 int icon) override {
33 alerts_.push_back(ReceivedAlert(message, title, type, icon));
34 return 0;
35 }
36
15 int SetTimer(int msecs, TimerCallback fn) override { 37 int SetTimer(int msecs, TimerCallback fn) override {
16 expiry_to_timer_map_.insert(std::pair<int, Timer>( 38 expiry_to_timer_map_.insert(std::pair<int, Timer>(
17 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn))); 39 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn)));
18 return next_timer_id_; 40 return next_timer_id_;
19 } 41 }
20 42
21 void KillTimer(int id) override { 43 void KillTimer(int id) override {
22 for (auto iter = expiry_to_timer_map_.begin(); 44 for (auto iter = expiry_to_timer_map_.begin();
23 iter != expiry_to_timer_map_.end(); ++iter) { 45 iter != expiry_to_timer_map_.end(); ++iter) {
24 if (iter->second.first == id) { 46 if (iter->second.first == id) {
(...skipping 12 matching lines...) Expand all
37 } 59 }
38 Timer t = iter->second; 60 Timer t = iter->second;
39 if (t.first > imaginary_elapsed_msecs_) { 61 if (t.first > imaginary_elapsed_msecs_) {
40 break; 62 break;
41 } 63 }
42 expiry_to_timer_map_.erase(iter); 64 expiry_to_timer_map_.erase(iter);
43 t.second(t.first); // Fire timer. 65 t.second(t.first); // Fire timer.
44 } 66 }
45 } 67 }
46 68
69 const std::vector<ReceivedAlert>& GetAlerts() const { return alerts_; }
70
47 protected: 71 protected:
48 using Timer = std::pair<int, TimerCallback>; // ID, callback pair. 72 using Timer = std::pair<int, TimerCallback>; // ID, callback pair.
49 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. 73 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout.
50 int next_timer_id_ = 0; 74 int next_timer_id_ = 0;
51 int imaginary_elapsed_msecs_ = 0; 75 int imaginary_elapsed_msecs_ = 0;
76 std::vector<ReceivedAlert> alerts_;
52 }; 77 };
53 78
54 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ 79 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
OLDNEW
« no previous file with comments | « samples/pdfium_test.cc ('k') | testing/resources/bug_551248.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698