OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | |
6 #include "chrome/grit/generated_resources.h" | |
7 #include "chrome/test/base/testing_profile.h" | |
8 #include "content/public/test/test_browser_thread_bundle.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 | |
12 namespace { | |
13 | |
14 class TestCallback { | |
15 public: | |
16 TestCallback() : current_(-1) {} | |
17 | |
18 PermissionMenuModel::ChangeCallback callback() { | |
19 return base::Bind(&TestCallback::PermissionChanged, base::Unretained(this)); | |
20 } | |
21 void PermissionChanged(const WebsiteSettingsUI::PermissionInfo& permission) { | |
22 current_ = permission.setting; | |
23 } | |
24 | |
25 int current_; | |
26 }; | |
27 | |
28 class PermissionMenuModelTest : public testing::Test { | |
29 protected: | |
30 TestingProfile* profile() { return &profile_; } | |
31 | |
32 private: | |
33 content::TestBrowserThreadBundle thread_bundle_; | |
34 TestingProfile profile_; | |
35 }; | |
36 | |
37 } // namespace | |
38 | |
39 TEST_F(PermissionMenuModelTest, TestDefault) { | |
40 TestCallback callback; | |
41 WebsiteSettingsUI::PermissionInfo permission; | |
42 permission.type = CONTENT_SETTINGS_TYPE_COOKIES; | |
43 permission.setting = CONTENT_SETTING_ALLOW; | |
44 permission.default_setting = CONTENT_SETTING_ALLOW; | |
45 permission.is_incognito = false; | |
46 PermissionMenuModel model(profile(), GURL("http://www.google.com"), | |
47 permission, callback.callback()); | |
48 EXPECT_EQ(3, model.GetItemCount()); | |
49 } | |
50 | |
51 TEST_F(PermissionMenuModelTest, TestDefaultMediaHttp) { | |
52 for (int i = 0; i < 2; ++i) { | |
53 ContentSettingsType type = i ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | |
54 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | |
55 TestCallback callback; | |
56 WebsiteSettingsUI::PermissionInfo permission; | |
57 permission.type = type; | |
58 permission.setting = CONTENT_SETTING_ALLOW; | |
59 permission.default_setting = CONTENT_SETTING_ALLOW; | |
60 permission.is_incognito = false; | |
61 PermissionMenuModel model(profile(), GURL("http://www.google.com"), | |
62 permission, callback.callback()); | |
63 EXPECT_EQ(2, model.GetItemCount()); | |
64 } | |
65 } | |
66 | |
67 TEST_F(PermissionMenuModelTest, TestAllowBlock) { | |
68 TestCallback callback; | |
69 PermissionMenuModel model(profile(), GURL("http://www.google.com"), | |
70 CONTENT_SETTING_ALLOW, callback.callback()); | |
71 EXPECT_EQ(2, model.GetItemCount()); | |
72 } | |
73 | |
74 TEST_F(PermissionMenuModelTest, TestIncognitoNotifications) { | |
75 TestCallback callback; | |
76 WebsiteSettingsUI::PermissionInfo permission; | |
77 permission.type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | |
78 permission.setting = CONTENT_SETTING_ASK; | |
79 permission.default_setting = CONTENT_SETTING_ASK; | |
80 | |
81 permission.is_incognito = false; | |
82 PermissionMenuModel regular_model(profile(), GURL("https://www.google.com"), | |
83 permission, callback.callback()); | |
84 EXPECT_EQ(3, regular_model.GetItemCount()); | |
85 | |
86 permission.is_incognito = true; | |
87 PermissionMenuModel incognito_model(profile(), GURL("https://www.google.com"), | |
88 permission, callback.callback()); | |
89 EXPECT_EQ(2, incognito_model.GetItemCount()); | |
90 } | |
OLD | NEW |