#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h"
+#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_browser_thread.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_change_processor.h"
using notifier::SyncedNotificationAppInfoService;
using sync_pb::SyncedNotificationAppInfoSpecifics;
-namespace {
-const char kSendingService1Name[] = "TestService1";
-const char kSendingService2Name[] = "TestService2";
-const char kSendingService3Name[] = "TestService3";
-const char kAppId1[] = "service1_appid1";
-const char kAppId2[] = "service1_appid2";
-const char kAppId3[] = "service1_appid3";
-const char kAppId4[] = "service2_appid1";
-const char kAppId5[] = "service2_appid2";
-const char kTestIconUrl[] = "https://www.google.com/someicon.png";
-} // namespace
-
namespace notifier {
// Extract app_info id from syncer::SyncData.
// Create the app_info struct, setting the settings display name.
// The sending_service_infos_ list will take ownership of this pointer.
- SyncedNotificationAppInfo* test_item1 =
- new SyncedNotificationAppInfo(kSendingService1Name);
+ SyncedNotificationAppInfo* test_item1 = new SyncedNotificationAppInfo(
+ NULL, kSendingService1Name, app_info_service);
// Add some App IDs.
test_item1->AddAppId(kAppId1);
test_item1->AddAppId(kAppId2);
// Set this icon GURL.
- test_item1->SetSettingsIcon(GURL(kTestIconUrl));
+ test_item1->SetSettingsURLs(GURL(kTestIconUrl), GURL());
// Add to the list.
app_info_service->sending_service_infos_.push_back(test_item1);
// Add a second test item for another service.
- SyncedNotificationAppInfo* test_item2 =
- new SyncedNotificationAppInfo(kSendingService2Name);
+ SyncedNotificationAppInfo* test_item2 = new SyncedNotificationAppInfo(
+ NULL, kSendingService2Name, app_info_service);
// Add some App IDs.
test_item2->AddAppId(kAppId4);
test_item2->AddAppId(kAppId5);
// Set thi icon GURL.
- test_item2->SetSettingsIcon(GURL(kTestIconUrl));
+ test_item2->SetSettingsURLs(GURL(kTestIconUrl), GURL());
// Add to the list.
app_info_service->sending_service_infos_.push_back(test_item2);
protobuf.add_app_id(std::string(kAppId1));
protobuf.add_app_id(std::string(kAppId2));
protobuf.set_settings_display_name(kSendingService1Name);
+ protobuf.set_info_url(kTestInfoUrl);
protobuf.mutable_icon()->set_url(kTestIconUrl);
}
// Helper to create syncer::SyncChange.
static SyncChange CreateSyncChange(SyncChange::SyncChangeType type,
const std::string& settings_display_name,
+ const std::string& info_url,
const std::string& icon_url,
const std::string& app_id1,
const std::string& app_id2) {
return SyncChange(
FROM_HERE,
type,
- CreateSyncData(settings_display_name, icon_url, app_id1, app_id2));
+ CreateSyncData(
+ settings_display_name, info_url, icon_url, app_id1, app_id2));
}
// Build a SyncData object to look like what Sync would deliver.
static SyncData CreateSyncData(const std::string& settings_display_name,
+ const std::string& info_url,
const std::string& icon_url,
const std::string& app_id1,
const std::string& app_id2) {
// Add the key, the settings display name.
app_info->set_settings_display_name(settings_display_name);
+ // Add the welcome notification info URL.
+ app_info->set_info_url(info_url);
+
// Add the icon URL.
app_info->mutable_icon()->set_url(icon_url);
private:
scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_;
- content::TestBrowserThreadBundle thread_bundle_;
DISALLOW_COPY_AND_ASSIGN(SyncedNotificationAppInfoServiceTest);
};
TEST_F(SyncedNotificationAppInfoServiceTest, ProcessSyncChangesEmptyModel) {
// We initially have no data.
SyncedNotificationAppInfoService app_info_service(profile_.get());
+ app_info_service.set_avoid_bitmap_fetching_for_test(true);
// Set up an ADD.
SyncChangeList changes;
changes.push_back(CreateSyncChange(SyncChange::ACTION_ADD,
kSendingService1Name,
+ kTestInfoUrl,
kTestIconUrl,
kAppId1,
kAppId2));
// Process sync changes when there is local data.
TEST_F(SyncedNotificationAppInfoServiceTest, ProcessSyncChangesNonEmptyModel) {
SyncedNotificationAppInfoService app_info_service(profile_.get());
+ app_info_service.set_avoid_bitmap_fetching_for_test(true);
// Create some local fake data. We rely on the specific ids set up here.
AddTestingAppInfosToList(&app_info_service);
changes.push_back(CreateSyncChange(SyncChange::ACTION_UPDATE,
kSendingService1Name,
+ kTestInfoUrl,
kTestIconUrl,
kAppId1,
kAppId3));
ProcessIncomingAppInfoProtobufAddTest) {
// Get an app info service object.
SyncedNotificationAppInfoService app_info_service(profile_.get());
+ app_info_service.set_avoid_bitmap_fetching_for_test(true);
// Get an app info protobuf.
sync_pb::SyncedNotificationAppInfo protobuf;
ProcessIncomingAppInfoProtobufUpdateTest) {
// Get an app info service object.
SyncedNotificationAppInfoService app_info_service(profile_.get());
+ app_info_service.set_avoid_bitmap_fetching_for_test(true);
// Make an app info with the same display name as the first one in the test
// data.
// Test our function that creates a synced notification from a protobuf.
TEST_F(SyncedNotificationAppInfoServiceTest,
CreateSyncedNotificationAppInfoFromProtobufTest) {
+ SyncedNotificationAppInfoService app_info_service(profile_.get());
// Build a protobuf and fill it with data.
sync_pb::SyncedNotificationAppInfo protobuf;
FillProtobufWithTestData1(protobuf);
scoped_ptr<SyncedNotificationAppInfo> app_info;
- app_info = SyncedNotificationAppInfoService::
- CreateSyncedNotificationAppInfoFromProtobuf(protobuf);
+ app_info =
+ app_info_service.CreateSyncedNotificationAppInfoFromProtobuf(protobuf);
// Ensure the app info class has the fields we expect.
EXPECT_EQ(std::string(kSendingService1Name),
app_info->settings_display_name());
+ EXPECT_EQ(GURL(kTestInfoUrl), app_info->welcome_link_url());
EXPECT_TRUE(app_info->HasAppId(kAppId1));
EXPECT_TRUE(app_info->HasAppId(kAppId2));
EXPECT_EQ(GURL(std::string(kTestIconUrl)), app_info->settings_icon_url());
}
-// Test our find function.
+// Test our find by sending service name function.
TEST_F(SyncedNotificationAppInfoServiceTest,
FindSyncedNotificationAppInfoByNameTest) {
SyncedNotificationAppInfoService app_info_service(profile_.get());
EXPECT_EQ(NULL, found);
}
+// Test our find by AppId function.
+TEST_F(SyncedNotificationAppInfoServiceTest,
+ FindSyncedNotificationAppInfoByAppIdTest) {
+ SyncedNotificationAppInfoService app_info_service(profile_.get());
+
+ AddTestingAppInfosToList(&app_info_service);
+
+ SyncedNotificationAppInfo* found;
+
+ found = app_info_service.FindSyncedNotificationAppInfoByAppId(kAppId1);
+
+ EXPECT_NE(static_cast<SyncedNotificationAppInfo*>(NULL), found);
+ EXPECT_EQ(std::string(kSendingService1Name), found->settings_display_name());
+
+ found = app_info_service.FindSyncedNotificationAppInfoByName(kAppId5);
+ EXPECT_EQ(NULL, found);
+}
+
+// Test our find sending service name by app id function.
+TEST_F(SyncedNotificationAppInfoServiceTest,
+ FindSendingServiceNameFromAppIdTest) {
+ SyncedNotificationAppInfoService app_info_service(profile_.get());
+
+ AddTestingAppInfosToList(&app_info_service);
+
+ std::string found_name;
+
+ found_name = app_info_service.FindSendingServiceNameFromAppId(kAppId1);
+
+ EXPECT_EQ(std::string(kSendingService1Name), found_name);
+
+ found_name = app_info_service.FindSendingServiceNameFromAppId(kAppId6);
+ EXPECT_TRUE(found_name.empty());
+}
+
// Test our delete function.
TEST_F(SyncedNotificationAppInfoServiceTest,
FreeSyncedNotificationAppInfoByNameTest) {
EXPECT_EQ(NULL, found);
}
+TEST_F(SyncedNotificationAppInfoServiceTest,
+ GetAllSendingServiceSettingsDataTest) {
+ SyncedNotificationAppInfoService app_info_service(profile_.get());
+
+ AddTestingAppInfosToList(&app_info_service);
+
+ std::vector<SyncedNotificationSendingServiceSettingsData> data;
+ data = app_info_service.GetAllSendingServiceSettingsData();
+
+ EXPECT_EQ(static_cast<unsigned int>(2), data.size());
+ EXPECT_EQ(kSendingService1Name, data[0].settings_display_name);
+ EXPECT_EQ(kSendingService2Name, data[1].settings_display_name);
+}
+
} // namespace notifier