Home | History | Annotate | Download | only in notifier
      1 // Copyright 2013 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 SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_
      6 #define SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "sync/base/sync_export.h"
     13 #include "sync/internal_api/public/util/weak_handle.h"
     14 #include "sync/notifier/ack_handler.h"
     15 
     16 namespace syncer {
     17 
     18 class Invalidation;
     19 
     20 // This AckHandler implementation colaborates with the FakeInvalidationService
     21 // to enable unit tests to assert that invalidations are being acked properly.
     22 class SYNC_EXPORT MockAckHandler
     23   : public AckHandler,
     24     public base::SupportsWeakPtr<MockAckHandler> {
     25  public:
     26   MockAckHandler();
     27   virtual ~MockAckHandler();
     28 
     29   // Sets up some internal state to track this invalidation, and modifies it so
     30   // that its Acknowledge() and Drop() methods will route back to us.
     31   void RegisterInvalidation(Invalidation* invalidation);
     32 
     33   // No one was listening for this invalidation, so no one will receive it or
     34   // ack it.  We keep track of it anyway to let tests make assertions about it.
     35   void RegisterUnsentInvalidation(Invalidation* invalidation);
     36 
     37   // Returns true if the specified invalidaition has been delivered, but has not
     38   // been acknowledged yet.
     39   bool IsUnacked(const Invalidation& invalidation) const;
     40 
     41   // Returns true if the specified invalidation was never delivered.
     42   bool IsUnsent(const Invalidation& invalidation) const;
     43 
     44   // Implementation of AckHandler.
     45   virtual void Acknowledge(
     46       const invalidation::ObjectId& id,
     47       const AckHandle& handle) OVERRIDE;
     48   virtual void Drop(
     49       const invalidation::ObjectId& id,
     50       const AckHandle& handle) OVERRIDE;
     51 
     52  private:
     53   typedef std::vector<syncer::Invalidation> InvalidationVector;
     54 
     55   WeakHandle<AckHandler> WeakHandleThis();
     56 
     57   InvalidationVector unsent_invalidations_;
     58   InvalidationVector unacked_invalidations_;
     59   InvalidationVector acked_invalidations_;
     60 };
     61 
     62 }  // namespace syncer
     63 
     64 #endif  // SYNC_NOTIFIER_MOCK_ACK_HANDLER_H_
     65