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