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

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view_unittest.cc

Issue 2011963002: PermissionSelectorView: use Combobox on MacViews builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Give up on SetPermissionInfo Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/website_settings/permissions_bubble_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/website_settings/website_settings_popup_view.h " 5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h "
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 8 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
9 #include "chrome/browser/ui/views/website_settings/chosen_object_view.h" 9 #include "chrome/browser/ui/views/website_settings/chosen_object_view.h"
10 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" 10 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h"
11 #include "chrome/browser/usb/usb_chooser_context.h" 11 #include "chrome/browser/usb/usb_chooser_context.h"
12 #include "chrome/browser/usb/usb_chooser_context_factory.h" 12 #include "chrome/browser/usb/usb_chooser_context_factory.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/common/ssl_status.h" 14 #include "content/public/common/ssl_status.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "content/public/test/test_web_contents_factory.h" 16 #include "content/public/test/test_web_contents_factory.h"
17 #include "device/core/device_client.h" 17 #include "device/core/device_client.h"
18 #include "device/usb/mock_usb_device.h" 18 #include "device/usb/mock_usb_device.h"
19 #include "device/usb/mock_usb_service.h" 19 #include "device/usb/mock_usb_service.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
22 #include "ui/views/controls/button/menu_button.h" 22 #include "ui/views/controls/button/menu_button.h"
23 #include "ui/views/controls/combobox/combobox.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 #include "ui/views/test/scoped_views_test_helper.h" 25 #include "ui/views/test/scoped_views_test_helper.h"
25 26
26 const char* kUrl = "http://www.example.com/index.html"; 27 const char* kUrl = "http://www.example.com/index.html";
27 28
28 namespace test { 29 namespace test {
29 30
30 class WebsiteSettingsPopupViewTestApi { 31 class WebsiteSettingsPopupViewTestApi {
31 public: 32 public:
32 WebsiteSettingsPopupViewTestApi(gfx::NativeView parent, 33 WebsiteSettingsPopupViewTestApi(gfx::NativeView parent,
(...skipping 18 matching lines...) Expand all
51 } 52 }
52 53
53 WebsiteSettingsPopupView* view() { return view_; } 54 WebsiteSettingsPopupView* view() { return view_; }
54 views::View* permissions_content() { return view_->permissions_content_; } 55 views::View* permissions_content() { return view_->permissions_content_; }
55 56
56 PermissionSelectorView* GetPermissionSelectorAt(int index) { 57 PermissionSelectorView* GetPermissionSelectorAt(int index) {
57 return static_cast<PermissionSelectorView*>( 58 return static_cast<PermissionSelectorView*>(
58 permissions_content()->child_at(index)); 59 permissions_content()->child_at(index));
59 } 60 }
60 61
61 views::MenuButton* GetPermissionButtonAt(int index) { 62 base::string16 GetPermissionButtonTextAt(int index) {
62 const int kButtonIndex = 2; // Button should be the third child. 63 const int kButtonIndex = 2; // Button should be the third child.
63 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); 64 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex);
64 EXPECT_EQ(views::MenuButton::kViewClassName, view->GetClassName()); 65 if (view->GetClassName() == views::MenuButton::kViewClassName) {
65 return static_cast<views::MenuButton*>(view); 66 return static_cast<views::MenuButton*>(view)->GetText();
67 } else if (view->GetClassName() == views::Combobox::kViewClassName) {
68 views::Combobox* combobox = static_cast<views::Combobox*>(view);
69 return combobox->GetTextForRow(combobox->GetSelectedRow());
70 } else {
71 NOTREACHED() << "Unknown class " << view->GetClassName();
72 return base::ASCIIToUTF16("");
73 }
66 } 74 }
67 75
68 // Simulates recreating the dialog with a new PermissionInfoList. 76 // Simulates recreating the dialog with a new PermissionInfoList.
69 void SetPermissionInfo(const PermissionInfoList& list) { 77 void SetPermissionInfo(const PermissionInfoList& list) {
70 for (const WebsiteSettingsPopupView::PermissionInfo& info : list) 78 for (const WebsiteSettingsPopupView::PermissionInfo& info : list)
71 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); 79 view_->presenter_->OnSitePermissionChanged(info.type, info.setting);
72 CreateView(); 80 CreateView();
73 } 81 }
74 82
75 private: 83 private:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 156
149 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget. 157 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget.
150 std::unique_ptr<test::WebsiteSettingsPopupViewTestApi> api_; 158 std::unique_ptr<test::WebsiteSettingsPopupViewTestApi> api_;
151 159
152 private: 160 private:
153 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupViewTest); 161 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupViewTest);
154 }; 162 };
155 163
156 } // namespace 164 } // namespace
157 165
166 // TODO(ellyjones): re-enable this test for OSX.
167 // This test exercises PermissionSelectorView in a way that it is not used in
168 // practice. In practice, every setting in PermissionSelectorView starts off
169 // "set", so there is always one option checked in the resulting MenuModel. This
170 // test creates settings that are left at their defaults, leading to zero
171 // checked options, and checks that the text on the MenuButtons is right. Since
172 // the Comboboxes the MacViews version of this dialog uses don't have separate
173 // text, this test doesn't work.
174 #if defined(OS_MACOSX)
175 #define MAYBE_SetPermissionInfo DISABLED_SetPermissionInfo
176 #else
177 #define MAYBE_SetPermissionInfo SetPermissionInfo
178 #endif
179
158 // Test UI construction and reconstruction via 180 // Test UI construction and reconstruction via
159 // WebsiteSettingsPopupView::SetPermissionInfo(). 181 // WebsiteSettingsPopupView::SetPermissionInfo().
160 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfo) { 182 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) {
161 PermissionInfoList list(1); 183 PermissionInfoList list(1);
162 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; 184 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION;
163 list.back().source = content_settings::SETTING_SOURCE_USER; 185 list.back().source = content_settings::SETTING_SOURCE_USER;
164 list.back().is_incognito = false; 186 list.back().is_incognito = false;
187 list.back().setting = CONTENT_SETTING_DEFAULT;
165 188
166 const int kExpectedChildren = 189 const int kExpectedChildren =
167 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; 190 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13;
168 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 191 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
169 192
170 list.back().setting = CONTENT_SETTING_ALLOW; 193 list.back().setting = CONTENT_SETTING_ALLOW;
171 api_->SetPermissionInfo(list); 194 api_->SetPermissionInfo(list);
172 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 195 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
173 196
174 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); 197 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0);
175 EXPECT_EQ(3, selector->child_count()); 198 EXPECT_EQ(3, selector->child_count());
176 199
177 // Verify labels match the settings on the PermissionInfoList. 200 // Verify labels match the settings on the PermissionInfoList.
178 const int kLabelIndex = 1; 201 const int kLabelIndex = 1;
179 EXPECT_EQ(views::Label::kViewClassName, 202 EXPECT_EQ(views::Label::kViewClassName,
180 selector->child_at(kLabelIndex)->GetClassName()); 203 selector->child_at(kLabelIndex)->GetClassName());
181 views::Label* label = 204 views::Label* label =
182 static_cast<views::Label*>(selector->child_at(kLabelIndex)); 205 static_cast<views::Label*>(selector->child_at(kLabelIndex));
183 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); 206 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text());
184 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), 207 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"),
185 api_->GetPermissionButtonAt(0)->GetText()); 208 api_->GetPermissionButtonTextAt(0));
186 209
187 // Verify calling SetPermisisonInfo() directly updates the UI. 210 // Verify calling SetPermisisonInfo() directly updates the UI.
188 list.back().setting = CONTENT_SETTING_BLOCK; 211 list.back().setting = CONTENT_SETTING_BLOCK;
189 api_->SetPermissionInfo(list); 212 api_->SetPermissionInfo(list);
190 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), 213 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"),
191 api_->GetPermissionButtonAt(0)->GetText()); 214 api_->GetPermissionButtonTextAt(0));
192 215
193 // Simulate a user selection via the UI. Note this will also cover logic in 216 // Simulate a user selection via the UI. Note this will also cover logic in
194 // WebsiteSettings to update the pref. 217 // WebsiteSettings to update the pref.
195 list.back().setting = CONTENT_SETTING_ALLOW; 218 list.back().setting = CONTENT_SETTING_ALLOW;
196 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); 219 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back());
197 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 220 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
198 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), 221 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"),
199 api_->GetPermissionButtonAt(0)->GetText()); 222 api_->GetPermissionButtonTextAt(0));
200 223
201 // Setting to the default via the UI should keep the button around. 224 // Setting to the default via the UI should keep the button around.
202 list.back().setting = CONTENT_SETTING_ASK; 225 list.back().setting = CONTENT_SETTING_ASK;
203 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); 226 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back());
204 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 227 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
205 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), 228 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"),
206 api_->GetPermissionButtonAt(0)->GetText()); 229 api_->GetPermissionButtonTextAt(0));
207 230
208 // However, since the setting is now default, recreating the dialog with those 231 // However, since the setting is now default, recreating the dialog with those
209 // settings should omit the permission from the UI. 232 // settings should omit the permission from the UI.
210 api_->SetPermissionInfo(list); 233 api_->SetPermissionInfo(list);
211 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 234 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
212 } 235 }
213 236
214 // Test UI construction and reconstruction with USB devices. 237 // Test UI construction and reconstruction with USB devices.
215 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { 238 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) {
216 const int kExpectedChildren = 239 const int kExpectedChildren =
(...skipping 27 matching lines...) Expand all
244 267
245 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 268 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
246 ui::EventTimeForNow(), 0, 0); 269 ui::EventTimeForNow(), 0, 0);
247 views::ButtonListener* button_listener = 270 views::ButtonListener* button_listener =
248 static_cast<views::ButtonListener*>(object_view); 271 static_cast<views::ButtonListener*>(object_view);
249 button_listener->ButtonPressed(button, event); 272 button_listener->ButtonPressed(button, event);
250 api_->SetPermissionInfo(list); 273 api_->SetPermissionInfo(list);
251 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); 274 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
252 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); 275 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device));
253 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/website_settings/permissions_bubble_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698