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 "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 #ifdef OS_MACOSX |
| 168 // Mac OS X still has Fullscreen and Mouse Lock permissions. | |
|
tapted
2016/03/06 23:02:08
This is actually in a fieldtrial on Mac, to catch
palmer
2016/03/09 20:13:07
OK, I've changed the tests to use ExclusiveAccessM
| |
| 169 const int kExpectedChildren = 12; | |
| 170 #else | |
| 171 const int kExpectedChildren = 10; | |
| 172 #endif | |
| 173 | |
| 174 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | |
| 168 | 175 |
| 169 list.back().setting = CONTENT_SETTING_ALLOW; | 176 list.back().setting = CONTENT_SETTING_ALLOW; |
| 170 api_->SetPermissionInfo(list); | 177 api_->SetPermissionInfo(list); |
| 171 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 178 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 172 | 179 |
| 173 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); | 180 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); |
| 174 EXPECT_EQ(3, selector->child_count()); | 181 EXPECT_EQ(3, selector->child_count()); |
| 175 | 182 |
| 176 // Verify labels match the settings on the PermissionInfoList. | 183 // Verify labels match the settings on the PermissionInfoList. |
| 177 const int kLabelIndex = 1; | 184 const int kLabelIndex = 1; |
| 178 EXPECT_EQ(views::Label::kViewClassName, | 185 EXPECT_EQ(views::Label::kViewClassName, |
| 179 selector->child_at(kLabelIndex)->GetClassName()); | 186 selector->child_at(kLabelIndex)->GetClassName()); |
| 180 views::Label* label = | 187 views::Label* label = |
| 181 static_cast<views::Label*>(selector->child_at(kLabelIndex)); | 188 static_cast<views::Label*>(selector->child_at(kLabelIndex)); |
| 182 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); | 189 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); |
| 183 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), | 190 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), |
| 184 api_->GetPermissionButtonAt(0)->GetText()); | 191 api_->GetPermissionButtonAt(0)->GetText()); |
| 185 | 192 |
| 186 // Verify calling SetPermisisonInfo() directly updates the UI. | 193 // Verify calling SetPermisisonInfo() directly updates the UI. |
| 187 list.back().setting = CONTENT_SETTING_BLOCK; | 194 list.back().setting = CONTENT_SETTING_BLOCK; |
| 188 api_->SetPermissionInfo(list); | 195 api_->SetPermissionInfo(list); |
| 189 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), | 196 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), |
| 190 api_->GetPermissionButtonAt(0)->GetText()); | 197 api_->GetPermissionButtonAt(0)->GetText()); |
| 191 | 198 |
| 192 // Simulate a user selection via the UI. Note this will also cover logic in | 199 // Simulate a user selection via the UI. Note this will also cover logic in |
| 193 // WebsiteSettings to update the pref. | 200 // WebsiteSettings to update the pref. |
| 194 list.back().setting = CONTENT_SETTING_ALLOW; | 201 list.back().setting = CONTENT_SETTING_ALLOW; |
| 195 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 202 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 196 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 203 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 197 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), | 204 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), |
| 198 api_->GetPermissionButtonAt(0)->GetText()); | 205 api_->GetPermissionButtonAt(0)->GetText()); |
| 199 | 206 |
| 200 // Setting to the default via the UI should keep the button around. | 207 // Setting to the default via the UI should keep the button around. |
| 201 list.back().setting = CONTENT_SETTING_ASK; | 208 list.back().setting = CONTENT_SETTING_ASK; |
| 202 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 209 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 203 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 210 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 204 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), | 211 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), |
| 205 api_->GetPermissionButtonAt(0)->GetText()); | 212 api_->GetPermissionButtonAt(0)->GetText()); |
| 206 | 213 |
| 207 // 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 |
| 208 // settings should omit the permission from the UI. | 215 // settings should omit the permission from the UI. |
| 209 api_->SetPermissionInfo(list); | 216 api_->SetPermissionInfo(list); |
| 210 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 217 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 211 } | 218 } |
| 212 | 219 |
| 213 // Test UI construction and reconstruction with USB devices. | 220 // Test UI construction and reconstruction with USB devices. |
| 214 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { | 221 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { |
| 215 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 222 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 216 | 223 |
| 217 const GURL origin = GURL(kUrl).GetOrigin(); | 224 const GURL origin = GURL(kUrl).GetOrigin(); |
| 218 scoped_refptr<device::UsbDevice> device = | 225 scoped_refptr<device::UsbDevice> device = |
| 219 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 226 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
| 220 device_client_.usb_service().AddDevice(device); | 227 device_client_.usb_service().AddDevice(device); |
| 221 UsbChooserContext* store = | 228 UsbChooserContext* store = |
| 222 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); | 229 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); |
| 223 store->GrantDevicePermission(origin, origin, device->guid()); | 230 store->GrantDevicePermission(origin, origin, device->guid()); |
| 224 | 231 |
| 225 PermissionInfoList list; | 232 PermissionInfoList list; |
| 226 api_->SetPermissionInfo(list); | 233 api_->SetPermissionInfo(list); |
| 227 EXPECT_EQ(1, api_->permissions_content()->child_count()); | 234 EXPECT_EQ(11, api_->permissions_content()->child_count()); |
| 228 | 235 |
| 229 ChosenObjectView* object_view = | 236 ChosenObjectView* object_view = |
| 230 static_cast<ChosenObjectView*>(api_->permissions_content()->child_at(0)); | 237 static_cast<ChosenObjectView*>(api_->permissions_content()->child_at(10)); |
| 231 EXPECT_EQ(3, object_view->child_count()); | 238 EXPECT_EQ(3, object_view->child_count()); |
| 232 | 239 |
| 233 const int kLabelIndex = 1; | 240 const int kLabelIndex = 1; |
| 234 views::Label* label = | 241 views::Label* label = |
| 235 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); | 242 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); |
| 236 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); | 243 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); |
| 237 | 244 |
| 238 const int kButtonIndex = 2; | 245 const int kButtonIndex = 2; |
| 239 views::Button* button = | 246 views::Button* button = |
| 240 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); | 247 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); |
| 241 | 248 |
| 242 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 249 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 243 ui::EventTimeForNow(), 0, 0); | 250 ui::EventTimeForNow(), 0, 0); |
| 244 views::ButtonListener* button_listener = | 251 views::ButtonListener* button_listener = |
| 245 static_cast<views::ButtonListener*>(object_view); | 252 static_cast<views::ButtonListener*>(object_view); |
| 246 button_listener->ButtonPressed(button, event); | 253 button_listener->ButtonPressed(button, event); |
| 247 api_->SetPermissionInfo(list); | 254 api_->SetPermissionInfo(list); |
| 248 EXPECT_EQ(0, api_->permissions_content()->child_count()); | 255 EXPECT_EQ(10, api_->permissions_content()->child_count()); |
| 249 EXPECT_FALSE(store->HasDevicePermission( | 256 EXPECT_FALSE(store->HasDevicePermission( |
| 250 origin, origin, *device::usb::DeviceInfo::From(*device))); | 257 origin, origin, *device::usb::DeviceInfo::From(*device))); |
| 251 } | 258 } |
| OLD | NEW |