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/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
9 #include "chrome/browser/content_settings/permission_queue_controller.h" | 9 #include "chrome/browser/content_settings/permission_queue_controller.h" |
10 #include "chrome/browser/content_settings/permission_request_id.h" | 10 #include "chrome/browser/content_settings/permission_request_id.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
12 #include "chrome/common/content_settings.h" | 13 #include "chrome/common/content_settings.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "components/content_settings/core/common/content_settings_types.h" | 16 #include "components/content_settings/core/common/content_settings_types.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "content/public/test/mock_render_process_host.h" | 18 #include "content/public/test/mock_render_process_host.h" |
18 #include "content/public/test/web_contents_tester.h" | 19 #include "content/public/test/web_contents_tester.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { | 22 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { |
22 protected: | 23 protected: |
23 PermissionContextBaseTests() {} | 24 PermissionContextBaseTests() {} |
24 virtual ~PermissionContextBaseTests() {} | 25 virtual ~PermissionContextBaseTests() {} |
25 | 26 |
27 // Accept or dismiss the permission bubble or infobar. | |
28 void RespondToPermission(const PermissionRequestID& id, | |
29 const GURL& url, | |
30 bool accept) { | |
31 if (!PermissionBubbleManager::Enabled()) { | |
32 permission_context.GetInfoBarController()->OnPermissionSet( | |
33 id, url, url, accept, accept); | |
Bernhard Bauer
2014/08/13 21:30:31
You could return here to remove a level of indenta
Greg Billock
2014/08/13 22:12:23
Done.
| |
34 } else { | |
35 PermissionBubbleManager* manager = | |
36 PermissionBubbleManager::FromWebContents(web_contents()); | |
37 if (accept) | |
38 manager->Accept(); | |
39 else | |
40 manager->Closing(); | |
41 } | |
42 } | |
43 | |
26 private: | 44 private: |
27 // ChromeRenderViewHostTestHarness: | 45 // ChromeRenderViewHostTestHarness: |
28 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
29 ChromeRenderViewHostTestHarness::SetUp(); | 47 ChromeRenderViewHostTestHarness::SetUp(); |
30 InfoBarService::CreateForWebContents(web_contents()); | 48 InfoBarService::CreateForWebContents(web_contents()); |
49 PermissionBubbleManager::CreateForWebContents(web_contents()); | |
31 } | 50 } |
32 | 51 |
33 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 52 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); |
34 }; | 53 }; |
35 | 54 |
36 class TestPermissionContext : public PermissionContextBase { | 55 class TestPermissionContext : public PermissionContextBase { |
37 public: | 56 public: |
38 TestPermissionContext(Profile* profile, | 57 TestPermissionContext(Profile* profile, |
39 const ContentSettingsType permission_type) | 58 const ContentSettingsType permission_type) |
40 : PermissionContextBase(profile, permission_type), | 59 : PermissionContextBase(profile, permission_type), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 const PermissionRequestID id( | 108 const PermissionRequestID id( |
90 web_contents()->GetRenderProcessHost()->GetID(), | 109 web_contents()->GetRenderProcessHost()->GetID(), |
91 web_contents()->GetRenderViewHost()->GetRoutingID(), | 110 web_contents()->GetRenderViewHost()->GetRoutingID(), |
92 -1, GURL()); | 111 -1, GURL()); |
93 permission_context.RequestPermission( | 112 permission_context.RequestPermission( |
94 web_contents(), | 113 web_contents(), |
95 id, url, true, | 114 id, url, true, |
96 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 115 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
97 base::Unretained(&permission_context))); | 116 base::Unretained(&permission_context))); |
98 | 117 |
99 permission_context.GetInfoBarController()->OnPermissionSet( | 118 RespondToPermission(id, url, true); |
100 id, url, url, true, true); | |
101 EXPECT_TRUE(permission_context.permission_set()); | 119 EXPECT_TRUE(permission_context.permission_set()); |
102 EXPECT_TRUE(permission_context.permission_granted()); | 120 EXPECT_TRUE(permission_context.permission_granted()); |
103 EXPECT_TRUE(permission_context.tab_context_updated()); | 121 EXPECT_TRUE(permission_context.tab_context_updated()); |
104 | 122 |
105 ContentSetting setting = | 123 ContentSetting setting = |
106 profile()->GetHostContentSettingsMap()->GetContentSetting( | 124 profile()->GetHostContentSettingsMap()->GetContentSetting( |
107 url.GetOrigin(), url.GetOrigin(), | 125 url.GetOrigin(), url.GetOrigin(), |
108 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()); | 126 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()); |
109 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); | 127 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); |
110 }; | 128 }; |
111 | 129 |
112 // Simulates clicking Dismiss (X in the infobar. | 130 // Simulates clicking Dismiss (X in the infobar. |
113 // The permission should be denied but not saved for future use. | 131 // The permission should be denied but not saved for future use. |
114 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { | 132 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { |
115 TestPermissionContext permission_context(profile(), | 133 TestPermissionContext permission_context(profile(), |
116 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 134 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
117 GURL url("http://www.google.es"); | 135 GURL url("http://www.google.es"); |
118 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 136 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
119 | 137 |
120 const PermissionRequestID id( | 138 const PermissionRequestID id( |
121 web_contents()->GetRenderProcessHost()->GetID(), | 139 web_contents()->GetRenderProcessHost()->GetID(), |
122 web_contents()->GetRenderViewHost()->GetRoutingID(), | 140 web_contents()->GetRenderViewHost()->GetRoutingID(), |
123 -1, GURL()); | 141 -1, GURL()); |
124 permission_context.RequestPermission( | 142 permission_context.RequestPermission( |
125 web_contents(), | 143 web_contents(), |
126 id, url, true, | 144 id, url, true, |
127 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 145 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
128 base::Unretained(&permission_context))); | 146 base::Unretained(&permission_context))); |
129 | 147 |
130 permission_context.GetInfoBarController()->OnPermissionSet( | 148 RespondToPermission(false); |
Bernhard Bauer
2014/08/13 21:30:31
Missing parameters?
Greg Billock
2014/08/13 22:12:23
yeah, I thought I compiled this, but obviously not
| |
131 id, url, url, false, false); | |
132 EXPECT_TRUE(permission_context.permission_set()); | 149 EXPECT_TRUE(permission_context.permission_set()); |
133 EXPECT_FALSE(permission_context.permission_granted()); | 150 EXPECT_FALSE(permission_context.permission_granted()); |
134 EXPECT_TRUE(permission_context.tab_context_updated()); | 151 EXPECT_TRUE(permission_context.tab_context_updated()); |
135 | 152 |
136 ContentSetting setting = | 153 ContentSetting setting = |
137 profile()->GetHostContentSettingsMap()->GetContentSetting( | 154 profile()->GetHostContentSettingsMap()->GetContentSetting( |
138 url.GetOrigin(), url.GetOrigin(), | 155 url.GetOrigin(), url.GetOrigin(), |
139 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); | 156 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); |
140 EXPECT_EQ(CONTENT_SETTING_ASK , setting); | 157 EXPECT_EQ(CONTENT_SETTING_ASK , setting); |
141 }; | 158 }; |
OLD | NEW |