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

Side by Side Diff: chrome/browser/notifications/notification_permission_context_unittest.cc

Issue 1207363002: Simplify permission-related code for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "chrome/browser/notifications/notification_permission_context.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
9 #include "chrome/browser/permissions/permission_request_id.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h"
16
17 namespace {
18
19 class TestNotificationPermissionContext : public NotificationPermissionContext {
20 public:
21 explicit TestNotificationPermissionContext(Profile* profile)
22 : NotificationPermissionContext(profile) {}
23 ~TestNotificationPermissionContext() override {}
24
25 // Simulates a call to PermissionContextBase::NotifyPermissionSet().
26 void SimulatePermissionSet(const GURL& requesting_origin,
27 const GURL& embedding_origin,
28 ContentSetting content_setting,
29 ContentSetting* content_setting_out) {
30 DCHECK(content_setting_out);
31
32 const PermissionRequestID id(-1 /* render_process_id */,
33 -1 /* render_frame_id */,
34 -1 /* request_id */,
35 GURL() /* origin */);
36
37 NotifyPermissionSet(
38 id, requesting_origin, embedding_origin,
39 base::Bind(&TestNotificationPermissionContext::DidSetPermission,
40 base::Unretained(this), content_setting_out),
41 true /* persist */, content_setting);
42 }
43
44 private:
45 void DidSetPermission(ContentSetting* content_setting_out,
46 ContentSetting content_setting) {
47 *content_setting_out = content_setting;
48 }
49
50 DISALLOW_COPY_AND_ASSIGN(TestNotificationPermissionContext);
51 };
52
53 // Web Notification permission requests will completely ignore the embedder
54 // origin. See https://crbug.com/416894.
55 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
56 content::TestBrowserThreadBundle thread_bundle;
57 ContentSetting decided_content_setting;
58 TestingProfile profile;
59
60 GURL requesting_origin("https://example.com");
61 GURL embedding_origin("https://chrome.com");
62 GURL different_origin("https://foobar.com");
63
64 TestNotificationPermissionContext context(&profile);
65 ASSERT_NO_FATAL_FAILURE(
66 context.SimulatePermissionSet(requesting_origin,
67 embedding_origin,
68 CONTENT_SETTING_ALLOW,
69 &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.
70
71 EXPECT_EQ(CONTENT_SETTING_ALLOW, decided_content_setting);
72
73 EXPECT_EQ(CONTENT_SETTING_ALLOW,
74 context.GetPermissionStatus(requesting_origin, embedding_origin));
75
76 EXPECT_EQ(CONTENT_SETTING_ALLOW,
77 context.GetPermissionStatus(requesting_origin, different_origin));
78 }
79
80 // Web Notifications do not require a secure origin when requesting permission.
81 // See https://crbug.com/404095.
82 TEST(NotificationPermissionContextTest, NoSecureOriginRequirement) {
83 content::TestBrowserThreadBundle thread_bundle;
84 TestingProfile profile;
85
86 GURL origin("http://example.com");
87
88 TestNotificationPermissionContext context(&profile);
89 EXPECT_EQ(CONTENT_SETTING_ASK,
90 context.GetPermissionStatus(origin, origin));
91
92 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.
93
94 EXPECT_EQ(CONTENT_SETTING_ALLOW,
95 context.GetPermissionStatus(origin, origin));
96 }
97
98 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698