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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/website_settings/permission_menu_model.h"
6 #include "chrome/grit/generated_resources.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/l10n/l10n_util.h"
14 TestCallback() : current_(-1) {}
16 PermissionMenuModel::ChangeCallback
callback() {
17 return base::Bind(&TestCallback::PermissionChanged
, base::Unretained(this));
19 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo
& permission
) {
20 current_
= permission
.setting
;
28 TEST(PermissionMenuModelTest
, TestDefault
) {
29 TestCallback callback
;
30 WebsiteSettingsUI::PermissionInfo permission
;
31 permission
.type
= CONTENT_SETTINGS_TYPE_COOKIES
;
32 permission
.setting
= CONTENT_SETTING_ALLOW
;
33 permission
.default_setting
= CONTENT_SETTING_ALLOW
;
34 PermissionMenuModel
model(
35 GURL("http://www.google.com"), permission
, callback
.callback());
36 EXPECT_EQ(3, model
.GetItemCount());
39 TEST(PermissionMenuModelTest
, TestDefaultMediaHttp
) {
40 TestCallback callback
;
41 WebsiteSettingsUI::PermissionInfo permission
;
42 permission
.type
= CONTENT_SETTINGS_TYPE_MEDIASTREAM
;
43 permission
.setting
= CONTENT_SETTING_ALLOW
;
44 permission
.default_setting
= CONTENT_SETTING_ALLOW
;
45 PermissionMenuModel
model(
46 GURL("http://www.google.com"), permission
, callback
.callback());
47 EXPECT_EQ(2, model
.GetItemCount());
50 TEST(PermissionMenuModelTest
, TestAllowBlock
) {
51 TestCallback callback
;
52 PermissionMenuModel
model(GURL("http://www.google.com"),
53 CONTENT_SETTING_ALLOW
,
55 EXPECT_EQ(2, model
.GetItemCount());
58 TEST(PermissionMenuModelTest
, TestFullscreenMouseLockFileUrl
) {
59 TestCallback callback
;
60 WebsiteSettingsUI::PermissionInfo permission
;
61 permission
.type
= CONTENT_SETTINGS_TYPE_FULLSCREEN
;
62 permission
.setting
= CONTENT_SETTING_ASK
;
63 permission
.default_setting
= CONTENT_SETTING_ASK
;
64 PermissionMenuModel
fullscreen_model(GURL("file:///test.html"), permission
,
66 EXPECT_EQ(1, fullscreen_model
.GetItemCount());
68 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK
),
69 fullscreen_model
.GetLabelAt(0));
71 permission
.type
= CONTENT_SETTINGS_TYPE_MOUSELOCK
;
72 PermissionMenuModel
mouselock_model(GURL("file:///test.html"), permission
,
74 EXPECT_EQ(1, mouselock_model
.GetItemCount());
76 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK
),
77 fullscreen_model
.GetLabelAt(0));