summaryrefslogtreecommitdiff
path: root/testing/embedder_test_timer_handling_delegate.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-06-02 16:51:07 -0700
committerTom Sepez <tsepez@chromium.org>2015-06-02 16:51:07 -0700
commita76f557650dfc95cae5f535d4a1b627a84d2b5f0 (patch)
tree40de9a298f1e02774dcb6cfb303d629bc97a7ec4 /testing/embedder_test_timer_handling_delegate.h
parentb29338d126125d96d63817af1d80a64ea929ffae (diff)
downloadpdfium-a76f557650dfc95cae5f535d4a1b627a84d2b5f0.tar.xz
Automated test case for 487928.
Reproducing this bug requires the embedder to fire timers, something the single-pass pdfium-test binary doesn't do properly at the present. So we modify the embedder test delegate to allow the immediate triggering of the same. Perform some cleanup along the way by removing EmbedderTestDefaultDelegate -- it buys us nothing over the the no-op one. And, of course, v8 initialization is busted again, and we need v8 here. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1153213004
Diffstat (limited to 'testing/embedder_test_timer_handling_delegate.h')
-rw-r--r--testing/embedder_test_timer_handling_delegate.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/testing/embedder_test_timer_handling_delegate.h b/testing/embedder_test_timer_handling_delegate.h
new file mode 100644
index 0000000000..d05a134b4e
--- /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_