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