OLD | NEW |
---|---|
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 "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
10 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" | 10 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 view_->GetWidget()->CloseNow(); | 46 view_->GetWidget()->CloseNow(); |
47 | 47 |
48 security_state::SecurityStateModel::SecurityInfo security_info; | 48 security_state::SecurityStateModel::SecurityInfo security_info; |
49 views::View* anchor_view = nullptr; | 49 views::View* anchor_view = nullptr; |
50 view_ = | 50 view_ = |
51 new WebsiteSettingsPopupView(anchor_view, parent_, profile_, | 51 new WebsiteSettingsPopupView(anchor_view, parent_, profile_, |
52 web_contents_, GURL(kUrl), security_info); | 52 web_contents_, GURL(kUrl), security_info); |
53 } | 53 } |
54 | 54 |
55 WebsiteSettingsPopupView* view() { return view_; } | 55 WebsiteSettingsPopupView* view() { return view_; } |
56 views::View* permissions_content() { return view_->permissions_content_; } | 56 views::View* permissions_view() { return view_->permissions_view_; } |
57 | 57 |
58 PermissionSelectorRow* GetPermissionSelectorAt(int index) { | 58 PermissionSelectorRow* GetPermissionSelectorAt(int index) { |
59 return static_cast<PermissionSelectorRow*>( | 59 return static_cast<PermissionSelectorRow*>( |
60 permissions_content()->child_at(index)); | 60 permissions_view()->child_at(index)); |
61 } | 61 } |
62 | 62 |
63 base::string16 GetPermissionButtonTextAt(int index) { | 63 base::string16 GetPermissionButtonTextAt(int index) { |
64 const int kButtonIndex = 2; // Button should be the third child. | 64 const int kButtonIndex = 2; // Button should be the third child. |
65 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); | 65 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); |
66 if (view->GetClassName() == views::MenuButton::kViewClassName) { | 66 if (view->GetClassName() == views::MenuButton::kViewClassName) { |
67 return static_cast<views::MenuButton*>(view)->GetText(); | 67 return static_cast<views::MenuButton*>(view)->GetText(); |
68 } else if (view->GetClassName() == views::Combobox::kViewClassName) { | 68 } else if (view->GetClassName() == views::Combobox::kViewClassName) { |
69 views::Combobox* combobox = static_cast<views::Combobox*>(view); | 69 views::Combobox* combobox = static_cast<views::Combobox*>(view); |
70 return combobox->GetTextForRow(combobox->GetSelectedRow()); | 70 return combobox->GetTextForRow(combobox->GetSelectedRow()); |
71 } else { | 71 } else { |
72 NOTREACHED() << "Unknown class " << view->GetClassName(); | 72 NOTREACHED() << "Unknown class " << view->GetClassName(); |
73 return base::ASCIIToUTF16(""); | 73 return base::ASCIIToUTF16(""); |
msw
2016/10/08 16:15:25
optional nit: return base::string16();
| |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 // Simulates recreating the dialog with a new PermissionInfoList. | 77 // Simulates recreating the dialog with a new PermissionInfoList. |
78 void SetPermissionInfo(const PermissionInfoList& list) { | 78 void SetPermissionInfo(const PermissionInfoList& list) { |
79 for (const WebsiteSettingsPopupView::PermissionInfo& info : list) | 79 for (const WebsiteSettingsPopupView::PermissionInfo& info : list) |
80 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); | 80 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); |
81 CreateView(); | 81 CreateView(); |
82 } | 82 } |
83 | 83 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // WebsiteSettingsPopupView::SetPermissionInfo(). | 169 // WebsiteSettingsPopupView::SetPermissionInfo(). |
170 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { | 170 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { |
171 PermissionInfoList list(1); | 171 PermissionInfoList list(1); |
172 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 172 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
173 list.back().source = content_settings::SETTING_SOURCE_USER; | 173 list.back().source = content_settings::SETTING_SOURCE_USER; |
174 list.back().is_incognito = false; | 174 list.back().is_incognito = false; |
175 list.back().setting = CONTENT_SETTING_DEFAULT; | 175 list.back().setting = CONTENT_SETTING_DEFAULT; |
176 | 176 |
177 const int kExpectedChildren = | 177 const int kExpectedChildren = |
178 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; | 178 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; |
179 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 179 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
180 | 180 |
181 list.back().setting = CONTENT_SETTING_ALLOW; | 181 list.back().setting = CONTENT_SETTING_ALLOW; |
182 api_->SetPermissionInfo(list); | 182 api_->SetPermissionInfo(list); |
183 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 183 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
184 | 184 |
185 PermissionSelectorRow* selector = api_->GetPermissionSelectorAt(0); | 185 PermissionSelectorRow* selector = api_->GetPermissionSelectorAt(0); |
186 EXPECT_EQ(3, selector->child_count()); | 186 EXPECT_EQ(3, selector->child_count()); |
187 | 187 |
188 // Verify labels match the settings on the PermissionInfoList. | 188 // Verify labels match the settings on the PermissionInfoList. |
189 const int kLabelIndex = 1; | 189 const int kLabelIndex = 1; |
190 EXPECT_EQ(views::Label::kViewClassName, | 190 EXPECT_EQ(views::Label::kViewClassName, |
191 selector->child_at(kLabelIndex)->GetClassName()); | 191 selector->child_at(kLabelIndex)->GetClassName()); |
192 views::Label* label = | 192 views::Label* label = |
193 static_cast<views::Label*>(selector->child_at(kLabelIndex)); | 193 static_cast<views::Label*>(selector->child_at(kLabelIndex)); |
194 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); | 194 EXPECT_EQ(base::ASCIIToUTF16("Location"), label->text()); |
195 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); | 195 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
196 | 196 |
197 // Verify calling SetPermisisonInfo() directly updates the UI. | 197 // Verify calling SetPermisisonInfo() directly updates the UI. |
198 list.back().setting = CONTENT_SETTING_BLOCK; | 198 list.back().setting = CONTENT_SETTING_BLOCK; |
199 api_->SetPermissionInfo(list); | 199 api_->SetPermissionInfo(list); |
200 EXPECT_EQ(base::ASCIIToUTF16("Block"), api_->GetPermissionButtonTextAt(0)); | 200 EXPECT_EQ(base::ASCIIToUTF16("Block"), api_->GetPermissionButtonTextAt(0)); |
201 | 201 |
202 // Simulate a user selection via the UI. Note this will also cover logic in | 202 // Simulate a user selection via the UI. Note this will also cover logic in |
203 // WebsiteSettings to update the pref. | 203 // WebsiteSettings to update the pref. |
204 list.back().setting = CONTENT_SETTING_ALLOW; | 204 list.back().setting = CONTENT_SETTING_ALLOW; |
205 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 205 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
206 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 206 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
207 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); | 207 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
208 | 208 |
209 // Setting to the default via the UI should keep the button around. | 209 // Setting to the default via the UI should keep the button around. |
210 list.back().setting = CONTENT_SETTING_ASK; | 210 list.back().setting = CONTENT_SETTING_ASK; |
211 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 211 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
212 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 212 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
213 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); | 213 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); |
214 | 214 |
215 // However, since the setting is now default, recreating the dialog with those | 215 // However, since the setting is now default, recreating the dialog with those |
216 // settings should omit the permission from the UI. | 216 // settings should omit the permission from the UI. |
217 api_->SetPermissionInfo(list); | 217 api_->SetPermissionInfo(list); |
218 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 218 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
219 } | 219 } |
220 | 220 |
221 // Test UI construction and reconstruction with USB devices. | 221 // Test UI construction and reconstruction with USB devices. |
222 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { | 222 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { |
223 const int kExpectedChildren = | 223 const int kExpectedChildren = |
224 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; | 224 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; |
225 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 225 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
226 | 226 |
227 const GURL origin = GURL(kUrl).GetOrigin(); | 227 const GURL origin = GURL(kUrl).GetOrigin(); |
228 scoped_refptr<device::UsbDevice> device = | 228 scoped_refptr<device::UsbDevice> device = |
229 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 229 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
230 device_client_.usb_service()->AddDevice(device); | 230 device_client_.usb_service()->AddDevice(device); |
231 UsbChooserContext* store = | 231 UsbChooserContext* store = |
232 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); | 232 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); |
233 store->GrantDevicePermission(origin, origin, device->guid()); | 233 store->GrantDevicePermission(origin, origin, device->guid()); |
234 | 234 |
235 PermissionInfoList list; | 235 PermissionInfoList list; |
236 api_->SetPermissionInfo(list); | 236 api_->SetPermissionInfo(list); |
237 EXPECT_EQ(kExpectedChildren + 1, api_->permissions_content()->child_count()); | 237 EXPECT_EQ(kExpectedChildren + 1, api_->permissions_view()->child_count()); |
238 | 238 |
239 ChosenObjectRow* object_view = static_cast<ChosenObjectRow*>( | 239 ChosenObjectRow* object_view = static_cast<ChosenObjectRow*>( |
240 api_->permissions_content()->child_at(kExpectedChildren)); | 240 api_->permissions_view()->child_at(kExpectedChildren)); |
241 EXPECT_EQ(3, object_view->child_count()); | 241 EXPECT_EQ(3, object_view->child_count()); |
242 | 242 |
243 const int kLabelIndex = 1; | 243 const int kLabelIndex = 1; |
244 views::Label* label = | 244 views::Label* label = |
245 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); | 245 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); |
246 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); | 246 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); |
247 | 247 |
248 const int kButtonIndex = 2; | 248 const int kButtonIndex = 2; |
249 views::Button* button = | 249 views::Button* button = |
250 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); | 250 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); |
251 | 251 |
252 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 252 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
253 ui::EventTimeForNow(), 0, 0); | 253 ui::EventTimeForNow(), 0, 0); |
254 views::ButtonListener* button_listener = | 254 views::ButtonListener* button_listener = |
255 static_cast<views::ButtonListener*>(object_view); | 255 static_cast<views::ButtonListener*>(object_view); |
256 button_listener->ButtonPressed(button, event); | 256 button_listener->ButtonPressed(button, event); |
257 api_->SetPermissionInfo(list); | 257 api_->SetPermissionInfo(list); |
258 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 258 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
259 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 259 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
260 } | 260 } |
OLD | NEW |