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

Side by Side Diff: chrome/browser/sync/test/integration/sync_app_list_helper.cc

Issue 148403007: Protect AppListItemList Add/Remove and fix sync bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/integration/sync_app_list_helper.h" 5 #include "chrome/browser/sync/test/integration/sync_app_list_helper.h"
6 6
7 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h" 12 #include "chrome/browser/sync/test/integration/sync_test.h"
12 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" 13 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
13 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 14 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
14 #include "chrome/common/extensions/sync_helper.h" 15 #include "chrome/common/extensions/sync_helper.h"
16 #include "ui/app_list/app_list_folder_item.h"
15 #include "ui/app_list/app_list_item.h" 17 #include "ui/app_list/app_list_item.h"
16 #include "ui/app_list/app_list_model.h" 18 #include "ui/app_list/app_list_model.h"
17 19
20 using app_list::AppListFolderItem;
21 using app_list::AppListItem;
18 using app_list::AppListItemList; 22 using app_list::AppListItemList;
19 using app_list::AppListItem;
20 using app_list::AppListSyncableService; 23 using app_list::AppListSyncableService;
21 using app_list::AppListSyncableServiceFactory; 24 using app_list::AppListSyncableServiceFactory;
22 25
23 SyncAppListHelper* SyncAppListHelper::GetInstance() { 26 SyncAppListHelper* SyncAppListHelper::GetInstance() {
24 SyncAppListHelper* instance = Singleton<SyncAppListHelper>::get(); 27 SyncAppListHelper* instance = Singleton<SyncAppListHelper>::get();
25 instance->SetupIfNecessary(sync_datatype_helper::test()); 28 instance->SetupIfNecessary(sync_datatype_helper::test());
26 return instance; 29 return instance;
27 } 30 }
28 31
29 SyncAppListHelper::SyncAppListHelper() : test_(NULL), setup_completed_(false) { 32 SyncAppListHelper::SyncAppListHelper() : test_(NULL), setup_completed_(false) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 bool SyncAppListHelper::AllProfilesHaveSameAppListAsVerifier() { 94 bool SyncAppListHelper::AllProfilesHaveSameAppListAsVerifier() {
92 bool res = true; 95 bool res = true;
93 for (int i = 0; i < test_->num_clients(); ++i) { 96 for (int i = 0; i < test_->num_clients(); ++i) {
94 if (!AppListMatchesVerifier(test_->GetProfile(i))) { 97 if (!AppListMatchesVerifier(test_->GetProfile(i))) {
95 LOG(ERROR) << "Profile " << i 98 LOG(ERROR) << "Profile " << i
96 << " doesn't have the same app list as the verifier profile."; 99 << " doesn't have the same app list as the verifier profile.";
97 res = false; 100 res = false;
98 } 101 }
99 } 102 }
100 if (!res) { 103 if (!res) {
101 VLOG(1) << "Verifier:"; 104 Profile* verifier = test_->verifier();
105 VLOG(1) << "Verifier: "
106 << AppListSyncableServiceFactory::GetForProfile(verifier);
102 PrintAppList(test_->verifier()); 107 PrintAppList(test_->verifier());
103 for (int i = 0; i < test_->num_clients(); ++i) { 108 for (int i = 0; i < test_->num_clients(); ++i) {
104 VLOG(1) << "Profile: " << i; 109 Profile* profile = test_->GetProfile(i);
105 PrintAppList(test_->GetProfile(i)); 110 VLOG(1) << "Profile: " << i << ": "
111 << AppListSyncableServiceFactory::GetForProfile(profile);
112 PrintAppList(profile);
106 } 113 }
107 } 114 }
108 return res; 115 return res;
109 } 116 }
110 117
111 void SyncAppListHelper::MoveApp(Profile* profile, size_t from, size_t to) { 118 void SyncAppListHelper::MoveApp(Profile* profile, size_t from, size_t to) {
112 AppListSyncableService* service = 119 AppListSyncableService* service =
113 AppListSyncableServiceFactory::GetForProfile(profile); 120 AppListSyncableServiceFactory::GetForProfile(profile);
114 service->model()->item_list()->MoveItem(from, to); 121 service->model()->item_list()->MoveItem(from, to);
115 } 122 }
116 123
117 void SyncAppListHelper::CopyOrdinalsToVerifier(Profile* profile, 124 void SyncAppListHelper::CopyOrdinalsToVerifier(Profile* profile,
118 const std::string& id) { 125 const std::string& id) {
119 AppListSyncableService* service = 126 AppListSyncableService* service =
120 AppListSyncableServiceFactory::GetForProfile(profile); 127 AppListSyncableServiceFactory::GetForProfile(profile);
121 AppListSyncableService* verifier = 128 AppListSyncableService* verifier =
122 AppListSyncableServiceFactory::GetForProfile(test_->verifier()); 129 AppListSyncableServiceFactory::GetForProfile(test_->verifier());
123 verifier->model()->item_list()->SetItemPosition( 130 verifier->model()->item_list()->SetItemPosition(
124 verifier->model()->item_list()->FindItem(id), 131 verifier->model()->item_list()->FindItem(id),
125 service->model()->item_list()->FindItem(id)->position()); 132 service->model()->item_list()->FindItem(id)->position());
126 } 133 }
127 134
128 void SyncAppListHelper::PrintAppList(Profile* profile) { 135 void SyncAppListHelper::PrintAppList(Profile* profile) {
129 AppListSyncableService* service = 136 AppListSyncableService* service =
130 AppListSyncableServiceFactory::GetForProfile(profile); 137 AppListSyncableServiceFactory::GetForProfile(profile);
131 for (size_t i = 0; i < service->model()->item_list()->item_count(); ++i) { 138 for (size_t i = 0; i < service->model()->item_list()->item_count(); ++i) {
132 AppListItem* item = service->model()->item_list()->item_at(i); 139 AppListItem* item = service->model()->item_list()->item_at(i);
133 extensions::AppSorting* s = 140 std::string label =
134 extensions::ExtensionSystem::Get(profile)->extension_service()-> 141 base::StringPrintf("Item(%d): ", static_cast<int>(i));
135 extension_prefs()->app_sorting(); 142 PrintItem(profile, item, label);
136 std::string id = item->id();
137 VLOG(1)
138 << "Item(" << i << "): " << item->ToDebugString()
139 << " Page: " << s->GetPageOrdinal(id).ToDebugString().substr(0, 8)
140 << " Item: " << s->GetAppLaunchOrdinal(id).ToDebugString().substr(0, 8);
141 } 143 }
142 } 144 }
145
146 void SyncAppListHelper::PrintItem(Profile* profile,
147 AppListItem* item,
148 const std::string& label) {
149 extensions::AppSorting* s =
150 extensions::ExtensionSystem::Get(profile)->extension_service()->
151 extension_prefs()->app_sorting();
152 std::string id = item->id();
153 if (item->GetItemType() == AppListFolderItem::kItemType) {
154 VLOG(1) << label << item->ToDebugString();
155 AppListFolderItem* folder = static_cast<AppListFolderItem*>(item);
156 for (size_t i = 0; i < folder->item_list()->item_count(); ++i) {
157 AppListItem* child = folder->item_list()->item_at(i);
158 std::string child_label =
159 base::StringPrintf(" Folder Item(%d): ", static_cast<int>(i));
160 PrintItem(profile, child, child_label);
161 }
162 return;
163 }
164 VLOG(1)
165 << label << item->ToDebugString()
166 << " Page: " << s->GetPageOrdinal(id).ToDebugString().substr(0, 8)
167 << " Item: " << s->GetAppLaunchOrdinal(id).ToDebugString().substr(0, 8);
168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698