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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc

Issue 10584042: Bring up a content settings icon for ungestured registerProtocolHandler call. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Repair merge Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/content_settings.h"
14 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
17 #include "content/public/test/web_contents_tester.h" 20 #include "content/public/test/web_contents_tester.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 22
20 using content::BrowserThread; 23 using content::BrowserThread;
21 using content::WebContentsTester; 24 using content::WebContentsTester;
22 25
23 class ContentSettingBubbleModelTest : public TabContentsTestHarness { 26 class ContentSettingBubbleModelTest : public TabContentsTestHarness {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 std::string file_url("file:///tmp/test.html"); 216 std::string file_url("file:///tmp/test.html");
214 NavigateAndCommit(GURL(file_url)); 217 NavigateAndCommit(GURL(file_url));
215 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 218 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
216 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 219 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
217 NULL, tab_contents(), profile(), 220 NULL, tab_contents(), profile(),
218 CONTENT_SETTINGS_TYPE_IMAGES)); 221 CONTENT_SETTINGS_TYPE_IMAGES));
219 std::string title = 222 std::string title =
220 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; 223 content_setting_bubble_model->bubble_content().radio_group.radio_items[0];
221 ASSERT_NE(std::string::npos, title.find(file_url)); 224 ASSERT_NE(std::string::npos, title.find(file_url));
222 } 225 }
226
227 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) {
228 const GURL page_url("http://toplevel.example/");
229 NavigateAndCommit(page_url);
230 TabSpecificContentSettings* content_settings =
231 tab_contents()->content_settings();
232 content_settings->set_pending_protocol_handler(
233 ProtocolHandler::CreateProtocolHandler("mailto",
234 GURL("http://www.toplevel.example/"), ASCIIToUTF16("Handler")));
235
236 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
237 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
238 NULL, tab_contents(), profile(),
239 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS));
240 const ContentSettingBubbleModel::BubbleContent& bubble_content =
241 content_setting_bubble_model->bubble_content();
242 EXPECT_FALSE(bubble_content.title.empty());
243 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty());
244 EXPECT_TRUE(bubble_content.popup_items.empty());
245 EXPECT_TRUE(bubble_content.domain_lists.empty());
246 EXPECT_TRUE(bubble_content.custom_link.empty());
247 EXPECT_FALSE(bubble_content.custom_link_enabled);
248 EXPECT_FALSE(bubble_content.manage_link.empty());
249 }
250
251 TEST_F(ContentSettingBubbleModelTest, RPHAllow) {
252 profile()->CreateProtocolHandlerRegistry();
253
254 const GURL page_url("http://toplevel.example/");
255 NavigateAndCommit(page_url);
256 TabSpecificContentSettings* content_settings =
257 tab_contents()->content_settings();
258 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler(
259 "mailto", GURL("http://www.toplevel.example/"),
260 ASCIIToUTF16("Handler"));
261 content_settings->set_pending_protocol_handler(test_handler);
262
263 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
264 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
265 NULL, tab_contents(), profile(),
266 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS));
267
268 {
269 ProtocolHandler handler =
270 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto");
271 EXPECT_TRUE(handler.IsEmpty());
272 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
273 content_settings->pending_protocol_handler_setting());
274 }
275
276 // "0" is the "Allow" radio button.
277 content_setting_bubble_model->OnRadioClicked(0);
278 {
279 ProtocolHandler handler =
280 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto");
281 ASSERT_FALSE(handler.IsEmpty());
282 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title());
283 EXPECT_EQ(CONTENT_SETTING_ALLOW,
284 content_settings->pending_protocol_handler_setting());
285 }
286
287 // "1" is the "Deny" radio button.
288 content_setting_bubble_model->OnRadioClicked(1);
289 {
290 ProtocolHandler handler =
291 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto");
292 EXPECT_TRUE(handler.IsEmpty());
293 EXPECT_EQ(CONTENT_SETTING_BLOCK,
294 content_settings->pending_protocol_handler_setting());
295 }
296
297 // "2" is the "Ignore button.
298 content_setting_bubble_model->OnRadioClicked(2);
299 {
300 ProtocolHandler handler =
301 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto");
302 EXPECT_TRUE(handler.IsEmpty());
303 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
304 content_settings->pending_protocol_handler_setting());
305 EXPECT_TRUE(profile()->GetProtocolHandlerRegistry()->IsIgnored(
306 test_handler));
307 }
308
309 // "0" is the "Allow" radio button.
310 content_setting_bubble_model->OnRadioClicked(0);
311 {
312 ProtocolHandler handler =
313 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto");
314 ASSERT_FALSE(handler.IsEmpty());
315 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title());
316 EXPECT_EQ(CONTENT_SETTING_ALLOW,
317 content_settings->pending_protocol_handler_setting());
318 EXPECT_FALSE(profile()->GetProtocolHandlerRegistry()->IsIgnored(
319 test_handler));
320 }
321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698