Cancel on-going scan when change directory is requested.
[chromium-blink-merge.git] / components / invalidation / invalidation_notifier_unittest.cc
blob0c5df39a07aad349a614c33a2b2321ddc410a738
1 // Copyright 2014 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.
5 #include "components/invalidation/invalidation_notifier.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/invalidation/fake_invalidation_handler.h"
10 #include "components/invalidation/fake_invalidation_state_tracker.h"
11 #include "components/invalidation/invalidation_state_tracker.h"
12 #include "components/invalidation/invalidator_test_template.h"
13 #include "components/invalidation/push_client_channel.h"
14 #include "jingle/notifier/base/fake_base_task.h"
15 #include "jingle/notifier/base/notifier_options.h"
16 #include "jingle/notifier/listener/fake_push_client.h"
17 #include "net/url_request/url_request_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace syncer {
22 namespace {
24 class InvalidationNotifierTestDelegate {
25 public:
26 InvalidationNotifierTestDelegate() {}
28 ~InvalidationNotifierTestDelegate() {
29 DestroyInvalidator();
32 void CreateInvalidator(
33 const std::string& invalidator_client_id,
34 const std::string& initial_state,
35 const base::WeakPtr<InvalidationStateTracker>&
36 invalidation_state_tracker) {
37 DCHECK(!invalidator_.get());
38 scoped_ptr<notifier::PushClient> push_client(
39 new notifier::FakePushClient());
40 scoped_ptr<SyncNetworkChannel> network_channel(
41 new PushClientChannel(push_client.Pass()));
42 invalidator_.reset(
43 new InvalidationNotifier(network_channel.Pass(),
44 invalidator_client_id,
45 UnackedInvalidationsMap(),
46 initial_state,
47 invalidation_state_tracker,
48 base::MessageLoopProxy::current(),
49 "fake_client_info"));
52 Invalidator* GetInvalidator() {
53 return invalidator_.get();
56 void DestroyInvalidator() {
57 // Stopping the invalidation notifier stops its scheduler, which deletes
58 // any pending tasks without running them. Some tasks "run and delete"
59 // another task, so they must be run in order to avoid leaking the inner
60 // task. Stopping does not schedule any tasks, so it's both necessary and
61 // sufficient to drain the task queue before stopping the notifier.
62 message_loop_.RunUntilIdle();
63 invalidator_.reset();
66 void WaitForInvalidator() {
67 message_loop_.RunUntilIdle();
70 void TriggerOnInvalidatorStateChange(InvalidatorState state) {
71 invalidator_->OnInvalidatorStateChange(state);
74 void TriggerOnIncomingInvalidation(
75 const ObjectIdInvalidationMap& invalidation_map) {
76 invalidator_->OnInvalidate(invalidation_map);
79 private:
80 base::MessageLoop message_loop_;
81 scoped_ptr<InvalidationNotifier> invalidator_;
84 INSTANTIATE_TYPED_TEST_CASE_P(
85 InvalidationNotifierTest, InvalidatorTest,
86 InvalidationNotifierTestDelegate);
88 } // namespace
90 } // namespace syncer