| OLD | NEW |
| 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 "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 9 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 10 #include "chrome/browser/sync/test/integration/sync_test.h" | 10 #include "chrome/browser/sync/test/integration/sync_test.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 setup_completed_ = true; | 51 setup_completed_ = true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool SyncAppListHelper::AppListMatchesVerifier(Profile* profile) { | 54 bool SyncAppListHelper::AppListMatchesVerifier(Profile* profile) { |
| 55 AppListSyncableService* service = | 55 AppListSyncableService* service = |
| 56 AppListSyncableServiceFactory::GetForProfile(profile); | 56 AppListSyncableServiceFactory::GetForProfile(profile); |
| 57 AppListSyncableService* verifier = | 57 AppListSyncableService* verifier = |
| 58 AppListSyncableServiceFactory::GetForProfile(test_->verifier()); | 58 AppListSyncableServiceFactory::GetForProfile(test_->verifier()); |
| 59 // Note: sync item entries may not exist in verifier, but item lists should | 59 // Note: sync item entries may not exist in verifier, but item lists should |
| 60 // match. | 60 // match. |
| 61 if (service->model()->top_level_item_list()->item_count() != | 61 if (service->GetModel()->top_level_item_list()->item_count() != |
| 62 verifier->model()->top_level_item_list()->item_count()) { | 62 verifier->GetModel()->top_level_item_list()->item_count()) { |
| 63 LOG(ERROR) << "Model item count: " | 63 LOG(ERROR) << "Model item count: " |
| 64 << service->model()->top_level_item_list()->item_count() | 64 << service->GetModel()->top_level_item_list()->item_count() |
| 65 << " != " | 65 << " != " |
| 66 << verifier->model()->top_level_item_list()->item_count(); | 66 << verifier->GetModel()->top_level_item_list()->item_count(); |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 bool res = true; | 69 bool res = true; |
| 70 for (size_t i = 0; i < service->model()->top_level_item_list()->item_count(); | 70 for (size_t i = 0; |
| 71 ++i) { | 71 i < service->GetModel()->top_level_item_list()->item_count(); ++i) { |
| 72 AppListItem* item1 = service->model()->top_level_item_list()->item_at(i); | 72 AppListItem* item1 = service->GetModel()->top_level_item_list()->item_at(i); |
| 73 AppListItem* item2 = verifier->model()->top_level_item_list()->item_at(i); | 73 AppListItem* item2 = |
| 74 verifier->GetModel()->top_level_item_list()->item_at(i); |
| 74 if (item1->CompareForTest(item2)) | 75 if (item1->CompareForTest(item2)) |
| 75 continue; | 76 continue; |
| 76 | 77 |
| 77 LOG(ERROR) << "Item(" << i << "): " << item1->ToDebugString() | 78 LOG(ERROR) << "Item(" << i << "): " << item1->ToDebugString() |
| 78 << " != " << item2->ToDebugString(); | 79 << " != " << item2->ToDebugString(); |
| 79 size_t index2; | 80 size_t index2; |
| 80 if (!verifier->model()->top_level_item_list()->FindItemIndex(item1->id(), | 81 if (!verifier->GetModel()->top_level_item_list()->FindItemIndex(item1->id(), |
| 81 &index2)) { | 82 &index2)) { |
| 82 LOG(ERROR) << " Item(" << i << "): " << item1->ToDebugString() | 83 LOG(ERROR) << " Item(" << i << "): " << item1->ToDebugString() |
| 83 << " Not in verifier."; | 84 << " Not in verifier."; |
| 84 } else { | 85 } else { |
| 85 LOG(ERROR) << " Item(" << i << "): " << item1->ToDebugString() | 86 LOG(ERROR) << " Item(" << i << "): " << item1->ToDebugString() |
| 86 << " Has different verifier index: " << index2; | 87 << " Has different verifier index: " << index2; |
| 87 item2 = verifier->model()->top_level_item_list()->item_at(index2); | 88 item2 = verifier->GetModel()->top_level_item_list()->item_at(index2); |
| 88 LOG(ERROR) << " Verifier Item(" << index2 | 89 LOG(ERROR) << " Verifier Item(" << index2 |
| 89 << "): " << item2->ToDebugString(); | 90 << "): " << item2->ToDebugString(); |
| 90 } | 91 } |
| 91 res = false; | 92 res = false; |
| 92 } | 93 } |
| 93 return res; | 94 return res; |
| 94 } | 95 } |
| 95 | 96 |
| 96 bool SyncAppListHelper::AllProfilesHaveSameAppListAsVerifier() { | 97 bool SyncAppListHelper::AllProfilesHaveSameAppListAsVerifier() { |
| 97 bool res = true; | 98 bool res = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 << AppListSyncableServiceFactory::GetForProfile(profile); | 114 << AppListSyncableServiceFactory::GetForProfile(profile); |
| 114 PrintAppList(profile); | 115 PrintAppList(profile); |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 return res; | 118 return res; |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SyncAppListHelper::MoveApp(Profile* profile, size_t from, size_t to) { | 121 void SyncAppListHelper::MoveApp(Profile* profile, size_t from, size_t to) { |
| 121 AppListSyncableService* service = | 122 AppListSyncableService* service = |
| 122 AppListSyncableServiceFactory::GetForProfile(profile); | 123 AppListSyncableServiceFactory::GetForProfile(profile); |
| 123 service->model()->top_level_item_list()->MoveItem(from, to); | 124 service->GetModel()->top_level_item_list()->MoveItem(from, to); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void SyncAppListHelper::MoveAppToFolder(Profile* profile, | 127 void SyncAppListHelper::MoveAppToFolder(Profile* profile, |
| 127 size_t index, | 128 size_t index, |
| 128 const std::string& folder_id) { | 129 const std::string& folder_id) { |
| 129 AppListSyncableService* service = | 130 AppListSyncableService* service = |
| 130 AppListSyncableServiceFactory::GetForProfile(profile); | 131 AppListSyncableServiceFactory::GetForProfile(profile); |
| 131 service->model()->MoveItemToFolder( | 132 service->GetModel()->MoveItemToFolder( |
| 132 service->model()->top_level_item_list()->item_at(index), folder_id); | 133 service->GetModel()->top_level_item_list()->item_at(index), folder_id); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void SyncAppListHelper::MoveAppFromFolder(Profile* profile, | 136 void SyncAppListHelper::MoveAppFromFolder(Profile* profile, |
| 136 size_t index_in_folder, | 137 size_t index_in_folder, |
| 137 const std::string& folder_id) { | 138 const std::string& folder_id) { |
| 138 AppListSyncableService* service = | 139 AppListSyncableService* service = |
| 139 AppListSyncableServiceFactory::GetForProfile(profile); | 140 AppListSyncableServiceFactory::GetForProfile(profile); |
| 140 AppListFolderItem* folder = service->model()->FindFolderItem(folder_id); | 141 AppListFolderItem* folder = service->GetModel()->FindFolderItem(folder_id); |
| 141 if (!folder) { | 142 if (!folder) { |
| 142 LOG(ERROR) << "Folder not found: " << folder_id; | 143 LOG(ERROR) << "Folder not found: " << folder_id; |
| 143 return; | 144 return; |
| 144 } | 145 } |
| 145 service->model()->MoveItemToFolder( | 146 service->GetModel()->MoveItemToFolder( |
| 146 folder->item_list()->item_at(index_in_folder), ""); | 147 folder->item_list()->item_at(index_in_folder), ""); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void SyncAppListHelper::CopyOrdinalsToVerifier(Profile* profile, | 150 void SyncAppListHelper::CopyOrdinalsToVerifier(Profile* profile, |
| 150 const std::string& id) { | 151 const std::string& id) { |
| 151 AppListSyncableService* service = | 152 AppListSyncableService* service = |
| 152 AppListSyncableServiceFactory::GetForProfile(profile); | 153 AppListSyncableServiceFactory::GetForProfile(profile); |
| 153 AppListSyncableService* verifier = | 154 AppListSyncableService* verifier = |
| 154 AppListSyncableServiceFactory::GetForProfile(test_->verifier()); | 155 AppListSyncableServiceFactory::GetForProfile(test_->verifier()); |
| 155 verifier->model()->top_level_item_list()->SetItemPosition( | 156 verifier->GetModel()->top_level_item_list()->SetItemPosition( |
| 156 verifier->model()->FindItem(id), | 157 verifier->GetModel()->FindItem(id), |
| 157 service->model()->FindItem(id)->position()); | 158 service->GetModel()->FindItem(id)->position()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void SyncAppListHelper::PrintAppList(Profile* profile) { | 161 void SyncAppListHelper::PrintAppList(Profile* profile) { |
| 161 AppListSyncableService* service = | 162 AppListSyncableService* service = |
| 162 AppListSyncableServiceFactory::GetForProfile(profile); | 163 AppListSyncableServiceFactory::GetForProfile(profile); |
| 163 for (size_t i = 0; i < service->model()->top_level_item_list()->item_count(); | 164 for (size_t i = 0; |
| 164 ++i) { | 165 i < service->GetModel()->top_level_item_list()->item_count(); ++i) { |
| 165 AppListItem* item = service->model()->top_level_item_list()->item_at(i); | 166 AppListItem* item = service->GetModel()->top_level_item_list()->item_at(i); |
| 166 std::string label = base::StringPrintf("Item(%d): ", static_cast<int>(i)); | 167 std::string label = base::StringPrintf("Item(%d): ", static_cast<int>(i)); |
| 167 PrintItem(profile, item, label); | 168 PrintItem(profile, item, label); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 void SyncAppListHelper::PrintItem(Profile* profile, | 172 void SyncAppListHelper::PrintItem(Profile* profile, |
| 172 AppListItem* item, | 173 AppListItem* item, |
| 173 const std::string& label) { | 174 const std::string& label) { |
| 174 extensions::AppSorting* s = | 175 extensions::AppSorting* s = |
| 175 extensions::ExtensionPrefs::Get(profile)->app_sorting(); | 176 extensions::ExtensionPrefs::Get(profile)->app_sorting(); |
| 176 std::string id = item->id(); | 177 std::string id = item->id(); |
| 177 if (item->GetItemType() == AppListFolderItem::kItemType) { | 178 if (item->GetItemType() == AppListFolderItem::kItemType) { |
| 178 DVLOG(1) << label << item->ToDebugString(); | 179 DVLOG(1) << label << item->ToDebugString(); |
| 179 AppListFolderItem* folder = static_cast<AppListFolderItem*>(item); | 180 AppListFolderItem* folder = static_cast<AppListFolderItem*>(item); |
| 180 for (size_t i = 0; i < folder->item_list()->item_count(); ++i) { | 181 for (size_t i = 0; i < folder->item_list()->item_count(); ++i) { |
| 181 AppListItem* child = folder->item_list()->item_at(i); | 182 AppListItem* child = folder->item_list()->item_at(i); |
| 182 std::string child_label = | 183 std::string child_label = |
| 183 base::StringPrintf(" Folder Item(%d): ", static_cast<int>(i)); | 184 base::StringPrintf(" Folder Item(%d): ", static_cast<int>(i)); |
| 184 PrintItem(profile, child, child_label); | 185 PrintItem(profile, child, child_label); |
| 185 } | 186 } |
| 186 return; | 187 return; |
| 187 } | 188 } |
| 188 DVLOG(1) << label << item->ToDebugString() | 189 DVLOG(1) << label << item->ToDebugString() |
| 189 << " Page: " << s->GetPageOrdinal(id).ToDebugString().substr(0, 8) | 190 << " Page: " << s->GetPageOrdinal(id).ToDebugString().substr(0, 8) |
| 190 << " Item: " | 191 << " Item: " |
| 191 << s->GetAppLaunchOrdinal(id).ToDebugString().substr(0, 8); | 192 << s->GetAppLaunchOrdinal(id).ToDebugString().substr(0, 8); |
| 192 } | 193 } |
| OLD | NEW |