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

Unified Diff: testing/embedder_test_timer_handling_delegate.h

Issue 1158483004: Merge to XFA: Automated test case for 487928. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Tidy after merge. Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/embedder_test_mock_delegate.h ('k') | testing/resources/bug_487928.in » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/embedder_test_timer_handling_delegate.h
diff --git a/testing/embedder_test_timer_handling_delegate.h b/testing/embedder_test_timer_handling_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..d05a134b4e14c08fc8570f4ac6c874fdadc9fffd
--- /dev/null
+++ b/testing/embedder_test_timer_handling_delegate.h
@@ -0,0 +1,54 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
+#define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
+
+#include <map>
+#include <utility>
+
+#include "embedder_test.h"
+
+class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate {
+public:
+ int SetTimer(int msecs, TimerCallback fn) override {
+ expiry_to_timer_map_.insert(std::pair<int, Timer>(
+ msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn)));
+ return next_timer_id_;
+ }
+
+ void KillTimer(int id) override {
+ for (auto iter = expiry_to_timer_map_.begin();
+ iter != expiry_to_timer_map_.end(); ++iter) {
+ if (iter->second.first == id) {
+ expiry_to_timer_map_.erase(iter);
+ break;
+ }
+ }
+ }
+
+ void AdvanceTime(int increment_msecs) {
+ imaginary_elapsed_msecs_ += increment_msecs;
+ while (1) {
+ auto iter = expiry_to_timer_map_.begin();
+ if (iter == expiry_to_timer_map_.end()) {
+ break;
+ }
+ Timer t = iter->second;
+ if (t.first > imaginary_elapsed_msecs_) {
+ break;
+ }
+ expiry_to_timer_map_.erase(iter);
+ t.second(t.first); // Fire timer.
+ }
+ }
+
+protected:
+ using Timer = std::pair<int, TimerCallback>; // ID, callback pair.
+ std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout.
+ int next_timer_id_ = 0;
+ int imaginary_elapsed_msecs_ = 0;
+};
+
+#endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
« no previous file with comments | « testing/embedder_test_mock_delegate.h ('k') | testing/resources/bug_487928.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698