Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view_unittest.cc

Issue 1766493002: Restore the permission selection listing in the Origin Info Bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(). Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/website_settings/website_settings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/website_settings/chosen_object_view.h" 9 #include "chrome/browser/ui/views/website_settings/chosen_object_view.h"
9 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" 10 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h"
10 #include "chrome/browser/usb/usb_chooser_context.h" 11 #include "chrome/browser/usb/usb_chooser_context.h"
11 #include "chrome/browser/usb/usb_chooser_context_factory.h" 12 #include "chrome/browser/usb/usb_chooser_context_factory.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/common/ssl_status.h" 14 #include "content/public/common/ssl_status.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/public/test/test_web_contents_factory.h" 16 #include "content/public/test/test_web_contents_factory.h"
16 #include "device/core/device_client.h" 17 #include "device/core/device_client.h"
17 #include "device/usb/mock_usb_device.h" 18 #include "device/usb/mock_usb_device.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } // namespace 158 } // namespace
158 159
159 // Test UI construction and reconstruction via 160 // Test UI construction and reconstruction via
160 // WebsiteSettingsPopupView::SetPermissionInfo(). 161 // WebsiteSettingsPopupView::SetPermissionInfo().
161 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfo) { 162 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfo) {
162 PermissionInfoList list(1); 163 PermissionInfoList list(1);
163 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; 164 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION;
164 list.back().source = content_settings::SETTING_SOURCE_USER; 165 list.back().source = content_settings::SETTING_SOURCE_USER;
165 list.back().is_incognito = false; 166 list.back().is_incognito = false;
166 167
167 EXPECT_EQ(0, api_->permissions_content()->child_count()); 168 const int kExpectedChildren =
169 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 10 : 12;
170 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
168 171
169 list.back().setting = CONTENT_SETTING_ALLOW; 172 list.back().setting = CONTENT_SETTING_ALLOW;
170 api_->SetPermissionInfo(list); 173 api_->SetPermissionInfo(list);
171 EXPECT_EQ(1, api_->permissions_content()->child_count()); 174 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
172 175
173 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0); 176 PermissionSelectorView* selector = api_->GetPermissionSelectorAt(0);
174 EXPECT_EQ(3, selector->child_count()); 177 EXPECT_EQ(3, selector->child_count());
175 178
176 // Verify labels match the settings on the PermissionInfoList. 179 // Verify labels match the settings on the PermissionInfoList.
177 const int kLabelIndex = 1; 180 const int kLabelIndex = 1;
178 EXPECT_EQ(views::Label::kViewClassName, 181 EXPECT_EQ(views::Label::kViewClassName,
179 selector->child_at(kLabelIndex)->GetClassName()); 182 selector->child_at(kLabelIndex)->GetClassName());
180 views::Label* label = 183 views::Label* label =
181 static_cast<views::Label*>(selector->child_at(kLabelIndex)); 184 static_cast<views::Label*>(selector->child_at(kLabelIndex));
182 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text()); 185 EXPECT_EQ(base::ASCIIToUTF16("Location:"), label->text());
183 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), 186 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"),
184 api_->GetPermissionButtonAt(0)->GetText()); 187 api_->GetPermissionButtonAt(0)->GetText());
185 188
186 // Verify calling SetPermisisonInfo() directly updates the UI. 189 // Verify calling SetPermisisonInfo() directly updates the UI.
187 list.back().setting = CONTENT_SETTING_BLOCK; 190 list.back().setting = CONTENT_SETTING_BLOCK;
188 api_->SetPermissionInfo(list); 191 api_->SetPermissionInfo(list);
189 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"), 192 EXPECT_EQ(base::ASCIIToUTF16("Blocked by you"),
190 api_->GetPermissionButtonAt(0)->GetText()); 193 api_->GetPermissionButtonAt(0)->GetText());
191 194
192 // Simulate a user selection via the UI. Note this will also cover logic in 195 // Simulate a user selection via the UI. Note this will also cover logic in
193 // WebsiteSettings to update the pref. 196 // WebsiteSettings to update the pref.
194 list.back().setting = CONTENT_SETTING_ALLOW; 197 list.back().setting = CONTENT_SETTING_ALLOW;
195 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); 198 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back());
196 EXPECT_EQ(1, api_->permissions_content()->child_count()); 199 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
197 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"), 200 EXPECT_EQ(base::ASCIIToUTF16("Allowed by you"),
198 api_->GetPermissionButtonAt(0)->GetText()); 201 api_->GetPermissionButtonAt(0)->GetText());
199 202
200 // Setting to the default via the UI should keep the button around. 203 // Setting to the default via the UI should keep the button around.
201 list.back().setting = CONTENT_SETTING_ASK; 204 list.back().setting = CONTENT_SETTING_ASK;
202 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back()); 205 api_->GetPermissionSelectorAt(0)->PermissionChanged(list.back());
203 EXPECT_EQ(1, api_->permissions_content()->child_count()); 206 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
204 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"), 207 EXPECT_EQ(base::ASCIIToUTF16("Ask by you"),
205 api_->GetPermissionButtonAt(0)->GetText()); 208 api_->GetPermissionButtonAt(0)->GetText());
206 209
207 // However, since the setting is now default, recreating the dialog with those 210 // However, since the setting is now default, recreating the dialog with those
208 // settings should omit the permission from the UI. 211 // settings should omit the permission from the UI.
209 api_->SetPermissionInfo(list); 212 api_->SetPermissionInfo(list);
210 EXPECT_EQ(0, api_->permissions_content()->child_count()); 213 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
211 } 214 }
212 215
213 // Test UI construction and reconstruction with USB devices. 216 // Test UI construction and reconstruction with USB devices.
214 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) { 217 TEST_F(WebsiteSettingsPopupViewTest, SetPermissionInfoWithUsbDevice) {
215 EXPECT_EQ(0, api_->permissions_content()->child_count()); 218 const int kExpectedChildren =
219 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 10 : 12;
220 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
216 221
217 const GURL origin = GURL(kUrl).GetOrigin(); 222 const GURL origin = GURL(kUrl).GetOrigin();
218 scoped_refptr<device::UsbDevice> device = 223 scoped_refptr<device::UsbDevice> device =
219 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); 224 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890");
220 device_client_.usb_service().AddDevice(device); 225 device_client_.usb_service().AddDevice(device);
221 UsbChooserContext* store = 226 UsbChooserContext* store =
222 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); 227 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile());
223 store->GrantDevicePermission(origin, origin, device->guid()); 228 store->GrantDevicePermission(origin, origin, device->guid());
224 229
225 PermissionInfoList list; 230 PermissionInfoList list;
226 api_->SetPermissionInfo(list); 231 api_->SetPermissionInfo(list);
227 EXPECT_EQ(1, api_->permissions_content()->child_count()); 232 EXPECT_EQ(kExpectedChildren + 1, api_->permissions_content()->child_count());
228 233
229 ChosenObjectView* object_view = 234 ChosenObjectView* object_view = static_cast<ChosenObjectView*>(
230 static_cast<ChosenObjectView*>(api_->permissions_content()->child_at(0)); 235 api_->permissions_content()->child_at(kExpectedChildren));
231 EXPECT_EQ(3, object_view->child_count()); 236 EXPECT_EQ(3, object_view->child_count());
232 237
233 const int kLabelIndex = 1; 238 const int kLabelIndex = 1;
234 views::Label* label = 239 views::Label* label =
235 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); 240 static_cast<views::Label*>(object_view->child_at(kLabelIndex));
236 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); 241 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text());
237 242
238 const int kButtonIndex = 2; 243 const int kButtonIndex = 2;
239 views::Button* button = 244 views::Button* button =
240 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); 245 static_cast<views::Button*>(object_view->child_at(kButtonIndex));
241 246
242 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 247 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
243 ui::EventTimeForNow(), 0, 0); 248 ui::EventTimeForNow(), 0, 0);
244 views::ButtonListener* button_listener = 249 views::ButtonListener* button_listener =
245 static_cast<views::ButtonListener*>(object_view); 250 static_cast<views::ButtonListener*>(object_view);
246 button_listener->ButtonPressed(button, event); 251 button_listener->ButtonPressed(button, event);
247 api_->SetPermissionInfo(list); 252 api_->SetPermissionInfo(list);
248 EXPECT_EQ(0, api_->permissions_content()->child_count()); 253 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count());
249 EXPECT_FALSE(store->HasDevicePermission( 254 EXPECT_FALSE(store->HasDevicePermission(
250 origin, origin, *device::usb::DeviceInfo::From(*device))); 255 origin, origin, *device::usb::DeviceInfo::From(*device)));
251 } 256 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/website_settings/website_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698