Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_view() { return view_->permissions_view_; } | 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*>( |
|
sky
2017/03/07 22:03:40
Do you need this cast?
Elly Fong-Jones
2017/03/08 18:41:09
Nope, deleted.
| |
| 60 permissions_view()->child_at(index)); | 60 view_->selector_rows_.at(index).get()); |
|
sky
2017/03/07 22:03:40
.at(index) -> [index] ?
Elly Fong-Jones
2017/03/08 18:41:09
Done.
| |
| 61 } | |
| 62 | |
| 63 base::string16 GetPermissionLabelTextAt(int index) { | |
| 64 views::View* view = GetPermissionSelectorAt(index)->label_; | |
| 65 if (view->GetClassName() == views::Label::kViewClassName) | |
|
sky
2017/03/07 22:03:40
This is subtle and worth a comment.
Elly Fong-Jones
2017/03/08 18:41:09
Done.
| |
| 66 return static_cast<views::Label*>(view)->text(); | |
| 67 return base::string16(); | |
| 61 } | 68 } |
| 62 | 69 |
| 63 base::string16 GetPermissionButtonTextAt(int index) { | 70 base::string16 GetPermissionButtonTextAt(int index) { |
| 64 const int kButtonIndex = 2; // Button should be the third child. | 71 views::View* view = GetPermissionSelectorAt(index)->button(); |
| 65 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); | |
| 66 if (view->GetClassName() == views::MenuButton::kViewClassName) { | 72 if (view->GetClassName() == views::MenuButton::kViewClassName) { |
| 67 return static_cast<views::MenuButton*>(view)->GetText(); | 73 return static_cast<views::MenuButton*>(view)->GetText(); |
| 68 } else if (view->GetClassName() == views::Combobox::kViewClassName) { | 74 } else if (view->GetClassName() == views::Combobox::kViewClassName) { |
| 69 views::Combobox* combobox = static_cast<views::Combobox*>(view); | 75 views::Combobox* combobox = static_cast<views::Combobox*>(view); |
| 70 return combobox->GetTextForRow(combobox->GetSelectedRow()); | 76 return combobox->GetTextForRow(combobox->GetSelectedRow()); |
| 71 } else { | 77 } else { |
| 72 NOTREACHED() << "Unknown class " << view->GetClassName(); | 78 NOTREACHED() << "Unknown class " << view->GetClassName(); |
| 73 return base::string16(); | 79 return base::string16(); |
| 74 } | 80 } |
| 75 } | 81 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // Test UI construction and reconstruction via | 174 // Test UI construction and reconstruction via |
| 169 // WebsiteSettingsPopupView::SetPermissionInfo(). | 175 // WebsiteSettingsPopupView::SetPermissionInfo(). |
| 170 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { | 176 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { |
| 171 PermissionInfoList list(1); | 177 PermissionInfoList list(1); |
| 172 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 178 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
| 173 list.back().source = content_settings::SETTING_SOURCE_USER; | 179 list.back().source = content_settings::SETTING_SOURCE_USER; |
| 174 list.back().is_incognito = false; | 180 list.back().is_incognito = false; |
| 175 list.back().setting = CONTENT_SETTING_DEFAULT; | 181 list.back().setting = CONTENT_SETTING_DEFAULT; |
| 176 | 182 |
| 177 const int kExpectedChildren = | 183 const int kExpectedChildren = |
| 178 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; | 184 3 * (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); |
|
sky
2017/03/07 22:03:40
The 3 is subtle and worth a comment. I suggest a c
Elly Fong-Jones
2017/03/08 18:41:09
Done.
| |
| 179 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 185 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 180 | 186 |
| 181 list.back().setting = CONTENT_SETTING_ALLOW; | 187 list.back().setting = CONTENT_SETTING_ALLOW; |
| 182 api_->SetPermissionInfo(list); | 188 api_->SetPermissionInfo(list); |
| 183 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 189 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 184 | 190 |
| 185 PermissionSelectorRow* selector = api_->GetPermissionSelectorAt(0); | 191 PermissionSelectorRow* selector = api_->GetPermissionSelectorAt(0); |
| 186 EXPECT_EQ(3, selector->child_count()); | 192 EXPECT_NE(nullptr, selector); |
|
sky
2017/03/07 22:03:40
EXPECT(selector)?
Elly Fong-Jones
2017/03/08 18:41:09
Done.
| |
| 187 | 193 |
| 188 // Verify labels match the settings on the PermissionInfoList. | 194 // Verify labels match the settings on the PermissionInfoList. |
| 189 const int kLabelIndex = 1; | 195 EXPECT_EQ(base::ASCIIToUTF16("Location"), api_->GetPermissionLabelTextAt(0)); |
| 190 EXPECT_EQ(views::Label::kViewClassName, | |
| 191 selector->child_at(kLabelIndex)->GetClassName()); | |
| 192 views::Label* label = | |
| 193 static_cast<views::Label*>(selector->child_at(kLabelIndex)); | |
| 194 EXPECT_EQ(base::ASCIIToUTF16("Location"), label->text()); | |
| 195 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); | 196 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
| 196 | 197 |
| 197 // Verify calling SetPermisisonInfo() directly updates the UI. | 198 // Verify calling SetPermisisonInfo() directly updates the UI. |
| 198 list.back().setting = CONTENT_SETTING_BLOCK; | 199 list.back().setting = CONTENT_SETTING_BLOCK; |
| 199 api_->SetPermissionInfo(list); | 200 api_->SetPermissionInfo(list); |
| 200 EXPECT_EQ(base::ASCIIToUTF16("Block"), api_->GetPermissionButtonTextAt(0)); | 201 EXPECT_EQ(base::ASCIIToUTF16("Block"), api_->GetPermissionButtonTextAt(0)); |
| 201 | 202 |
| 202 // Simulate a user selection via the UI. Note this will also cover logic in | 203 // Simulate a user selection via the UI. Note this will also cover logic in |
| 203 // WebsiteSettings to update the pref. | 204 // WebsiteSettings to update the pref. |
| 204 list.back().setting = CONTENT_SETTING_ALLOW; | 205 list.back().setting = CONTENT_SETTING_ALLOW; |
| 205 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 206 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 206 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 207 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 207 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); | 208 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
| 208 | 209 |
| 209 // Setting to the default via the UI should keep the button around. | 210 // Setting to the default via the UI should keep the button around. |
| 210 list.back().setting = CONTENT_SETTING_ASK; | 211 list.back().setting = CONTENT_SETTING_ASK; |
| 211 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 212 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 212 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 213 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 213 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); | 214 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); |
| 214 | 215 |
| 215 // However, since the setting is now default, recreating the dialog with those | 216 // However, since the setting is now default, recreating the dialog with those |
| 216 // settings should omit the permission from the UI. | 217 // settings should omit the permission from the UI. |
| 217 api_->SetPermissionInfo(list); | 218 api_->SetPermissionInfo(list); |
| 218 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 219 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Test UI construction and reconstruction with USB devices. | 222 // Test UI construction and reconstruction with USB devices. |
| 222 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { | 223 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { |
| 223 const int kExpectedChildren = | 224 const int kExpectedChildren = |
| 224 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; | 225 3 * (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); |
| 225 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 226 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 226 | 227 |
| 227 const GURL origin = GURL(kUrl).GetOrigin(); | 228 const GURL origin = GURL(kUrl).GetOrigin(); |
| 228 scoped_refptr<device::UsbDevice> device = | 229 scoped_refptr<device::UsbDevice> device = |
| 229 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 230 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
| 230 device_client_.usb_service()->AddDevice(device); | 231 device_client_.usb_service()->AddDevice(device); |
| 231 UsbChooserContext* store = | 232 UsbChooserContext* store = |
| 232 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); | 233 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); |
| 233 store->GrantDevicePermission(origin, origin, device->guid()); | 234 store->GrantDevicePermission(origin, origin, device->guid()); |
| 234 | 235 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 251 | 252 |
| 252 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 253 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 253 ui::EventTimeForNow(), 0, 0); | 254 ui::EventTimeForNow(), 0, 0); |
| 254 views::ButtonListener* button_listener = | 255 views::ButtonListener* button_listener = |
| 255 static_cast<views::ButtonListener*>(object_view); | 256 static_cast<views::ButtonListener*>(object_view); |
| 256 button_listener->ButtonPressed(button, event); | 257 button_listener->ButtonPressed(button, event); |
| 257 api_->SetPermissionInfo(list); | 258 api_->SetPermissionInfo(list); |
| 258 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 259 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 259 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 260 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
| 260 } | 261 } |
| OLD | NEW |