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

Side by Side Diff: chrome/browser/content_settings/permission_context_base_unittest.cc

Issue 411503005: Change tests to prepare for turning on the permission bubble flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_permission_request.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
12 #include "chrome/common/content_settings.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
13 #include "components/content_settings/core/common/content_settings.h" 15 #include "components/content_settings/core/common/content_settings.h"
14 #include "components/content_settings/core/common/content_settings_types.h" 16 #include "components/content_settings/core/common/content_settings_types.h"
15 #include "components/content_settings/core/common/permission_request_id.h" 17 #include "components/content_settings/core/common/permission_request_id.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/mock_render_process_host.h" 19 #include "content/public/test/mock_render_process_host.h"
18 #include "content/public/test/web_contents_tester.h" 20 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool allowed) override { 73 bool allowed) override {
72 tab_context_updated_ = true; 74 tab_context_updated_ = true;
73 } 75 }
74 76
75 private: 77 private:
76 bool permission_set_; 78 bool permission_set_;
77 bool permission_granted_; 79 bool permission_granted_;
78 bool tab_context_updated_; 80 bool tab_context_updated_;
79 }; 81 };
80 82
83 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
84 protected:
85 PermissionContextBaseTests() {}
86 virtual ~PermissionContextBaseTests() {}
87
88 // Accept or dismiss the permission bubble or infobar.
89 void RespondToPermission(TestPermissionContext* context,
90 const PermissionRequestID& id,
91 const GURL& url,
92 bool accept) {
93 if (!PermissionBubbleManager::Enabled()) {
94 context->GetInfoBarController()->OnPermissionSet(
95 id, url, url, accept, accept);
96 return;
97 }
98
99 PermissionBubbleManager* manager =
100 PermissionBubbleManager::FromWebContents(web_contents());
101 if (accept)
102 manager->Accept();
103 else
104 manager->Closing();
105 }
106
107 private:
108 // ChromeRenderViewHostTestHarness:
109 virtual void SetUp() OVERRIDE {
110 ChromeRenderViewHostTestHarness::SetUp();
111 InfoBarService::CreateForWebContents(web_contents());
112 PermissionBubbleManager::CreateForWebContents(web_contents());
113 }
114
115 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests);
116 };
117
81 // Simulates clicking Accept. The permission should be granted and 118 // Simulates clicking Accept. The permission should be granted and
82 // saved for future use. 119 // saved for future use.
83 TEST_F(PermissionContextBaseTests, TestAskAndGrant) { 120 TEST_F(PermissionContextBaseTests, TestAskAndGrant) {
84 TestPermissionContext permission_context(profile(), 121 TestPermissionContext permission_context(profile(),
85 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 122 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
86 GURL url("http://www.google.com"); 123 GURL url("http://www.google.com");
87 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 124 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
88 125
89 const PermissionRequestID id( 126 const PermissionRequestID id(
90 web_contents()->GetRenderProcessHost()->GetID(), 127 web_contents()->GetRenderProcessHost()->GetID(),
91 web_contents()->GetRenderViewHost()->GetRoutingID(), 128 web_contents()->GetRenderViewHost()->GetRoutingID(),
92 -1, GURL()); 129 -1, GURL());
93 permission_context.RequestPermission( 130 permission_context.RequestPermission(
94 web_contents(), 131 web_contents(),
95 id, url, true, 132 id, url, true,
96 base::Bind(&TestPermissionContext::TrackPermissionDecision, 133 base::Bind(&TestPermissionContext::TrackPermissionDecision,
97 base::Unretained(&permission_context))); 134 base::Unretained(&permission_context)));
98 135
99 permission_context.GetInfoBarController()->OnPermissionSet( 136 RespondToPermission(&permission_context, id, url, true);
100 id, url, url, true, true);
101 EXPECT_TRUE(permission_context.permission_set()); 137 EXPECT_TRUE(permission_context.permission_set());
102 EXPECT_TRUE(permission_context.permission_granted()); 138 EXPECT_TRUE(permission_context.permission_granted());
103 EXPECT_TRUE(permission_context.tab_context_updated()); 139 EXPECT_TRUE(permission_context.tab_context_updated());
104 140
105 ContentSetting setting = 141 ContentSetting setting =
106 profile()->GetHostContentSettingsMap()->GetContentSetting( 142 profile()->GetHostContentSettingsMap()->GetContentSetting(
107 url.GetOrigin(), url.GetOrigin(), 143 url.GetOrigin(), url.GetOrigin(),
108 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()); 144 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string());
109 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); 145 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting);
110 }; 146 };
111 147
112 // Simulates clicking Dismiss (X in the infobar. 148 // Simulates clicking Dismiss (X in the infobar.
113 // The permission should be denied but not saved for future use. 149 // The permission should be denied but not saved for future use.
114 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { 150 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) {
115 TestPermissionContext permission_context(profile(), 151 TestPermissionContext permission_context(profile(),
116 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 152 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
117 GURL url("http://www.google.es"); 153 GURL url("http://www.google.es");
118 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 154 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
119 155
120 const PermissionRequestID id( 156 const PermissionRequestID id(
121 web_contents()->GetRenderProcessHost()->GetID(), 157 web_contents()->GetRenderProcessHost()->GetID(),
122 web_contents()->GetRenderViewHost()->GetRoutingID(), 158 web_contents()->GetRenderViewHost()->GetRoutingID(),
123 -1, GURL()); 159 -1, GURL());
124 permission_context.RequestPermission( 160 permission_context.RequestPermission(
125 web_contents(), 161 web_contents(),
126 id, url, true, 162 id, url, true,
127 base::Bind(&TestPermissionContext::TrackPermissionDecision, 163 base::Bind(&TestPermissionContext::TrackPermissionDecision,
128 base::Unretained(&permission_context))); 164 base::Unretained(&permission_context)));
129 165
130 permission_context.GetInfoBarController()->OnPermissionSet( 166 RespondToPermission(&permission_context, id, url, false);
131 id, url, url, false, false);
132 EXPECT_TRUE(permission_context.permission_set()); 167 EXPECT_TRUE(permission_context.permission_set());
133 EXPECT_FALSE(permission_context.permission_granted()); 168 EXPECT_FALSE(permission_context.permission_granted());
134 EXPECT_TRUE(permission_context.tab_context_updated()); 169 EXPECT_TRUE(permission_context.tab_context_updated());
135 170
136 ContentSetting setting = 171 ContentSetting setting =
137 profile()->GetHostContentSettingsMap()->GetContentSetting( 172 profile()->GetHostContentSettingsMap()->GetContentSetting(
138 url.GetOrigin(), url.GetOrigin(), 173 url.GetOrigin(), url.GetOrigin(),
139 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); 174 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string());
140 EXPECT_EQ(CONTENT_SETTING_ASK , setting); 175 EXPECT_EQ(CONTENT_SETTING_ASK , setting);
141 }; 176 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_permission_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698