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

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

Issue 11826048: Revert 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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"
11 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" 11 #include "chrome/browser/extensions/api/bookmarks/bookmark_api.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_manifest_constants.h" 15 #include "chrome/common/extensions/extension_manifest_constants.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using extensions::Extension; 20 using extensions::Extension;
21 21
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // IDs of |extension{1,2}_|. 79 // IDs of |extension{1,2}_|.
80 const std::string& id1_; 80 const std::string& id1_;
81 const std::string& id2_; 81 const std::string& id2_;
82 }; 82 };
83 83
84 // Fire some mutating bookmark API events with extension 1, then fire 84 // Fire some mutating bookmark API events with extension 1, then fire
85 // some mutating and non-mutating bookmark API events with extension 85 // some mutating and non-mutating bookmark API events with extension
86 // 2. Only the mutating events should be recorded by the 86 // 2. Only the mutating events should be recorded by the
87 // syncer::ExtensionsActivityMonitor. 87 // syncer::ExtensionsActivityMonitor.
88 TEST_F(SyncChromeExtensionsActivityMonitorTest, Basic) { 88 TEST_F(SyncChromeExtensionsActivityMonitorTest, Basic) {
89 FireBookmarksApiEvent<extensions::BookmarksRemoveFunction>(extension1_, 1); 89 FireBookmarksApiEvent<extensions::RemoveBookmarkFunction>(extension1_, 1);
90 FireBookmarksApiEvent<extensions::BookmarksMoveFunction>(extension1_, 1); 90 FireBookmarksApiEvent<extensions::MoveBookmarkFunction>(extension1_, 1);
91 FireBookmarksApiEvent<extensions::BookmarksUpdateFunction>(extension1_, 2); 91 FireBookmarksApiEvent<extensions::UpdateBookmarkFunction>(extension1_, 2);
92 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 3); 92 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 3);
93 FireBookmarksApiEvent<extensions::BookmarksSearchFunction>(extension1_, 5); 93 FireBookmarksApiEvent<extensions::SearchBookmarksFunction>(extension1_, 5);
94 const uint32 writes_by_extension1 = 1 + 1 + 2 + 3; 94 const uint32 writes_by_extension1 = 1 + 1 + 2 + 3;
95 95
96 FireBookmarksApiEvent<extensions::BookmarksRemoveTreeFunction>( 96 FireBookmarksApiEvent<extensions::RemoveTreeBookmarkFunction>(extension2_, 8);
97 extension2_, 8); 97 FireBookmarksApiEvent<extensions::GetBookmarkTreeFunction>(extension2_, 13);
98 FireBookmarksApiEvent<extensions::BookmarksGetSubTreeFunction>( 98 FireBookmarksApiEvent<extensions::GetBookmarkChildrenFunction>(
99 extension2_, 13);
100 FireBookmarksApiEvent<extensions::BookmarksGetChildrenFunction>(
101 extension2_, 21); 99 extension2_, 21);
102 FireBookmarksApiEvent<extensions::BookmarksGetTreeFunction>(extension2_, 33); 100 FireBookmarksApiEvent<extensions::GetBookmarksFunction>(extension2_, 33);
103 const uint32 writes_by_extension2 = 8; 101 const uint32 writes_by_extension2 = 8;
104 102
105 syncer::ExtensionsActivityMonitor::Records results; 103 syncer::ExtensionsActivityMonitor::Records results;
106 monitor_.GetAndClearRecords(&results); 104 monitor_.GetAndClearRecords(&results);
107 105
108 EXPECT_EQ(2U, results.size()); 106 EXPECT_EQ(2U, results.size());
109 EXPECT_TRUE(results.find(id1_) != results.end()); 107 EXPECT_TRUE(results.find(id1_) != results.end());
110 EXPECT_TRUE(results.find(id2_) != results.end()); 108 EXPECT_TRUE(results.find(id2_) != results.end());
111 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count); 109 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count);
112 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count); 110 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count);
113 } 111 }
114 112
115 // Fire some mutating bookmark API events with both extensions. Then 113 // Fire some mutating bookmark API events with both extensions. Then
116 // get the records, fire some more mutating and non-mutating events, 114 // get the records, fire some more mutating and non-mutating events,
117 // and put the old records back. Those should be merged with the new 115 // and put the old records back. Those should be merged with the new
118 // records correctly. 116 // records correctly.
119 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) { 117 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) {
120 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 5); 118 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 5);
121 FireBookmarksApiEvent<extensions::BookmarksMoveFunction>(extension2_, 8); 119 FireBookmarksApiEvent<extensions::MoveBookmarkFunction>(extension2_, 8);
122 120
123 syncer::ExtensionsActivityMonitor::Records results; 121 syncer::ExtensionsActivityMonitor::Records results;
124 monitor_.GetAndClearRecords(&results); 122 monitor_.GetAndClearRecords(&results);
125 123
126 EXPECT_EQ(2U, results.size()); 124 EXPECT_EQ(2U, results.size());
127 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 125 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
128 EXPECT_EQ(8U, results[id2_].bookmark_write_count); 126 EXPECT_EQ(8U, results[id2_].bookmark_write_count);
129 127
130 FireBookmarksApiEvent<extensions::BookmarksGetTreeFunction>(extension2_, 3); 128 FireBookmarksApiEvent<extensions::GetBookmarksFunction>(extension2_, 3);
131 FireBookmarksApiEvent<extensions::BookmarksUpdateFunction>(extension2_, 2); 129 FireBookmarksApiEvent<extensions::UpdateBookmarkFunction>(extension2_, 2);
132 130
133 // Simulate a commit failure, which augments the active record set with the 131 // Simulate a commit failure, which augments the active record set with the
134 // refugee records. 132 // refugee records.
135 monitor_.PutRecords(results); 133 monitor_.PutRecords(results);
136 syncer::ExtensionsActivityMonitor::Records new_records; 134 syncer::ExtensionsActivityMonitor::Records new_records;
137 monitor_.GetAndClearRecords(&new_records); 135 monitor_.GetAndClearRecords(&new_records);
138 136
139 EXPECT_EQ(2U, results.size()); 137 EXPECT_EQ(2U, results.size());
140 EXPECT_EQ(id1_, new_records[id1_].extension_id); 138 EXPECT_EQ(id1_, new_records[id1_].extension_id);
141 EXPECT_EQ(id2_, new_records[id2_].extension_id); 139 EXPECT_EQ(id2_, new_records[id2_].extension_id);
142 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count); 140 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count);
143 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count); 141 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count);
144 } 142 }
145 143
146 // Fire some mutating bookmark API events and get the records multiple 144 // Fire some mutating bookmark API events and get the records multiple
147 // times. The mintor should correctly clear its records every time 145 // times. The mintor should correctly clear its records every time
148 // they're returned. 146 // they're returned.
149 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) { 147 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) {
150 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 5); 148 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 5);
151 149
152 syncer::ExtensionsActivityMonitor::Records results; 150 syncer::ExtensionsActivityMonitor::Records results;
153 monitor_.GetAndClearRecords(&results); 151 monitor_.GetAndClearRecords(&results);
154 152
155 EXPECT_EQ(1U, results.size()); 153 EXPECT_EQ(1U, results.size());
156 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 154 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
157 155
158 monitor_.GetAndClearRecords(&results); 156 monitor_.GetAndClearRecords(&results);
159 EXPECT_TRUE(results.empty()); 157 EXPECT_TRUE(results.empty());
160 158
161 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 3); 159 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 3);
162 monitor_.GetAndClearRecords(&results); 160 monitor_.GetAndClearRecords(&results);
163 161
164 EXPECT_EQ(1U, results.size()); 162 EXPECT_EQ(1U, results.size());
165 EXPECT_EQ(3U, results[id1_].bookmark_write_count); 163 EXPECT_EQ(3U, results[id1_].bookmark_write_count);
166 } 164 }
167 165
168 } // namespace 166 } // namespace
169 167
170 } // namespace browser_sync 168 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698