Index: chrome/browser/notifications/notification_permission_context_unittest.cc |
diff --git a/chrome/browser/notifications/notification_permission_context_unittest.cc b/chrome/browser/notifications/notification_permission_context_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..43f8c2df13388188abe4923943e49fe3d83850dd |
--- /dev/null |
+++ b/chrome/browser/notifications/notification_permission_context_unittest.cc |
@@ -0,0 +1,98 @@ |
+// Copyright 2015 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/notifications/notification_permission_context.h" |
+ |
+#include "base/bind.h" |
+#include "chrome/browser/notifications/desktop_notification_profile_util.h" |
+#include "chrome/browser/permissions/permission_request_id.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "components/content_settings/core/browser/host_content_settings_map.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+namespace { |
+ |
+class TestNotificationPermissionContext : public NotificationPermissionContext { |
+ public: |
+ explicit TestNotificationPermissionContext(Profile* profile) |
+ : NotificationPermissionContext(profile) {} |
+ ~TestNotificationPermissionContext() override {} |
+ |
+ // Simulates a call to PermissionContextBase::NotifyPermissionSet(). |
+ void SimulatePermissionSet(const GURL& requesting_origin, |
+ const GURL& embedding_origin, |
+ ContentSetting content_setting, |
+ ContentSetting* content_setting_out) { |
+ DCHECK(content_setting_out); |
+ |
+ const PermissionRequestID id(-1 /* render_process_id */, |
+ -1 /* render_frame_id */, |
+ -1 /* request_id */, |
+ GURL() /* origin */); |
+ |
+ NotifyPermissionSet( |
+ id, requesting_origin, embedding_origin, |
+ base::Bind(&TestNotificationPermissionContext::DidSetPermission, |
+ base::Unretained(this), content_setting_out), |
+ true /* persist */, content_setting); |
+ } |
+ |
+ private: |
+ void DidSetPermission(ContentSetting* content_setting_out, |
+ ContentSetting content_setting) { |
+ *content_setting_out = content_setting; |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestNotificationPermissionContext); |
+}; |
+ |
+// Web Notification permission requests will completely ignore the embedder |
+// origin. See https://crbug.com/416894. |
+TEST(NotificationPermissionContextTest, IgnoresEmbedderOrigin) { |
mlamouri (slow - plz ping)
2015/06/29 10:57:42
Could you have a NotificationPermissionContextTest
Peter Beverloo
2015/06/29 12:54:21
I prefer two repetitive lines over introducing a f
|
+ content::TestBrowserThreadBundle thread_bundle; |
+ ContentSetting decided_content_setting; |
+ TestingProfile profile; |
+ |
+ GURL requesting_origin("https://example.com"); |
+ GURL embedding_origin("https://chrome.com"); |
+ GURL different_origin("https://foobar.com"); |
+ |
+ TestNotificationPermissionContext context(&profile); |
+ ASSERT_NO_FATAL_FAILURE( |
+ context.SimulatePermissionSet(requesting_origin, |
+ embedding_origin, |
+ CONTENT_SETTING_ALLOW, |
+ &decided_content_setting)); |
mlamouri (slow - plz ping)
2015/06/29 10:57:42
Why don't you call directly UpdateContentSetting()
Peter Beverloo
2015/06/29 12:54:21
Done.
|
+ |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, decided_content_setting); |
+ |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ context.GetPermissionStatus(requesting_origin, embedding_origin)); |
+ |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ context.GetPermissionStatus(requesting_origin, different_origin)); |
+} |
+ |
+// Web Notifications do not require a secure origin when requesting permission. |
+// See https://crbug.com/404095. |
+TEST(NotificationPermissionContextTest, NoSecureOriginRequirement) { |
+ content::TestBrowserThreadBundle thread_bundle; |
+ TestingProfile profile; |
+ |
+ GURL origin("http://example.com"); |
+ |
+ TestNotificationPermissionContext context(&profile); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ context.GetPermissionStatus(origin, origin)); |
+ |
+ DesktopNotificationProfileUtil::GrantPermission(&profile, origin); |
mlamouri (slow - plz ping)
2015/06/29 10:57:42
Could you call ::UpdateContentSetting() instead?
Peter Beverloo
2015/06/29 12:54:21
Done.
|
+ |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ context.GetPermissionStatus(origin, origin)); |
+} |
+ |
+} // namespace |