Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/test/integration/app_notification_helper.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/string_util.h" | |
| 10 #include "base/stringprintf.h" | |
| 11 #include "base/time.h" | |
| 12 #include "base/utf_string_conversions.h" | |
| 13 #include "chrome/browser/extensions/app_notification_manager.h" | |
| 14 #include "chrome/browser/extensions/extension_service.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 16 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
| 17 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | |
| 18 #include "chrome/browser/sync/test/integration/sync_test.h" | |
| 19 | |
| 20 using sync_datatype_helper::test; | |
| 21 | |
| 22 namespace app_notification_helper { | |
| 23 | |
| 24 AppNotificationManager* GetServiceForProfile(int index) { | |
| 25 return test()->GetProfile(index)-> | |
| 26 GetExtensionService()->app_notification_manager(); | |
| 27 } | |
| 28 | |
| 29 AppNotificationManager* GetVerifierService() { | |
| 30 return test()->verifier()->GetExtensionService()->app_notification_manager(); | |
| 31 } | |
| 32 | |
| 33 bool AppNotificationMatch(const AppNotification* not1, | |
| 34 const AppNotification* not2) { | |
| 35 CHECK(not1); | |
| 36 CHECK(not2); | |
| 37 | |
| 38 // Compare all major fields. | |
| 39 bool result = (not1->title() == not2->title() && | |
| 40 not1->body() == not2->body()); | |
| 41 // Print some useful debug info. | |
| 42 if (!result) { | |
| 43 LOG(ERROR) << "AppNotification did not match"; | |
| 44 } | |
| 45 return result; | |
| 46 } | |
| 47 | |
| 48 bool ServiceMatchesVerifier(int profile, const std::string& extension_id) { | |
| 49 AppNotificationManager* verifier = GetVerifierService(); | |
| 50 AppNotificationManager* other = GetServiceForProfile(profile); | |
| 51 | |
| 52 CHECK(verifier); | |
| 53 CHECK(other); | |
| 54 | |
| 55 const AppNotificationList* verifier_list = verifier->GetAll(extension_id); | |
| 56 const AppNotificationList* other_list = other->GetAll(extension_id); | |
| 57 if (verifier_list == NULL && other_list == NULL) { | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 if (verifier_list->size() != other_list->size()) { | |
|
Munjal (Google)
2011/12/03 05:03:49
You are checking verifier_list == NULL && other_li
| |
| 62 LOG(ERROR) << "Verifier and other service have a different " | |
| 63 << "count of notifications: " | |
| 64 << verifier_list->size() << " vs " | |
| 65 << other_list->size() << " respectively."; | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 for (size_t i = 0; i < verifier_list->size(); ++i) { | |
| 70 const AppNotification* verifier_notification = verifier_list->at(i).get(); | |
|
Munjal (Google)
2011/12/03 05:03:49
Nit: you can do verifier_list[i].get()
| |
| 71 const AppNotification* other_notification = other_list->at(i).get(); | |
| 72 CHECK(verifier_notification); | |
| 73 CHECK(other_notification); | |
| 74 | |
| 75 if (!AppNotificationMatch(verifier_notification, other_notification)) | |
| 76 return false; | |
| 77 } | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 void AddNotification(int profile, int seed) { | |
| 82 GetServiceForProfile(profile)->Add(CreateTestAppNotification(seed)); | |
| 83 if (test()->use_verifier()) | |
| 84 GetVerifierService()->Add(CreateTestAppNotification(seed)); | |
| 85 } | |
| 86 | |
| 87 AppNotification* CreateTestAppNotification(int seed) { | |
| 88 return new AppNotification(false, base::Time::Now(), | |
| 89 "guid" + seed, "extensionId", | |
| 90 "title" + seed, "body" +seed); | |
| 91 } | |
| 92 | |
| 93 } // namespace app_notification_helper | |
| 94 | |
|
Munjal (Google)
2011/12/03 05:03:49
Nit: remove this empty line.
| |
| OLD | NEW |