OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 10 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class MockSyncedWindowDelegate : public SyncedWindowDelegate { | 26 class MockSyncedWindowDelegate : public SyncedWindowDelegate { |
27 public: | 27 public: |
28 explicit MockSyncedWindowDelegate(Profile* profile) | 28 explicit MockSyncedWindowDelegate(Profile* profile) |
29 : is_restore_in_progress_(false), | 29 : is_restore_in_progress_(false), |
30 profile_(profile) {} | 30 profile_(profile) {} |
31 virtual ~MockSyncedWindowDelegate() {} | 31 virtual ~MockSyncedWindowDelegate() {} |
32 | 32 |
33 virtual bool HasWindow() const OVERRIDE { return false; } | 33 virtual bool HasWindow() const override { return false; } |
34 virtual SessionID::id_type GetSessionId() const OVERRIDE { return 0; } | 34 virtual SessionID::id_type GetSessionId() const override { return 0; } |
35 virtual int GetTabCount() const OVERRIDE { return 0; } | 35 virtual int GetTabCount() const override { return 0; } |
36 virtual int GetActiveIndex() const OVERRIDE { return 0; } | 36 virtual int GetActiveIndex() const override { return 0; } |
37 virtual bool IsApp() const OVERRIDE { return false; } | 37 virtual bool IsApp() const override { return false; } |
38 virtual bool IsTypeTabbed() const OVERRIDE { return false; } | 38 virtual bool IsTypeTabbed() const override { return false; } |
39 virtual bool IsTypePopup() const OVERRIDE { return false; } | 39 virtual bool IsTypePopup() const override { return false; } |
40 virtual bool IsTabPinned(const SyncedTabDelegate* tab) const OVERRIDE { | 40 virtual bool IsTabPinned(const SyncedTabDelegate* tab) const override { |
41 return false; | 41 return false; |
42 } | 42 } |
43 virtual SyncedTabDelegate* GetTabAt(int index) const OVERRIDE { return NULL; } | 43 virtual SyncedTabDelegate* GetTabAt(int index) const override { return NULL; } |
44 virtual SessionID::id_type GetTabIdAt(int index) const OVERRIDE { return 0; } | 44 virtual SessionID::id_type GetTabIdAt(int index) const override { return 0; } |
45 | 45 |
46 virtual bool IsSessionRestoreInProgress() const OVERRIDE { | 46 virtual bool IsSessionRestoreInProgress() const override { |
47 return is_restore_in_progress_; | 47 return is_restore_in_progress_; |
48 } | 48 } |
49 | 49 |
50 void SetSessionRestoreInProgress(bool is_restore_in_progress) { | 50 void SetSessionRestoreInProgress(bool is_restore_in_progress) { |
51 is_restore_in_progress_ = is_restore_in_progress; | 51 is_restore_in_progress_ = is_restore_in_progress; |
52 | 52 |
53 if (!is_restore_in_progress_) { | 53 if (!is_restore_in_progress_) { |
54 content::NotificationService::current()->Notify( | 54 content::NotificationService::current()->Notify( |
55 chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, | 55 chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, |
56 content::Source<Profile>(profile_), | 56 content::Source<Profile>(profile_), |
57 content::NotificationService::NoDetails()); | 57 content::NotificationService::NoDetails()); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 private: | 61 private: |
62 bool is_restore_in_progress_; | 62 bool is_restore_in_progress_; |
63 Profile* profile_; | 63 Profile* profile_; |
64 }; | 64 }; |
65 | 65 |
66 class MockSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { | 66 class MockSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { |
67 public: | 67 public: |
68 virtual const std::set<SyncedWindowDelegate*> | 68 virtual const std::set<SyncedWindowDelegate*> |
69 GetSyncedWindowDelegates() OVERRIDE { | 69 GetSyncedWindowDelegates() override { |
70 return delegates_; | 70 return delegates_; |
71 } | 71 } |
72 | 72 |
73 void Add(SyncedWindowDelegate* delegate) { | 73 void Add(SyncedWindowDelegate* delegate) { |
74 delegates_.insert(delegate); | 74 delegates_.insert(delegate); |
75 } | 75 } |
76 | 76 |
77 private: | 77 private: |
78 std::set<SyncedWindowDelegate*> delegates_; | 78 std::set<SyncedWindowDelegate*> delegates_; |
79 }; | 79 }; |
80 | 80 |
81 class SessionDataTypeControllerTest | 81 class SessionDataTypeControllerTest |
82 : public testing::Test { | 82 : public testing::Test { |
83 public: | 83 public: |
84 SessionDataTypeControllerTest() | 84 SessionDataTypeControllerTest() |
85 : load_finished_(false), | 85 : load_finished_(false), |
86 thread_bundle_(content::TestBrowserThreadBundle::DEFAULT), | 86 thread_bundle_(content::TestBrowserThreadBundle::DEFAULT), |
87 weak_ptr_factory_(this), | 87 weak_ptr_factory_(this), |
88 last_type_(syncer::UNSPECIFIED) {} | 88 last_type_(syncer::UNSPECIFIED) {} |
89 virtual ~SessionDataTypeControllerTest() {} | 89 virtual ~SessionDataTypeControllerTest() {} |
90 | 90 |
91 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() override { |
92 synced_window_delegate_.reset(new MockSyncedWindowDelegate(&profile_)); | 92 synced_window_delegate_.reset(new MockSyncedWindowDelegate(&profile_)); |
93 synced_window_getter_.reset(new MockSyncedWindowDelegatesGetter()); | 93 synced_window_getter_.reset(new MockSyncedWindowDelegatesGetter()); |
94 synced_window_getter_->Add(synced_window_delegate_.get()); | 94 synced_window_getter_->Add(synced_window_delegate_.get()); |
95 | 95 |
96 local_device_.reset(new LocalDeviceInfoProviderMock( | 96 local_device_.reset(new LocalDeviceInfoProviderMock( |
97 "cache_guid", | 97 "cache_guid", |
98 "Wayne Gretzky's Hacking Box", | 98 "Wayne Gretzky's Hacking Box", |
99 "Chromium 10k", | 99 "Chromium 10k", |
100 "Chrome 10k", | 100 "Chrome 10k", |
101 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 101 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
102 "device_id")); | 102 "device_id")); |
103 | 103 |
104 controller_ = new SessionDataTypeController( | 104 controller_ = new SessionDataTypeController( |
105 &profile_sync_factory_, | 105 &profile_sync_factory_, |
106 &profile_, | 106 &profile_, |
107 synced_window_getter_.get(), | 107 synced_window_getter_.get(), |
108 local_device_.get()); | 108 local_device_.get()); |
109 | 109 |
110 load_finished_ = false; | 110 load_finished_ = false; |
111 last_type_ = syncer::UNSPECIFIED; | 111 last_type_ = syncer::UNSPECIFIED; |
112 last_error_ = syncer::SyncError(); | 112 last_error_ = syncer::SyncError(); |
113 } | 113 } |
114 | 114 |
115 virtual void TearDown() OVERRIDE { | 115 virtual void TearDown() override { |
116 controller_ = NULL; | 116 controller_ = NULL; |
117 local_device_.reset(); | 117 local_device_.reset(); |
118 synced_window_getter_.reset(); | 118 synced_window_getter_.reset(); |
119 synced_window_delegate_.reset(); | 119 synced_window_delegate_.reset(); |
120 } | 120 } |
121 | 121 |
122 void Start() { | 122 void Start() { |
123 controller_->LoadModels( | 123 controller_->LoadModels( |
124 base::Bind(&SessionDataTypeControllerTest::OnLoadFinished, | 124 base::Bind(&SessionDataTypeControllerTest::OnLoadFinished, |
125 weak_ptr_factory_.GetWeakPtr())); | 125 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 local_device_->SetInitialized(true); | 238 local_device_->SetInitialized(true); |
239 EXPECT_EQ(sync_driver::DataTypeController::MODEL_LOADED, | 239 EXPECT_EQ(sync_driver::DataTypeController::MODEL_LOADED, |
240 controller_->state()); | 240 controller_->state()); |
241 EXPECT_TRUE(LoadResult()); | 241 EXPECT_TRUE(LoadResult()); |
242 } | 242 } |
243 | 243 |
244 } // namespace | 244 } // namespace |
245 | 245 |
246 } // namespace browser_sync | 246 } // namespace browser_sync |
OLD | NEW |