1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_TEST_PLUGIN_PLUGIN_SCHEDULE_TIMER_TEST_H 6 #define CONTENT_TEST_PLUGIN_PLUGIN_SCHEDULE_TIMER_TEST_H 7 8 #include "base/compiler_specific.h" 9 #include "base/time/time.h" 10 #include "content/test/plugin/plugin_test.h" 11 12 namespace NPAPIClient { 13 14 // This class tests scheduling and unscheduling of timers using 15 // NPN_ScheduleTimer and NPN_UnscheduleTimer. 16 class ScheduleTimerTest : public PluginTest { 17 public: 18 ScheduleTimerTest(NPP id, NPNetscapeFuncs *host_functions); 19 20 virtual NPError New(uint16 mode, int16 argc, const char* argn[], 21 const char* argv[], NPSavedData* saved) OVERRIDE; 22 23 void OnTimer(uint32 timer_id); 24 25 private: 26 // Table mapping timer index (as used in event schedule) to timer id. 27 static const int kNumTimers = 3; 28 uint32 timer_ids_[kNumTimers]; 29 30 // Schedule of events for test. 31 static const int kNumEvents = 11; 32 struct Event { 33 int time; 34 35 // The index of the timer that triggered the event or -1 for the first 36 // event. 37 int received_index; 38 39 // The index of the timer to schedule on this event or -1. 40 int scheduled_index; 41 42 // Info about the timer to be scheduled (if any). 43 uint32 scheduled_interval; 44 bool schedule_repeated; 45 46 // The index of the timer to unschedule on this event or -1. 47 int unscheduled_index; 48 }; 49 static Event schedule_[kNumEvents]; 50 int num_received_events_; 51 52 // Set of events that have been received (by index). 53 bool received_events_[kNumEvents]; 54 55 // Time of initial event. 56 base::Time start_time_; 57 58 // Returns index of matching unreceived event or -1 if not found. 59 int FindUnreceivedEvent(int time, uint32 timer_id); 60 void HandleEventIndex(int event_index); 61 }; 62 63 } // namespace NPAPIClient 64 65 #endif // CONTENT_TEST_PLUGIN_PLUGIN_SCHEDULE_TIMER_TEST_H 66