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/page_info/page_info_popup_view.h" | 5 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
10 #include "chrome/browser/ui/views/page_info/chosen_object_row.h" | 10 #include "chrome/browser/ui/views/page_info/chosen_object_row.h" |
11 #include "chrome/browser/ui/views/page_info/permission_selector_row.h" | 11 #include "chrome/browser/ui/views/page_info/permission_selector_row.h" |
12 #include "chrome/browser/usb/usb_chooser_context.h" | 12 #include "chrome/browser/usb/usb_chooser_context.h" |
13 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 13 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/browser/ssl_status.h" | 15 #include "content/public/browser/ssl_status.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_web_contents_factory.h" | 17 #include "content/public/test/test_web_contents_factory.h" |
18 #include "device/base/mock_device_client.h" | 18 #include "device/base/mock_device_client.h" |
19 #include "device/usb/mock_usb_device.h" | 19 #include "device/usb/mock_usb_device.h" |
20 #include "device/usb/mock_usb_service.h" | 20 #include "device/usb/mock_usb_service.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
23 #include "ui/views/controls/button/menu_button.h" | 23 #include "ui/views/controls/button/menu_button.h" |
24 #include "ui/views/controls/combobox/combobox.h" | 24 #include "ui/views/controls/combobox/combobox.h" |
25 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
26 #include "ui/views/test/scoped_views_test_helper.h" | 26 #include "ui/views/test/scoped_views_test_helper.h" |
27 | 27 |
28 const char* kUrl = "http://www.example.com/index.html"; | 28 const char* kUrl = "http://www.example.com/index.html"; |
29 | 29 |
30 namespace test { | 30 namespace test { |
31 | 31 |
32 class PageInfoPopupViewTestApi { | 32 class PageInfoBubbleViewTestApi { |
33 public: | 33 public: |
34 PageInfoPopupViewTestApi(gfx::NativeView parent, | 34 PageInfoBubbleViewTestApi(gfx::NativeView parent, |
35 Profile* profile, | 35 Profile* profile, |
36 content::WebContents* web_contents) | 36 content::WebContents* web_contents) |
37 : view_(nullptr), | 37 : view_(nullptr), |
38 parent_(parent), | 38 parent_(parent), |
39 profile_(profile), | 39 profile_(profile), |
40 web_contents_(web_contents) { | 40 web_contents_(web_contents) { |
41 CreateView(); | 41 CreateView(); |
42 } | 42 } |
43 | 43 |
44 void CreateView() { | 44 void CreateView() { |
45 if (view_) | 45 if (view_) |
46 view_->GetWidget()->CloseNow(); | 46 view_->GetWidget()->CloseNow(); |
47 | 47 |
48 security_state::SecurityInfo security_info; | 48 security_state::SecurityInfo security_info; |
49 views::View* anchor_view = nullptr; | 49 views::View* anchor_view = nullptr; |
50 view_ = new PageInfoPopupView(anchor_view, parent_, profile_, web_contents_, | 50 view_ = new PageInfoBubbleView(anchor_view, parent_, profile_, |
51 GURL(kUrl), security_info); | 51 web_contents_, GURL(kUrl), security_info); |
52 } | 52 } |
53 | 53 |
54 PageInfoPopupView* view() { return view_; } | 54 PageInfoBubbleView* view() { return view_; } |
55 views::View* permissions_view() { return view_->permissions_view_; } | 55 views::View* permissions_view() { return view_->permissions_view_; } |
56 | 56 |
57 PermissionSelectorRow* GetPermissionSelectorAt(int index) { | 57 PermissionSelectorRow* GetPermissionSelectorAt(int index) { |
58 return view_->selector_rows_[index].get(); | 58 return view_->selector_rows_[index].get(); |
59 } | 59 } |
60 | 60 |
61 // Returns the permission label text of the |index|th permission selector row. | 61 // Returns the permission label text of the |index|th permission selector row. |
62 // This function returns an empty string if the permission selector row's | 62 // This function returns an empty string if the permission selector row's |
63 // |label_| element isn't actually a |views::Label|. | 63 // |label_| element isn't actually a |views::Label|. |
64 base::string16 GetPermissionLabelTextAt(int index) { | 64 base::string16 GetPermissionLabelTextAt(int index) { |
(...skipping 11 matching lines...) Expand all Loading... |
76 views::Combobox* combobox = static_cast<views::Combobox*>(view); | 76 views::Combobox* combobox = static_cast<views::Combobox*>(view); |
77 return combobox->GetTextForRow(combobox->GetSelectedRow()); | 77 return combobox->GetTextForRow(combobox->GetSelectedRow()); |
78 } else { | 78 } else { |
79 NOTREACHED() << "Unknown class " << view->GetClassName(); | 79 NOTREACHED() << "Unknown class " << view->GetClassName(); |
80 return base::string16(); | 80 return base::string16(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 // Simulates recreating the dialog with a new PermissionInfoList. | 84 // Simulates recreating the dialog with a new PermissionInfoList. |
85 void SetPermissionInfo(const PermissionInfoList& list) { | 85 void SetPermissionInfo(const PermissionInfoList& list) { |
86 for (const PageInfoPopupView::PermissionInfo& info : list) | 86 for (const PageInfoBubbleView::PermissionInfo& info : list) |
87 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); | 87 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); |
88 CreateView(); | 88 CreateView(); |
89 } | 89 } |
90 | 90 |
91 private: | 91 private: |
92 PageInfoPopupView* view_; // Weak. Owned by its Widget. | 92 PageInfoBubbleView* view_; // Weak. Owned by its Widget. |
93 | 93 |
94 // For recreating the view. | 94 // For recreating the view. |
95 gfx::NativeView parent_; | 95 gfx::NativeView parent_; |
96 Profile* profile_; | 96 Profile* profile_; |
97 content::WebContents* web_contents_; | 97 content::WebContents* web_contents_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(PageInfoPopupViewTestApi); | 99 DISALLOW_COPY_AND_ASSIGN(PageInfoBubbleViewTestApi); |
100 }; | 100 }; |
101 | 101 |
102 } // namespace test | 102 } // namespace test |
103 | 103 |
104 namespace { | 104 namespace { |
105 | 105 |
106 // Helper class that wraps a TestingProfile and a TestWebContents for a test | 106 // Helper class that wraps a TestingProfile and a TestWebContents for a test |
107 // harness. Inspired by RenderViewHostTestHarness, but doesn't use inheritance | 107 // harness. Inspired by RenderViewHostTestHarness, but doesn't use inheritance |
108 // so the helper can be composed with other helpers in the test harness. | 108 // so the helper can be composed with other helpers in the test harness. |
109 class ScopedWebContentsTestHelper { | 109 class ScopedWebContentsTestHelper { |
110 public: | 110 public: |
111 ScopedWebContentsTestHelper() { | 111 ScopedWebContentsTestHelper() { |
112 web_contents_ = factory_.CreateWebContents(&profile_); | 112 web_contents_ = factory_.CreateWebContents(&profile_); |
113 } | 113 } |
114 | 114 |
115 Profile* profile() { return &profile_; } | 115 Profile* profile() { return &profile_; } |
116 content::WebContents* web_contents() { return web_contents_; } | 116 content::WebContents* web_contents() { return web_contents_; } |
117 | 117 |
118 private: | 118 private: |
119 content::TestBrowserThreadBundle thread_bundle_; | 119 content::TestBrowserThreadBundle thread_bundle_; |
120 TestingProfile profile_; | 120 TestingProfile profile_; |
121 content::TestWebContentsFactory factory_; | 121 content::TestWebContentsFactory factory_; |
122 content::WebContents* web_contents_; // Weak. Owned by factory_. | 122 content::WebContents* web_contents_; // Weak. Owned by factory_. |
123 | 123 |
124 DISALLOW_COPY_AND_ASSIGN(ScopedWebContentsTestHelper); | 124 DISALLOW_COPY_AND_ASSIGN(ScopedWebContentsTestHelper); |
125 }; | 125 }; |
126 | 126 |
127 class PageInfoPopupViewTest : public testing::Test { | 127 class PageInfoBubbleViewTest : public testing::Test { |
128 public: | 128 public: |
129 PageInfoPopupViewTest() {} | 129 PageInfoBubbleViewTest() {} |
130 | 130 |
131 // testing::Test: | 131 // testing::Test: |
132 void SetUp() override { | 132 void SetUp() override { |
133 views::Widget::InitParams parent_params; | 133 views::Widget::InitParams parent_params; |
134 parent_params.context = views_helper_.GetContext(); | 134 parent_params.context = views_helper_.GetContext(); |
135 parent_window_ = new views::Widget(); | 135 parent_window_ = new views::Widget(); |
136 parent_window_->Init(parent_params); | 136 parent_window_->Init(parent_params); |
137 | 137 |
138 content::WebContents* web_contents = web_contents_helper_.web_contents(); | 138 content::WebContents* web_contents = web_contents_helper_.web_contents(); |
139 TabSpecificContentSettings::CreateForWebContents(web_contents); | 139 TabSpecificContentSettings::CreateForWebContents(web_contents); |
140 api_.reset(new test::PageInfoPopupViewTestApi( | 140 api_.reset(new test::PageInfoBubbleViewTestApi( |
141 parent_window_->GetNativeView(), web_contents_helper_.profile(), | 141 parent_window_->GetNativeView(), web_contents_helper_.profile(), |
142 web_contents)); | 142 web_contents)); |
143 } | 143 } |
144 | 144 |
145 void TearDown() override { parent_window_->CloseNow(); } | 145 void TearDown() override { parent_window_->CloseNow(); } |
146 | 146 |
147 protected: | 147 protected: |
148 device::MockDeviceClient device_client_; | 148 device::MockDeviceClient device_client_; |
149 ScopedWebContentsTestHelper web_contents_helper_; | 149 ScopedWebContentsTestHelper web_contents_helper_; |
150 views::ScopedViewsTestHelper views_helper_; | 150 views::ScopedViewsTestHelper views_helper_; |
151 | 151 |
152 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget. | 152 views::Widget* parent_window_ = nullptr; // Weak. Owned by the NativeWidget. |
153 std::unique_ptr<test::PageInfoPopupViewTestApi> api_; | 153 std::unique_ptr<test::PageInfoBubbleViewTestApi> api_; |
154 | 154 |
155 private: | 155 private: |
156 DISALLOW_COPY_AND_ASSIGN(PageInfoPopupViewTest); | 156 DISALLOW_COPY_AND_ASSIGN(PageInfoBubbleViewTest); |
157 }; | 157 }; |
158 | 158 |
159 } // namespace | 159 } // namespace |
160 | 160 |
161 // TODO(ellyjones): re-enable this test for OSX. | 161 // TODO(ellyjones): re-enable this test for OSX. |
162 // This test exercises PermissionSelectorRow in a way that it is not used in | 162 // This test exercises PermissionSelectorRow in a way that it is not used in |
163 // practice. In practice, every setting in PermissionSelectorRow starts off | 163 // practice. In practice, every setting in PermissionSelectorRow starts off |
164 // "set", so there is always one option checked in the resulting MenuModel. This | 164 // "set", so there is always one option checked in the resulting MenuModel. This |
165 // test creates settings that are left at their defaults, leading to zero | 165 // test creates settings that are left at their defaults, leading to zero |
166 // checked options, and checks that the text on the MenuButtons is right. Since | 166 // checked options, and checks that the text on the MenuButtons is right. Since |
167 // the Comboboxes the MacViews version of this dialog uses don't have separate | 167 // the Comboboxes the MacViews version of this dialog uses don't have separate |
168 // text, this test doesn't work. | 168 // text, this test doesn't work. |
169 #if defined(OS_MACOSX) | 169 #if defined(OS_MACOSX) |
170 #define MAYBE_SetPermissionInfo DISABLED_SetPermissionInfo | 170 #define MAYBE_SetPermissionInfo DISABLED_SetPermissionInfo |
171 #else | 171 #else |
172 #define MAYBE_SetPermissionInfo SetPermissionInfo | 172 #define MAYBE_SetPermissionInfo SetPermissionInfo |
173 #endif | 173 #endif |
174 | 174 |
175 // Each permission selector row is like this: [icon] [label] [selector] | 175 // Each permission selector row is like this: [icon] [label] [selector] |
176 constexpr int kViewsPerPermissionRow = 3; | 176 constexpr int kViewsPerPermissionRow = 3; |
177 | 177 |
178 // Test UI construction and reconstruction via | 178 // Test UI construction and reconstruction via |
179 // PageInfoPopupView::SetPermissionInfo(). | 179 // PageInfoBubbleView::SetPermissionInfo(). |
180 TEST_F(PageInfoPopupViewTest, MAYBE_SetPermissionInfo) { | 180 TEST_F(PageInfoBubbleViewTest, MAYBE_SetPermissionInfo) { |
181 PermissionInfoList list(1); | 181 PermissionInfoList list(1); |
182 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 182 list.back().type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
183 list.back().source = content_settings::SETTING_SOURCE_USER; | 183 list.back().source = content_settings::SETTING_SOURCE_USER; |
184 list.back().is_incognito = false; | 184 list.back().is_incognito = false; |
185 list.back().setting = CONTENT_SETTING_DEFAULT; | 185 list.back().setting = CONTENT_SETTING_DEFAULT; |
186 | 186 |
187 const int kExpectedChildren = | 187 const int kExpectedChildren = |
188 kViewsPerPermissionRow * | 188 kViewsPerPermissionRow * |
189 (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); | 189 (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); |
190 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 190 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
(...skipping 27 matching lines...) Expand all Loading... |
218 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 218 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
219 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); | 219 EXPECT_EQ(base::ASCIIToUTF16("Ask"), api_->GetPermissionButtonTextAt(0)); |
220 | 220 |
221 // However, since the setting is now default, recreating the dialog with those | 221 // However, since the setting is now default, recreating the dialog with those |
222 // settings should omit the permission from the UI. | 222 // settings should omit the permission from the UI. |
223 api_->SetPermissionInfo(list); | 223 api_->SetPermissionInfo(list); |
224 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 224 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
225 } | 225 } |
226 | 226 |
227 // Test UI construction and reconstruction with USB devices. | 227 // Test UI construction and reconstruction with USB devices. |
228 TEST_F(PageInfoPopupViewTest, SetPermissionInfoWithUsbDevice) { | 228 TEST_F(PageInfoBubbleViewTest, SetPermissionInfoWithUsbDevice) { |
229 const int kExpectedChildren = | 229 const int kExpectedChildren = |
230 kViewsPerPermissionRow * | 230 kViewsPerPermissionRow * |
231 (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); | 231 (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 11 : 13); |
232 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 232 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
233 | 233 |
234 const GURL origin = GURL(kUrl).GetOrigin(); | 234 const GURL origin = GURL(kUrl).GetOrigin(); |
235 scoped_refptr<device::UsbDevice> device = | 235 scoped_refptr<device::UsbDevice> device = |
236 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); | 236 new device::MockUsbDevice(0, 0, "Google", "Gizmo", "1234567890"); |
237 device_client_.usb_service()->AddDevice(device); | 237 device_client_.usb_service()->AddDevice(device); |
238 UsbChooserContext* store = | 238 UsbChooserContext* store = |
(...skipping 19 matching lines...) Expand all Loading... |
258 | 258 |
259 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 259 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
260 ui::EventTimeForNow(), 0, 0); | 260 ui::EventTimeForNow(), 0, 0); |
261 views::ButtonListener* button_listener = | 261 views::ButtonListener* button_listener = |
262 static_cast<views::ButtonListener*>(object_view); | 262 static_cast<views::ButtonListener*>(object_view); |
263 button_listener->ButtonPressed(button, event); | 263 button_listener->ButtonPressed(button, event); |
264 api_->SetPermissionInfo(list); | 264 api_->SetPermissionInfo(list); |
265 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 265 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
266 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 266 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
267 } | 267 } |
OLD | NEW |