| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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("Allowed by you"), | 194 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
| 195 api_->GetPermissionButtonTextAt(0)); | |
| 196 | 195 |
| 197 // Verify calling SetPermisisonInfo() directly updates the UI. | 196 // Verify calling SetPermisisonInfo() directly updates the UI. |
| 198 list.back().setting = CONTENT_SETTING_BLOCK; | 197 list.back().setting = CONTENT_SETTING_BLOCK; |
| 199 api_->SetPermissionInfo(list); | 198 api_->SetPermissionInfo(list); |
| 200 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), | 199 EXPECT_EQ(base::ASCIIToUTF16("Block"), api_->GetPermissionButtonTextAt(0)); |
| 201 api_->GetPermissionButtonTextAt(0)); | |
| 202 | 200 |
| 203 // 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 |
| 204 // WebsiteSettings to update the pref. | 202 // WebsiteSettings to update the pref. |
| 205 list.back().setting = CONTENT_SETTING_ALLOW; | 203 list.back().setting = CONTENT_SETTING_ALLOW; |
| 206 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 204 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 207 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 205 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 208 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), | 206 EXPECT_EQ(base::ASCIIToUTF16("Allow"), api_->GetPermissionButtonTextAt(0)); |
| 209 api_->GetPermissionButtonTextAt(0)); | |
| 210 | 207 |
| 211 // 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. |
| 212 list.back().setting = CONTENT_SETTING_ASK; | 209 list.back().setting = CONTENT_SETTING_ASK; |
| 213 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); | 210 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); |
| 214 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 211 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 215 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), | 212 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); |
| 216 api_->GetPermissionButtonTextAt(0)); | |
| 217 | 213 |
| 218 // 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 |
| 219 // settings should omit the permission from the UI. | 215 // settings should omit the permission from the UI. |
| 220 api_->SetPermissionInfo(list); | 216 api_->SetPermissionInfo(list); |
| 221 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 217 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 222 } | 218 } |
| 223 | 219 |
| 224 // Test UI construction and reconstruction with USB devices. | 220 // Test UI construction and reconstruction with USB devices. |
| 225 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { | 221 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { |
| 226 const int kExpectedChildren = | 222 const int kExpectedChildren = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 254 | 250 |
| 255 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(), |
| 256 ui::EventTimeForNow(), 0, 0); | 252 ui::EventTimeForNow(), 0, 0); |
| 257 views::ButtonListener* button_listener = | 253 views::ButtonListener* button_listener = |
| 258 static_cast<views::ButtonListener*>(object_view); | 254 static_cast<views::ButtonListener*>(object_view); |
| 259 button_listener->ButtonPressed(button, event); | 255 button_listener->ButtonPressed(button, event); |
| 260 api_->SetPermissionInfo(list); | 256 api_->SetPermissionInfo(list); |
| 261 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 257 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
| 262 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 258 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
| 263 } | 259 } |
| OLD | NEW |