Home | History | Annotate | Download | only in invalidation
      1 // Copyright (c) 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 #include "chrome/browser/invalidation/invalidation_service_android.h"
      6 
      7 #include "chrome/browser/chrome_notification_types.h"
      8 #include "chrome/browser/invalidation/invalidation_service_factory.h"
      9 #include "chrome/browser/invalidation/invalidation_service_test_template.h"
     10 #include "chrome/test/base/testing_profile.h"
     11 #include "content/public/browser/notification_service.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 namespace invalidation {
     15 
     16 class InvalidationServiceAndroidTestDelegate {
     17  public:
     18   InvalidationServiceAndroidTestDelegate() { }
     19 
     20   ~InvalidationServiceAndroidTestDelegate() {
     21     DestroyInvalidationService();
     22   }
     23 
     24   void CreateInvalidationService() {
     25     profile_.reset(new TestingProfile());
     26     invalidation_service_android_.reset(
     27         new InvalidationServiceAndroid(profile_.get()));
     28   }
     29 
     30   InvalidationService* GetInvalidationService() {
     31     return invalidation_service_android_.get();
     32   }
     33 
     34   void DestroyInvalidationService() {
     35     invalidation_service_android_->Shutdown();
     36   }
     37 
     38   void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) {
     39     invalidation_service_android_->TriggerStateChangeForTest(state);
     40   }
     41 
     42   void TriggerOnIncomingInvalidation(
     43       const syncer::ObjectIdInvalidationMap& invalidation_map) {
     44     content::NotificationService::current()->Notify(
     45         chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
     46         content::Source<Profile>(profile_.get()),
     47         content::Details<const syncer::ObjectIdInvalidationMap>(
     48             &invalidation_map));
     49   }
     50 
     51   scoped_ptr<TestingProfile> profile_;
     52   scoped_ptr<InvalidationServiceAndroid> invalidation_service_android_;
     53 };
     54 
     55 INSTANTIATE_TYPED_TEST_CASE_P(
     56     AndroidInvalidationServiceTest, InvalidationServiceTest,
     57     InvalidationServiceAndroidTestDelegate);
     58 
     59 }  // namespace invalidation
     60