Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/sync/glue/chrome_extensions_activity_monitor_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h" 5 #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 scoped_refptr<Extension> extension1_; 76 scoped_refptr<Extension> extension1_;
77 scoped_refptr<Extension> extension2_; 77 scoped_refptr<Extension> extension2_;
78 // IDs of |extension{1,2}_|. 78 // IDs of |extension{1,2}_|.
79 const std::string& id1_; 79 const std::string& id1_;
80 const std::string& id2_; 80 const std::string& id2_;
81 }; 81 };
82 82
83 // Fire some mutating bookmark API events with extension 1, then fire 83 // Fire some mutating bookmark API events with extension 1, then fire
84 // some mutating and non-mutating bookmark API events with extension 84 // some mutating and non-mutating bookmark API events with extension
85 // 2. Only the mutating events should be recorded by the 85 // 2. Only the mutating events should be recorded by the
86 // csync::ExtensionsActivityMonitor. 86 // syncer::ExtensionsActivityMonitor.
87 TEST_F(SyncChromeExtensionsActivityMonitorTest, Basic) { 87 TEST_F(SyncChromeExtensionsActivityMonitorTest, Basic) {
88 FireBookmarksApiEvent<RemoveBookmarkFunction>(extension1_, 1); 88 FireBookmarksApiEvent<RemoveBookmarkFunction>(extension1_, 1);
89 FireBookmarksApiEvent<MoveBookmarkFunction>(extension1_, 1); 89 FireBookmarksApiEvent<MoveBookmarkFunction>(extension1_, 1);
90 FireBookmarksApiEvent<UpdateBookmarkFunction>(extension1_, 2); 90 FireBookmarksApiEvent<UpdateBookmarkFunction>(extension1_, 2);
91 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 3); 91 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 3);
92 FireBookmarksApiEvent<SearchBookmarksFunction>(extension1_, 5); 92 FireBookmarksApiEvent<SearchBookmarksFunction>(extension1_, 5);
93 const uint32 writes_by_extension1 = 1 + 1 + 2 + 3; 93 const uint32 writes_by_extension1 = 1 + 1 + 2 + 3;
94 94
95 FireBookmarksApiEvent<RemoveTreeBookmarkFunction>(extension2_, 8); 95 FireBookmarksApiEvent<RemoveTreeBookmarkFunction>(extension2_, 8);
96 FireBookmarksApiEvent<GetBookmarkTreeFunction>(extension2_, 13); 96 FireBookmarksApiEvent<GetBookmarkTreeFunction>(extension2_, 13);
97 FireBookmarksApiEvent<GetBookmarkChildrenFunction>(extension2_, 21); 97 FireBookmarksApiEvent<GetBookmarkChildrenFunction>(extension2_, 21);
98 FireBookmarksApiEvent<GetBookmarksFunction>(extension2_, 33); 98 FireBookmarksApiEvent<GetBookmarksFunction>(extension2_, 33);
99 const uint32 writes_by_extension2 = 8; 99 const uint32 writes_by_extension2 = 8;
100 100
101 csync::ExtensionsActivityMonitor::Records results; 101 syncer::ExtensionsActivityMonitor::Records results;
102 monitor_.GetAndClearRecords(&results); 102 monitor_.GetAndClearRecords(&results);
103 103
104 EXPECT_EQ(2U, results.size()); 104 EXPECT_EQ(2U, results.size());
105 EXPECT_TRUE(results.find(id1_) != results.end()); 105 EXPECT_TRUE(results.find(id1_) != results.end());
106 EXPECT_TRUE(results.find(id2_) != results.end()); 106 EXPECT_TRUE(results.find(id2_) != results.end());
107 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count); 107 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count);
108 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count); 108 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count);
109 } 109 }
110 110
111 // Fire some mutating bookmark API events with both extensions. Then 111 // Fire some mutating bookmark API events with both extensions. Then
112 // get the records, fire some more mutating and non-mutating events, 112 // get the records, fire some more mutating and non-mutating events,
113 // and put the old records back. Those should be merged with the new 113 // and put the old records back. Those should be merged with the new
114 // records correctly. 114 // records correctly.
115 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) { 115 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) {
116 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 5); 116 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 5);
117 FireBookmarksApiEvent<MoveBookmarkFunction>(extension2_, 8); 117 FireBookmarksApiEvent<MoveBookmarkFunction>(extension2_, 8);
118 118
119 csync::ExtensionsActivityMonitor::Records results; 119 syncer::ExtensionsActivityMonitor::Records results;
120 monitor_.GetAndClearRecords(&results); 120 monitor_.GetAndClearRecords(&results);
121 121
122 EXPECT_EQ(2U, results.size()); 122 EXPECT_EQ(2U, results.size());
123 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 123 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
124 EXPECT_EQ(8U, results[id2_].bookmark_write_count); 124 EXPECT_EQ(8U, results[id2_].bookmark_write_count);
125 125
126 FireBookmarksApiEvent<GetBookmarksFunction>(extension2_, 3); 126 FireBookmarksApiEvent<GetBookmarksFunction>(extension2_, 3);
127 FireBookmarksApiEvent<UpdateBookmarkFunction>(extension2_, 2); 127 FireBookmarksApiEvent<UpdateBookmarkFunction>(extension2_, 2);
128 128
129 // Simulate a commit failure, which augments the active record set with the 129 // Simulate a commit failure, which augments the active record set with the
130 // refugee records. 130 // refugee records.
131 monitor_.PutRecords(results); 131 monitor_.PutRecords(results);
132 csync::ExtensionsActivityMonitor::Records new_records; 132 syncer::ExtensionsActivityMonitor::Records new_records;
133 monitor_.GetAndClearRecords(&new_records); 133 monitor_.GetAndClearRecords(&new_records);
134 134
135 EXPECT_EQ(2U, results.size()); 135 EXPECT_EQ(2U, results.size());
136 EXPECT_EQ(id1_, new_records[id1_].extension_id); 136 EXPECT_EQ(id1_, new_records[id1_].extension_id);
137 EXPECT_EQ(id2_, new_records[id2_].extension_id); 137 EXPECT_EQ(id2_, new_records[id2_].extension_id);
138 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count); 138 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count);
139 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count); 139 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count);
140 } 140 }
141 141
142 // Fire some mutating bookmark API events and get the records multiple 142 // Fire some mutating bookmark API events and get the records multiple
143 // times. The mintor should correctly clear its records every time 143 // times. The mintor should correctly clear its records every time
144 // they're returned. 144 // they're returned.
145 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) { 145 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) {
146 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 5); 146 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 5);
147 147
148 csync::ExtensionsActivityMonitor::Records results; 148 syncer::ExtensionsActivityMonitor::Records results;
149 monitor_.GetAndClearRecords(&results); 149 monitor_.GetAndClearRecords(&results);
150 150
151 EXPECT_EQ(1U, results.size()); 151 EXPECT_EQ(1U, results.size());
152 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 152 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
153 153
154 monitor_.GetAndClearRecords(&results); 154 monitor_.GetAndClearRecords(&results);
155 EXPECT_TRUE(results.empty()); 155 EXPECT_TRUE(results.empty());
156 156
157 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 3); 157 FireBookmarksApiEvent<CreateBookmarkFunction>(extension1_, 3);
158 monitor_.GetAndClearRecords(&results); 158 monitor_.GetAndClearRecords(&results);
159 159
160 EXPECT_EQ(1U, results.size()); 160 EXPECT_EQ(1U, results.size());
161 EXPECT_EQ(3U, results[id1_].bookmark_write_count); 161 EXPECT_EQ(3U, results[id1_].bookmark_write_count);
162 } 162 }
163 163
164 } // namespace 164 } // namespace
165 165
166 } // namespace browser_sync 166 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698