| 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/views/website_settings/chosen_object_view.h" | 8 #include "chrome/browser/ui/views/website_settings/chosen_object_view.h" |
| 9 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 9 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
| 10 #include "chrome/browser/usb/usb_chooser_context.h" | 10 #include "chrome/browser/usb/usb_chooser_context.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } // namespace | 157 } // namespace |
| 158 | 158 |
| 159 // Test UI construction and reconstruction via | 159 // Test UI construction and reconstruction via |
| 160 // WebsiteSettingsPopupView::SetPermissionInfo(). | 160 // WebsiteSettingsPopupView::SetPermissionInfo(). |
| 161 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfo) { | 161 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfo) { |
| 162 PermissionInfoList list(1); | 162 PermissionInfoList list(1); |
| 163 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 163 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
| 164 list.back().source = content_settings::SETTING_SOURCE_USER; | 164 list.back().source = content_settings::SETTING_SOURCE_USER; |
| 165 list.back().is_incognito = false; | 165 list.back().is_incognito = false; |
| 166 | 166 |
| 167 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 167 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 168 | 168 |
| 169 list.back().setting = CONTENT_SETTING_ALLOW; | 169 list.back().setting = CONTENT_SETTING_ALLOW; |
| 170 api_->SetPermissionInfo(list); | 170 api_->SetPermissionInfo(list); |
| 171 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 171 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 172 | 172 |
| 173 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); | 173 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); |
| 174 EXPECT_EQ(3, selector->child_count()); | 174 EXPECT_EQ(3, selector->child_count()); |
| 175 | 175 |
| 176 // Verify labels match the settings on the PermissionInfoList. | 176 // Verify labels match the settings on the PermissionInfoList. |
| 177 const int kLabelIndex = 1; | 177 const int kLabelIndex = 1; |
| 178 EXPECT_EQ(views::Label::kViewClassName, | 178 EXPECT_EQ(views::Label::kViewClassName, |
| 179 selector->child_at(kLabelIndex)->GetClassName()); | 179 selector->child_at(kLabelIndex)->GetClassName()); |
| 180 views::Label* label = | 180 views::Label* label = |
| 181 static_cast<views::Label*>(selector->child_at(kLabelIndex)); | 181 static_cast<views::Label*>(selector->child_at(kLabelIndex)); |
| 182 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); | 182 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); |
| 183 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), | 183 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), |
| 184 api_->GetPermissionButtonAt(0)->GetText()); | 184 api_->GetPermissionButtonAt(0)->GetText()); |
| 185 | 185 |
| 186 // Verify calling SetPermisisonInfo() directly updates the UI. | 186 // Verify calling SetPermisisonInfo() directly updates the UI. |
| 187 list.back().setting = CONTENT_SETTING_BLOCK; | 187 list.back().setting = CONTENT_SETTING_BLOCK; |
| 188 api_->SetPermissionInfo(list); | 188 api_->SetPermissionInfo(list); |
| 189 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), | 189 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), |
| 190 api_->GetPermissionButtonAt(0)->GetText()); | 190 api_->GetPermissionButtonAt(0)->GetText()); |
| 191 | 191 |
| 192 // Simulate a user selection via the UI. Note this will also cover logic in | 192 // Simulate a user selection via the UI. Note this will also cover logic in |
| 193 // WebsiteSettings to update the pref. | 193 // WebsiteSettings to update the pref. |
| 194 list.back().setting = CONTENT_SETTING_ALLOW; | 194 list.back().setting = CONTENT_SETTING_ALLOW; |
| 195 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 195 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 196 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 196 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 197 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), | 197 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), |
| 198 api_->GetPermissionButtonAt(0)->GetText()); | 198 api_->GetPermissionButtonAt(0)->GetText()); |
| 199 | 199 |
| 200 // Setting to the default via the UI should keep the button around. | 200 // Setting to the default via the UI should keep the button around. |
| 201 list.back().setting = CONTENT_SETTING_ASK; | 201 list.back().setting = CONTENT_SETTING_ASK; |
| 202 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 202 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 203 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 203 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 204 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), | 204 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), |
| 205 api_->GetPermissionButtonAt(0)->GetText()); | 205 api_->GetPermissionButtonAt(0)->GetText()); |
| 206 | 206 |
| 207 // However, since the setting is now default, recreating the dialog with those | 207 // However, since the setting is now default, recreating the dialog with those |
| 208 // settings should omit the permission from the UI. | 208 // settings should omit the permission from the UI. |
| 209 api_->SetPermissionInfo(list); | 209 api_->SetPermissionInfo(list); |
| 210 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 210 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Test UI construction and reconstruction with USB devices. | 213 // Test UI construction and reconstruction with USB devices. |
| 214 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { | 214 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { |
| 215 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 215 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 216 | 216 |
| 217 const GURL origin = GURL(kUrl).GetOrigin(); | 217 const GURL origin = GURL(kUrl).GetOrigin(); |
| 218 scoped_refptr<device::UsbDevice> device = | 218 scoped_refptr<device::UsbDevice> device = |
| 219 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 219 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
| 220 device_client_.usb_service().AddDevice(device); | 220 device_client_.usb_service().AddDevice(device); |
| 221 UsbChooserContext* store = | 221 UsbChooserContext* store = |
| 222 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); | 222 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); |
| 223 store->GrantDevicePermission(origin, origin, device->guid()); | 223 store->GrantDevicePermission(origin, origin, device->guid()); |
| 224 | 224 |
| 225 PermissionInfoList list; | 225 PermissionInfoList list; |
| 226 api_->SetPermissionInfo(list); | 226 api_->SetPermissionInfo(list); |
| 227 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 227 EXPECT_EQ(11, api_->permissions_content()->child_count()); |
| 228 | 228 |
| 229 ChosenObjectView* object_view = | 229 ChosenObjectView* object_view = |
| 230 static_cast<ChosenObjectView*>(api_->permissions_content()->child_at(0)); | 230 static_cast<ChosenObjectView*>(api_->permissions_content()->child_at(10)); |
| 231 EXPECT_EQ(3, object_view->child_count()); | 231 EXPECT_EQ(3, object_view->child_count()); |
| 232 | 232 |
| 233 const int kLabelIndex = 1; | 233 const int kLabelIndex = 1; |
| 234 views::Label* label = | 234 views::Label* label = |
| 235 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); | 235 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); |
| 236 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); | 236 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); |
| 237 | 237 |
| 238 const int kButtonIndex = 2; | 238 const int kButtonIndex = 2; |
| 239 views::Button* button = | 239 views::Button* button = |
| 240 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); | 240 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); |
| 241 | 241 |
| 242 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 242 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 243 ui::EventTimeForNow(), 0, 0); | 243 ui::EventTimeForNow(), 0, 0); |
| 244 views::ButtonListener* button_listener = | 244 views::ButtonListener* button_listener = |
| 245 static_cast<views::ButtonListener*>(object_view); | 245 static_cast<views::ButtonListener*>(object_view); |
| 246 button_listener->ButtonPressed(button, event); | 246 button_listener->ButtonPressed(button, event); |
| 247 api_->SetPermissionInfo(list); | 247 api_->SetPermissionInfo(list); |
| 248 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 248 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 249 EXPECT_FALSE(store->HasDevicePermission( | 249 EXPECT_FALSE(store->HasDevicePermission( |
| 250 origin, origin, *device::usb::DeviceInfo::From(*device))); | 250 origin, origin, *device::usb::DeviceInfo::From(*device))); |
| 251 } | 251 } |
| OLD | NEW |