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

Unified Diff: content/shell/browser/layout_test/layout_test_notification_manager.cc

Issue 659043003: Implement the ability to layout test Web Worker-based Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 6 years, 2 months 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: content/shell/browser/layout_test/layout_test_notification_manager.cc
diff --git a/content/shell/browser/layout_test/layout_test_notification_manager.cc b/content/shell/browser/layout_test/layout_test_notification_manager.cc
index 99a6a23f7b63180d9a415dbfc2e277765a3b8df8..b3f64b471bd1760a91999686d5a6022d4b902a0a 100644
--- a/content/shell/browser/layout_test/layout_test_notification_manager.cc
+++ b/content/shell/browser/layout_test/layout_test_notification_manager.cc
@@ -4,14 +4,21 @@
#include "content/shell/browser/layout_test/layout_test_notification_manager.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/desktop_notification_delegate.h"
+#include "content/public/common/show_desktop_notification_params.h"
+
namespace content {
-LayoutTestNotificationManager::LayoutTestNotificationManager() {}
+LayoutTestNotificationManager::LayoutTestNotificationManager()
+ : weak_factory_(this) {}
LayoutTestNotificationManager::~LayoutTestNotificationManager() {}
blink::WebNotificationPermission
LayoutTestNotificationManager::CheckPermission(const GURL& origin) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
NotificationPermissionMap::iterator iter =
permission_map_.find(origin);
if (iter == permission_map_.end())
@@ -23,17 +30,73 @@ LayoutTestNotificationManager::CheckPermission(const GURL& origin) {
void LayoutTestNotificationManager::RequestPermission(
const GURL& origin,
const base::Callback<void(blink::WebNotificationPermission)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
callback.Run(CheckPermission(origin));
}
void LayoutTestNotificationManager::SetPermission(
const GURL& origin,
blink::WebNotificationPermission permission) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
permission_map_[origin] = permission;
}
void LayoutTestNotificationManager::ClearPermissions() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
permission_map_.clear();
}
+void LayoutTestNotificationManager::Show(
+ const ShowDesktopNotificationHostMsgParams& params,
+ scoped_ptr<DesktopNotificationDelegate> delegate,
+ base::Closure* cancel_callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ std::string title = base::UTF16ToUTF8(params.title);
+
+ DCHECK(cancel_callback);
+ *cancel_callback = base::Bind(&LayoutTestNotificationManager::Close,
+ weak_factory_.GetWeakPtr(),
+ title);
+
+ if (params.replace_id.length()) {
+ std::string replace_id = base::UTF16ToUTF8(params.replace_id);
+ auto replace_iter = replacements_.find(replace_id);
+ if (replace_iter != replacements_.end()) {
+ const std::string& previous_title = replace_iter->second;
+ auto notification_iter = notifications_.find(previous_title);
+ if (notification_iter != notifications_.end()) {
+ DesktopNotificationDelegate* previous_delegate =
+ notification_iter->second;
+ previous_delegate->NotificationClosed(false);
+
+ notifications_.erase(notification_iter);
+ delete previous_delegate;
+ }
+ }
+
+ replacements_[replace_id] = title;
+ }
+
+ notifications_[title] = delegate.release();
+ notifications_[title]->NotificationDisplayed();
+}
+
+void LayoutTestNotificationManager::SimulateClick(const std::string& title) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ auto iterator = notifications_.find(title);
+ if (iterator == notifications_.end())
+ return;
+
+ iterator->second->NotificationClick();
+}
+
+void LayoutTestNotificationManager::Close(const std::string& title) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ auto iterator = notifications_.find(title);
+ if (iterator == notifications_.end())
+ return;
+
+ iterator->second->NotificationClosed(false);
+}
+
} // namespace content
« no previous file with comments | « content/shell/browser/layout_test/layout_test_notification_manager.h ('k') | content/shell/common/shell_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698