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_view.h" | 9 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" |
10 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 10 #include "chrome/browser/ui/views/website_settings/permission_selector_row.h" |
11 #include "chrome/browser/usb/usb_chooser_context.h" | 11 #include "chrome/browser/usb/usb_chooser_context.h" |
12 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 12 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/common/ssl_status.h" | 14 #include "content/public/common/ssl_status.h" |
15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "content/public/test/test_web_contents_factory.h" | 16 #include "content/public/test/test_web_contents_factory.h" |
17 #include "device/core/mock_device_client.h" | 17 #include "device/core/mock_device_client.h" |
18 #include "device/usb/mock_usb_device.h" | 18 #include "device/usb/mock_usb_device.h" |
19 #include "device/usb/mock_usb_service.h" | 19 #include "device/usb/mock_usb_service.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 26 matching lines...) Expand all Loading... |
47 security_state::SecurityStateModel::SecurityInfo security_info; | 47 security_state::SecurityStateModel::SecurityInfo security_info; |
48 views::View* anchor_view = nullptr; | 48 views::View* anchor_view = nullptr; |
49 view_ = | 49 view_ = |
50 new WebsiteSettingsPopupView(anchor_view, parent_, profile_, | 50 new WebsiteSettingsPopupView(anchor_view, parent_, profile_, |
51 web_contents_, GURL(kUrl), security_info); | 51 web_contents_, GURL(kUrl), security_info); |
52 } | 52 } |
53 | 53 |
54 WebsiteSettingsPopupView* view() { return view_; } | 54 WebsiteSettingsPopupView* view() { return view_; } |
55 views::View* permissions_content() { return view_->permissions_content_; } | 55 views::View* permissions_content() { return view_->permissions_content_; } |
56 | 56 |
57 PermissionSelectorView* GetPermissionSelectorAt(int index) { | 57 PermissionSelectorRow* GetPermissionSelectorAt(int index) { |
58 return static_cast<PermissionSelectorView*>( | 58 return static_cast<PermissionSelectorRow*>( |
59 permissions_content()->child_at(index)); | 59 permissions_content()->child_at(index)); |
60 } | 60 } |
61 | 61 |
62 base::string16 GetPermissionButtonTextAt(int index) { | 62 base::string16 GetPermissionButtonTextAt(int index) { |
63 const int kButtonIndex = 2; // Button should be the third child. | 63 const int kButtonIndex = 2; // Button should be the third child. |
64 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); | 64 views::View* view = GetPermissionSelectorAt(index)->child_at(kButtonIndex); |
65 if (view->GetClassName() == views::MenuButton::kViewClassName) { | 65 if (view->GetClassName() == views::MenuButton::kViewClassName) { |
66 return static_cast<views::MenuButton*>(view)->GetText(); | 66 return static_cast<views::MenuButton*>(view)->GetText(); |
67 } else if (view->GetClassName() == views::Combobox::kViewClassName) { | 67 } else if (view->GetClassName() == views::Combobox::kViewClassName) { |
68 views::Combobox* combobox = static_cast<views::Combobox*>(view); | 68 views::Combobox* combobox = static_cast<views::Combobox*>(view); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget. | 144 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget. |
145 std::unique_ptr<test::WebsiteSettingsPopupViewTestApi> api_; | 145 std::unique_ptr<test::WebsiteSettingsPopupViewTestApi> api_; |
146 | 146 |
147 private: | 147 private: |
148 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupViewTest); | 148 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupViewTest); |
149 }; | 149 }; |
150 | 150 |
151 } // namespace | 151 } // namespace |
152 | 152 |
153 // TODO(ellyjones): re-enable this test for OSX. | 153 // TODO(ellyjones): re-enable this test for OSX. |
154 // This test exercises PermissionSelectorView in a way that it is not used in | 154 // This test exercises PermissionSelectorRow in a way that it is not used in |
155 // practice. In practice, every setting in PermissionSelectorView starts off | 155 // practice. In practice, every setting in PermissionSelectorRow starts off |
156 // "set", so there is always one option checked in the resulting MenuModel. This | 156 // "set", so there is always one option checked in the resulting MenuModel. This |
157 // test creates settings that are left at their defaults, leading to zero | 157 // test creates settings that are left at their defaults, leading to zero |
158 // checked options, and checks that the text on the MenuButtons is right. Since | 158 // checked options, and checks that the text on the MenuButtons is right. Since |
159 // the Comboboxes the MacViews version of this dialog uses don't have separate | 159 // the Comboboxes the MacViews version of this dialog uses don't have separate |
160 // text, this test doesn't work. | 160 // text, this test doesn't work. |
161 #if defined(OS_MACOSX) | 161 #if defined(OS_MACOSX) |
162 #define MAYBE_SetPermissionInfo DISABLED_SetPermissionInfo | 162 #define MAYBE_SetPermissionInfo DISABLED_SetPermissionInfo |
163 #else | 163 #else |
164 #define MAYBE_SetPermissionInfo SetPermissionInfo | 164 #define MAYBE_SetPermissionInfo SetPermissionInfo |
165 #endif | 165 #endif |
166 | 166 |
167 // Test UI construction and reconstruction via | 167 // Test UI construction and reconstruction via |
168 // WebsiteSettingsPopupView::SetPermissionInfo(). | 168 // WebsiteSettingsPopupView::SetPermissionInfo(). |
169 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { | 169 TEST_F(WebsiteSettingsPopupViewTest, MAYBE_SetPermissionInfo) { |
170 PermissionInfoList list(1); | 170 PermissionInfoList list(1); |
171 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 171 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
172 list.back().source = content_settings::SETTING_SOURCE_USER; | 172 list.back().source = content_settings::SETTING_SOURCE_USER; |
173 list.back().is_incognito = false; | 173 list.back().is_incognito = false; |
174 list.back().setting = CONTENT_SETTING_DEFAULT; | 174 list.back().setting = CONTENT_SETTING_DEFAULT; |
175 | 175 |
176 const int kExpectedChildren = | 176 const int kExpectedChildren = |
177 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; | 177 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13; |
178 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 178 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
179 | 179 |
180 list.back().setting = CONTENT_SETTING_ALLOW; | 180 list.back().setting = CONTENT_SETTING_ALLOW; |
181 api_->SetPermissionInfo(list); | 181 api_->SetPermissionInfo(list); |
182 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 182 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
183 | 183 |
184 PermissionSelectorView* 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("Allowed by you"), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 232 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
233 device_client_.usb_service()->AddDevice(device); | 233 device_client_.usb_service()->AddDevice(device); |
234 UsbChooserContext* store = | 234 UsbChooserContext* store = |
235 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); | 235 UsbChooserContextFactory::GetForProfile(web_contents_helper_.profile()); |
236 store->GrantDevicePermission(origin, origin, device->guid()); | 236 store->GrantDevicePermission(origin, origin, device->guid()); |
237 | 237 |
238 PermissionInfoList list; | 238 PermissionInfoList list; |
239 api_->SetPermissionInfo(list); | 239 api_->SetPermissionInfo(list); |
240 EXPECT_EQ(kExpectedChildren + 1, api_->permissions_content()->child_count()); | 240 EXPECT_EQ(kExpectedChildren + 1, api_->permissions_content()->child_count()); |
241 | 241 |
242 ChosenObjectView* object_view = static_cast<ChosenObjectView*>( | 242 ChosenObjectRow* object_view = static_cast<ChosenObjectRow*>( |
243 api_->permissions_content()->child_at(kExpectedChildren)); | 243 api_->permissions_content()->child_at(kExpectedChildren)); |
244 EXPECT_EQ(3, object_view->child_count()); | 244 EXPECT_EQ(3, object_view->child_count()); |
245 | 245 |
246 const int kLabelIndex = 1; | 246 const int kLabelIndex = 1; |
247 views::Label* label = | 247 views::Label* label = |
248 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); | 248 static_cast<views::Label*>(object_view->child_at(kLabelIndex)); |
249 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); | 249 EXPECT_EQ(base::ASCIIToUTF16("Gizmo"), label->text()); |
250 | 250 |
251 const int kButtonIndex = 2; | 251 const int kButtonIndex = 2; |
252 views::Button* button = | 252 views::Button* button = |
253 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); | 253 static_cast<views::Button*>(object_view->child_at(kButtonIndex)); |
254 | 254 |
255 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 255 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
256 ui::EventTimeForNow(), 0, 0); | 256 ui::EventTimeForNow(), 0, 0); |
257 views::ButtonListener* button_listener = | 257 views::ButtonListener* button_listener = |
258 static_cast<views::ButtonListener*>(object_view); | 258 static_cast<views::ButtonListener*>(object_view); |
259 button_listener->ButtonPressed(button, event); | 259 button_listener->ButtonPressed(button, event); |
260 api_->SetPermissionInfo(list); | 260 api_->SetPermissionInfo(list); |
261 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); | 261 EXPECT_EQ(kExpectedChildren, api_->permissions_content()->child_count()); |
262 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 262 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
263 } | 263 } |
OLD | NEW |