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

Unified Diff: chrome/browser/sync/test/integration/app_notification_helper.cc

Issue 8735019: Add App Notification Sync Integration Test (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/test/integration/app_notification_helper.cc
===================================================================
--- chrome/browser/sync/test/integration/app_notification_helper.cc (revision 0)
+++ chrome/browser/sync/test/integration/app_notification_helper.cc (revision 0)
@@ -0,0 +1,94 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/test/integration/app_notification_helper.h"
+
+#include <vector>
+
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/app_notification_manager.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/profile_sync_service_harness.h"
+#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
+#include "chrome/browser/sync/test/integration/sync_test.h"
+
+using sync_datatype_helper::test;
+
+namespace app_notification_helper {
+
+AppNotificationManager* GetServiceForProfile(int index) {
+ return test()->GetProfile(index)->
+ GetExtensionService()->app_notification_manager();
+}
+
+AppNotificationManager* GetVerifierService() {
+ return test()->verifier()->GetExtensionService()->app_notification_manager();
+}
+
+bool AppNotificationMatch(const AppNotification* not1,
+ const AppNotification* not2) {
+ CHECK(not1);
+ CHECK(not2);
+
+ // Compare all major fields.
+ bool result = (not1->title() == not2->title() &&
+ not1->body() == not2->body());
+ // Print some useful debug info.
+ if (!result) {
+ LOG(ERROR) << "AppNotification did not match";
+ }
+ return result;
+}
+
+bool ServiceMatchesVerifier(int profile, const std::string& extension_id) {
+ AppNotificationManager* verifier = GetVerifierService();
+ AppNotificationManager* other = GetServiceForProfile(profile);
+
+ CHECK(verifier);
+ CHECK(other);
+
+ const AppNotificationList* verifier_list = verifier->GetAll(extension_id);
+ const AppNotificationList* other_list = other->GetAll(extension_id);
+ if (verifier_list == NULL && other_list == NULL) {
+ return true;
+ }
+
+ if (verifier_list->size() != other_list->size()) {
Munjal (Google) 2011/12/03 05:03:49 You are checking verifier_list == NULL && other_li
+ LOG(ERROR) << "Verifier and other service have a different "
+ << "count of notifications: "
+ << verifier_list->size() << " vs "
+ << other_list->size() << " respectively.";
+ return false;
+ }
+
+ for (size_t i = 0; i < verifier_list->size(); ++i) {
+ 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()
+ const AppNotification* other_notification = other_list->at(i).get();
+ CHECK(verifier_notification);
+ CHECK(other_notification);
+
+ if (!AppNotificationMatch(verifier_notification, other_notification))
+ return false;
+ }
+ return true;
+}
+
+void AddNotification(int profile, int seed) {
+ GetServiceForProfile(profile)->Add(CreateTestAppNotification(seed));
+ if (test()->use_verifier())
+ GetVerifierService()->Add(CreateTestAppNotification(seed));
+}
+
+AppNotification* CreateTestAppNotification(int seed) {
+ return new AppNotification(false, base::Time::Now(),
+ "guid" + seed, "extensionId",
+ "title" + seed, "body" +seed);
+}
+
+} // namespace app_notification_helper
+
Munjal (Google) 2011/12/03 05:03:49 Nit: remove this empty line.

Powered by Google App Engine
This is Rietveld 408576698