OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/content_settings/permission_context_base.h" | 5 #include "chrome/browser/content_settings/permission_context_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/content_settings/permission_queue_controller.h" | 8 #include "chrome/browser/content_settings/permission_queue_controller.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 private: | 75 private: |
76 bool permission_set_; | 76 bool permission_set_; |
77 bool permission_granted_; | 77 bool permission_granted_; |
78 bool tab_context_updated_; | 78 bool tab_context_updated_; |
79 }; | 79 }; |
80 | 80 |
81 // Simulates clicking Accept. The permission should be granted and | 81 // Simulates clicking Accept. The permission should be granted and |
82 // saved for future use. | 82 // saved for future use. |
83 TEST_F(PermissionContextBaseTests, TestAskAndGrant) { | 83 TEST_F(PermissionContextBaseTests, TestAskAndGrant) { |
84 TestPermissionContext permission_context(profile(), | 84 TestPermissionContext permission_context(profile(), |
85 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 85 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
86 GURL url("http://www.google.com"); | 86 GURL url("http://www.google.com"); |
87 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 87 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
88 | 88 |
89 const PermissionRequestID id( | 89 const PermissionRequestID id( |
90 web_contents()->GetRenderProcessHost()->GetID(), | 90 web_contents()->GetRenderProcessHost()->GetID(), |
91 web_contents()->GetRenderViewHost()->GetRoutingID(), | 91 web_contents()->GetRenderViewHost()->GetRoutingID(), |
92 -1, GURL()); | 92 -1, GURL()); |
93 permission_context.RequestPermission( | 93 permission_context.RequestPermission( |
94 web_contents(), | 94 web_contents(), |
95 id, url, true, | 95 id, url, true, |
96 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 96 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
97 base::Unretained(&permission_context))); | 97 base::Unretained(&permission_context))); |
98 | 98 |
99 permission_context.GetInfoBarController()->OnPermissionSet( | 99 permission_context.GetInfoBarController()->OnPermissionSet( |
100 id, url, url, true, true); | 100 id, url, url, true, true); |
101 EXPECT_TRUE(permission_context.permission_set()); | 101 EXPECT_TRUE(permission_context.permission_set()); |
102 EXPECT_TRUE(permission_context.permission_granted()); | 102 EXPECT_TRUE(permission_context.permission_granted()); |
103 EXPECT_TRUE(permission_context.tab_context_updated()); | 103 EXPECT_TRUE(permission_context.tab_context_updated()); |
104 | 104 |
105 ContentSetting setting = | 105 ContentSetting setting = |
106 profile()->GetHostContentSettingsMap()->GetContentSetting( | 106 profile()->GetHostContentSettingsMap()->GetContentSetting( |
107 url.GetOrigin(), url.GetOrigin(), | 107 url.GetOrigin(), url.GetOrigin(), |
108 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()); | 108 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); |
109 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); | 109 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); |
110 }; | 110 }; |
111 | 111 |
112 // Simulates clicking Dismiss (X in the infobar. | 112 // Simulates clicking Dismiss (X in the infobar. |
113 // The permission should be denied but not saved for future use. | 113 // The permission should be denied but not saved for future use. |
114 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { | 114 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { |
115 TestPermissionContext permission_context(profile(), | 115 TestPermissionContext permission_context(profile(), |
116 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 116 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
117 GURL url("http://www.google.es"); | 117 GURL url("http://www.google.es"); |
118 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 118 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
(...skipping 13 matching lines...) Expand all Loading... |
132 EXPECT_TRUE(permission_context.permission_set()); | 132 EXPECT_TRUE(permission_context.permission_set()); |
133 EXPECT_FALSE(permission_context.permission_granted()); | 133 EXPECT_FALSE(permission_context.permission_granted()); |
134 EXPECT_TRUE(permission_context.tab_context_updated()); | 134 EXPECT_TRUE(permission_context.tab_context_updated()); |
135 | 135 |
136 ContentSetting setting = | 136 ContentSetting setting = |
137 profile()->GetHostContentSettingsMap()->GetContentSetting( | 137 profile()->GetHostContentSettingsMap()->GetContentSetting( |
138 url.GetOrigin(), url.GetOrigin(), | 138 url.GetOrigin(), url.GetOrigin(), |
139 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); | 139 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); |
140 EXPECT_EQ(CONTENT_SETTING_ASK , setting); | 140 EXPECT_EQ(CONTENT_SETTING_ASK , setting); |
141 }; | 141 }; |
OLD | NEW |