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

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

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ms release build 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/bookmark_api.h" 11 #include "chrome/browser/extensions/api/bookmarks/bookmarks_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::RemoveBookmarkFunction>(extension1_, 1); 89 FireBookmarksApiEvent<extensions::BookmarksRemoveFunction>(extension1_, 1);
90 FireBookmarksApiEvent<extensions::MoveBookmarkFunction>(extension1_, 1); 90 FireBookmarksApiEvent<extensions::BookmarksMoveFunction>(extension1_, 1);
91 FireBookmarksApiEvent<extensions::UpdateBookmarkFunction>(extension1_, 2); 91 FireBookmarksApiEvent<extensions::BookmarksUpdateFunction>(extension1_, 2);
92 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 3); 92 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 3);
93 FireBookmarksApiEvent<extensions::SearchBookmarksFunction>(extension1_, 5); 93 FireBookmarksApiEvent<extensions::BookmarksSearchFunction>(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::RemoveTreeBookmarkFunction>(extension2_, 8); 96 FireBookmarksApiEvent<extensions::BookmarksRemoveTreeFunction>(
97 FireBookmarksApiEvent<extensions::GetBookmarkTreeFunction>(extension2_, 13); 97 extension2_, 8);
98 FireBookmarksApiEvent<extensions::GetBookmarkChildrenFunction>( 98 FireBookmarksApiEvent<extensions::BookmarksGetSubTreeFunction>(
99 extension2_, 13);
100 FireBookmarksApiEvent<extensions::BookmarksGetChildrenFunction>(
99 extension2_, 21); 101 extension2_, 21);
100 FireBookmarksApiEvent<extensions::GetBookmarksFunction>(extension2_, 33); 102 FireBookmarksApiEvent<extensions::BookmarksGetTreeFunction>(extension2_, 33);
101 const uint32 writes_by_extension2 = 8; 103 const uint32 writes_by_extension2 = 8;
102 104
103 syncer::ExtensionsActivityMonitor::Records results; 105 syncer::ExtensionsActivityMonitor::Records results;
104 monitor_.GetAndClearRecords(&results); 106 monitor_.GetAndClearRecords(&results);
105 107
106 EXPECT_EQ(2U, results.size()); 108 EXPECT_EQ(2U, results.size());
107 EXPECT_TRUE(results.find(id1_) != results.end()); 109 EXPECT_TRUE(results.find(id1_) != results.end());
108 EXPECT_TRUE(results.find(id2_) != results.end()); 110 EXPECT_TRUE(results.find(id2_) != results.end());
109 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count); 111 EXPECT_EQ(writes_by_extension1, results[id1_].bookmark_write_count);
110 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count); 112 EXPECT_EQ(writes_by_extension2, results[id2_].bookmark_write_count);
111 } 113 }
112 114
113 // Fire some mutating bookmark API events with both extensions. Then 115 // Fire some mutating bookmark API events with both extensions. Then
114 // get the records, fire some more mutating and non-mutating events, 116 // get the records, fire some more mutating and non-mutating events,
115 // and put the old records back. Those should be merged with the new 117 // and put the old records back. Those should be merged with the new
116 // records correctly. 118 // records correctly.
117 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) { 119 TEST_F(SyncChromeExtensionsActivityMonitorTest, Put) {
118 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 5); 120 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 5);
119 FireBookmarksApiEvent<extensions::MoveBookmarkFunction>(extension2_, 8); 121 FireBookmarksApiEvent<extensions::BookmarksMoveFunction>(extension2_, 8);
120 122
121 syncer::ExtensionsActivityMonitor::Records results; 123 syncer::ExtensionsActivityMonitor::Records results;
122 monitor_.GetAndClearRecords(&results); 124 monitor_.GetAndClearRecords(&results);
123 125
124 EXPECT_EQ(2U, results.size()); 126 EXPECT_EQ(2U, results.size());
125 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 127 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
126 EXPECT_EQ(8U, results[id2_].bookmark_write_count); 128 EXPECT_EQ(8U, results[id2_].bookmark_write_count);
127 129
128 FireBookmarksApiEvent<extensions::GetBookmarksFunction>(extension2_, 3); 130 FireBookmarksApiEvent<extensions::BookmarksGetTreeFunction>(extension2_, 3);
129 FireBookmarksApiEvent<extensions::UpdateBookmarkFunction>(extension2_, 2); 131 FireBookmarksApiEvent<extensions::BookmarksUpdateFunction>(extension2_, 2);
130 132
131 // Simulate a commit failure, which augments the active record set with the 133 // Simulate a commit failure, which augments the active record set with the
132 // refugee records. 134 // refugee records.
133 monitor_.PutRecords(results); 135 monitor_.PutRecords(results);
134 syncer::ExtensionsActivityMonitor::Records new_records; 136 syncer::ExtensionsActivityMonitor::Records new_records;
135 monitor_.GetAndClearRecords(&new_records); 137 monitor_.GetAndClearRecords(&new_records);
136 138
137 EXPECT_EQ(2U, results.size()); 139 EXPECT_EQ(2U, results.size());
138 EXPECT_EQ(id1_, new_records[id1_].extension_id); 140 EXPECT_EQ(id1_, new_records[id1_].extension_id);
139 EXPECT_EQ(id2_, new_records[id2_].extension_id); 141 EXPECT_EQ(id2_, new_records[id2_].extension_id);
140 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count); 142 EXPECT_EQ(5U, new_records[id1_].bookmark_write_count);
141 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count); 143 EXPECT_EQ(8U + 2U, new_records[id2_].bookmark_write_count);
142 } 144 }
143 145
144 // Fire some mutating bookmark API events and get the records multiple 146 // Fire some mutating bookmark API events and get the records multiple
145 // times. The mintor should correctly clear its records every time 147 // times. The mintor should correctly clear its records every time
146 // they're returned. 148 // they're returned.
147 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) { 149 TEST_F(SyncChromeExtensionsActivityMonitorTest, MultiGet) {
148 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 5); 150 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 5);
149 151
150 syncer::ExtensionsActivityMonitor::Records results; 152 syncer::ExtensionsActivityMonitor::Records results;
151 monitor_.GetAndClearRecords(&results); 153 monitor_.GetAndClearRecords(&results);
152 154
153 EXPECT_EQ(1U, results.size()); 155 EXPECT_EQ(1U, results.size());
154 EXPECT_EQ(5U, results[id1_].bookmark_write_count); 156 EXPECT_EQ(5U, results[id1_].bookmark_write_count);
155 157
156 monitor_.GetAndClearRecords(&results); 158 monitor_.GetAndClearRecords(&results);
157 EXPECT_TRUE(results.empty()); 159 EXPECT_TRUE(results.empty());
158 160
159 FireBookmarksApiEvent<extensions::CreateBookmarkFunction>(extension1_, 3); 161 FireBookmarksApiEvent<extensions::BookmarksCreateFunction>(extension1_, 3);
160 monitor_.GetAndClearRecords(&results); 162 monitor_.GetAndClearRecords(&results);
161 163
162 EXPECT_EQ(1U, results.size()); 164 EXPECT_EQ(1U, results.size());
163 EXPECT_EQ(3U, results[id1_].bookmark_write_count); 165 EXPECT_EQ(3U, results[id1_].bookmark_write_count);
164 } 166 }
165 167
166 } // namespace 168 } // namespace
167 169
168 } // namespace browser_sync 170 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698