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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h" 12 #include "sync/api/sync_data.h" 13 #include "sync/api/sync_error_factory.h" 14 #include "sync/protocol/sync.pb.h" 15 #include "sync/protocol/synced_notification_specifics.pb.h" 16 17 // Test data for App Info structures. 18 extern const char kSendingService1Name[]; 19 extern const char kSendingService2Name[]; 20 extern const char kSendingService3Name[]; 21 extern const char kTestInfoUrl[]; 22 extern const char kTestIconUrl[]; 23 24 // Fake data for creating a SyncedNotification. 25 extern const char kAppId1[]; 26 extern const char kAppId2[]; 27 extern const char kAppId3[]; 28 extern const char kAppId4[]; 29 extern const char kAppId5[]; 30 extern const char kAppId6[]; 31 extern const char kAppId7[]; 32 extern const char kKey1[]; 33 extern const char kKey2[]; 34 extern const char kKey3[]; 35 extern const char kKey4[]; 36 extern const char kKey5[]; 37 extern const char kKey6[]; 38 extern const char kKey7[]; 39 extern const char kIconUrl1[]; 40 extern const char kIconUrl2[]; 41 extern const char kIconUrl3[]; 42 extern const char kIconUrl4[]; 43 extern const char kIconUrl5[]; 44 extern const char kIconUrl6[]; 45 extern const char kIconUrl7[]; 46 extern const char kTitle1[]; 47 extern const char kTitle2[]; 48 extern const char kTitle3[]; 49 extern const char kTitle4[]; 50 extern const char kTitle5[]; 51 extern const char kTitle6[]; 52 extern const char kTitle7[]; 53 extern const char kText1[]; 54 extern const char kText2[]; 55 extern const char kText3[]; 56 extern const char kText4[]; 57 extern const char kText5[]; 58 extern const char kText6[]; 59 extern const char kText7[]; 60 extern const char kText1And1[]; 61 extern const char kImageUrl1[]; 62 extern const char kImageUrl2[]; 63 extern const char kImageUrl3[]; 64 extern const char kImageUrl4[]; 65 extern const char kImageUrl5[]; 66 extern const char kImageUrl6[]; 67 extern const char kImageUrl7[]; 68 extern const char kExpectedOriginUrl[]; 69 extern const char kDefaultDestinationTitle[]; 70 extern const char kDefaultDestinationIconUrl[]; 71 extern const char kDefaultDestinationUrl[]; 72 extern const char kButtonOneTitle[]; 73 extern const char kButtonOneIconUrl[]; 74 extern const char kButtonOneUrl[]; 75 extern const char kButtonTwoTitle[]; 76 extern const char kButtonTwoIconUrl[]; 77 extern const char kButtonTwoUrl[]; 78 extern const char kContainedTitle1[]; 79 extern const char kContainedTitle2[]; 80 extern const char kContainedTitle3[]; 81 extern const char kContainedMessage1[]; 82 extern const char kContainedMessage2[]; 83 extern const char kContainedMessage3[]; 84 const uint64 kFakeCreationTime = 42; 85 const int kProtobufPriority = static_cast<int>( 86 sync_pb::CoalescedSyncedNotification_Priority_INVISIBLE); 87 88 const sync_pb::CoalescedSyncedNotification_ReadState kRead = 89 sync_pb::CoalescedSyncedNotification_ReadState_READ; 90 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = 91 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; 92 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = 93 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; 94 95 // This function builds the sync data object we use to create a testing 96 // notification. 97 syncer::SyncData CreateSyncData( 98 const std::string& title, 99 const std::string& text, 100 const std::string& app_icon_url, 101 const std::string& image_url, 102 const std::string& app_id, 103 const std::string& key, 104 const sync_pb::CoalescedSyncedNotification_ReadState read_state); 105 106 namespace notifier { 107 108 // Stub out the SyncedNotificationAppInfoService. This is used to 109 // 1. Verify that when bitmaps are fetched, the OnFetchComplete causes a call to 110 // OnBitmapFetchesDone. 111 // 2. Provide the app info for our first sending service. 112 class StubSyncedNotificationAppInfoService 113 : public SyncedNotificationAppInfoService { 114 public: 115 // Interface functions from SyncedNotificationAppInfoService 116 explicit StubSyncedNotificationAppInfoService(Profile* profile); 117 virtual ~StubSyncedNotificationAppInfoService(); Shutdown()118 virtual void Shutdown() OVERRIDE{} 119 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 120 syncer::ModelType type, 121 const syncer::SyncDataList& initial_sync_data, 122 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 123 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; StopSyncing(syncer::ModelType type)124 virtual void StopSyncing(syncer::ModelType type) OVERRIDE{} 125 virtual syncer::SyncError ProcessSyncChanges( 126 const tracked_objects::Location& from_here, 127 const syncer::SyncChangeList& change_list) OVERRIDE; 128 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const 129 OVERRIDE; ProcessIncomingAppInfoProtobuf(const sync_pb::SyncedNotificationAppInfo & app_info)130 void ProcessIncomingAppInfoProtobuf( 131 const sync_pb::SyncedNotificationAppInfo& app_info) {} ProcessRemovedAppInfoProtobuf(const sync_pb::SyncedNotificationAppInfo & app_info)132 void ProcessRemovedAppInfoProtobuf( 133 const sync_pb::SyncedNotificationAppInfo& app_info) {} 134 // Remember the arguments we saw in the most recent call. 135 virtual void OnBitmapFetchesDone(std::vector<std::string> added_app_ids, 136 std::vector<std::string> removed_app_ids) 137 OVERRIDE; 138 scoped_ptr<SyncedNotificationAppInfo> 139 CreateSyncedNotificationAppInfoFromProtobuf( 140 const sync_pb::SyncedNotificationAppInfo& app_info); 141 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByAppId( 142 const std::string& app_id); 143 std::string FindSendingServiceNameFromAppId(const std::string app_id); 144 std::vector<SyncedNotificationSendingServiceSettingsData> 145 GetAllSendingServiceSettingsData(); AddForTest(scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info)146 void AddForTest( 147 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) {} set_avoid_bitmap_fetching_for_test(bool avoid)148 static void set_avoid_bitmap_fetching_for_test(bool avoid) {} 149 150 // Probe functions to return data. 151 std::vector<std::string> added_app_ids(); 152 std::vector<std::string> removed_app_ids(); 153 bool on_bitmap_fetches_done_called(); 154 155 private: 156 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName( 157 const std::string& name); 158 std::vector<std::string> added_app_ids_; 159 std::vector<std::string> removed_app_ids_; 160 bool on_bitmap_fetches_done_called_; 161 }; 162 163 } // namespace notifier 164 165 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_ 166