OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_install_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_icon_manager.h" | 12 #include "chrome/browser/extensions/extension_icon_manager.h" |
13 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
14 #include "chrome/browser/extensions/extension_install_prompt_test_helper.h" | 14 #include "chrome/browser/extensions/extension_install_prompt_test_helper.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | 18 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
18 #include "chrome/common/extensions/extension_test_util.h" | 19 #include "chrome/common/extensions/extension_test_util.h" |
19 #include "components/constrained_window/constrained_window_views.h" | 20 #include "components/constrained_window/constrained_window_views.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
23 #include "extensions/common/permissions/permission_message_provider.h" | 24 #include "extensions/common/permissions/permission_message_provider.h" |
24 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
25 #include "extensions/common/test_util.h" | 26 #include "extensions/common/test_util.h" |
26 #include "ui/views/controls/scroll_view.h" | 27 #include "ui/views/controls/scroll_view.h" |
27 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
28 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
30 #include "ui/views/window/dialog_client_view.h" | |
29 | 31 |
30 using extensions::PermissionIDSet; | 32 using extensions::PermissionIDSet; |
31 using extensions::PermissionMessage; | 33 using extensions::PermissionMessage; |
32 using extensions::PermissionMessages; | 34 using extensions::PermissionMessages; |
33 | 35 |
34 class ExtensionInstallDialogViewTestBase : public ExtensionBrowserTest { | 36 class ExtensionInstallDialogViewTestBase : public ExtensionBrowserTest { |
35 protected: | 37 protected: |
36 explicit ExtensionInstallDialogViewTestBase( | 38 explicit ExtensionInstallDialogViewTestBase( |
37 ExtensionInstallPrompt::PromptType prompt_type); | 39 ExtensionInstallPrompt::PromptType prompt_type); |
38 ~ExtensionInstallDialogViewTestBase() override {} | 40 ~ExtensionInstallDialogViewTestBase() override {} |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 } | 147 } |
146 | 148 |
147 class ExtensionInstallDialogViewTest | 149 class ExtensionInstallDialogViewTest |
148 : public ExtensionInstallDialogViewTestBase { | 150 : public ExtensionInstallDialogViewTestBase { |
149 protected: | 151 protected: |
150 ExtensionInstallDialogViewTest() | 152 ExtensionInstallDialogViewTest() |
151 : ExtensionInstallDialogViewTestBase( | 153 : ExtensionInstallDialogViewTestBase( |
152 ExtensionInstallPrompt::INSTALL_PROMPT) {} | 154 ExtensionInstallPrompt::INSTALL_PROMPT) {} |
153 ~ExtensionInstallDialogViewTest() override {} | 155 ~ExtensionInstallDialogViewTest() override {} |
154 | 156 |
157 views::DialogDelegateView* CreateAndShowPrompt( | |
158 ExtensionInstallPromptTestHelper* helper) { | |
159 scoped_ptr<ExtensionInstallDialogView> dialog( | |
160 new ExtensionInstallDialogView(profile(), web_contents(), | |
161 helper->GetCallback(), CreatePrompt())); | |
162 views::DialogDelegateView* delegate_view = dialog.get(); | |
163 | |
164 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget( | |
165 dialog.release(), nullptr, browser()->window()->GetNativeWindow()); | |
166 modal_dialog->Show(); | |
msw
2016/02/11 18:08:58
I suppose it's potentially necessary to create the
Evan Stade
2016/02/11 20:02:11
i don't think it would interfere with other tests,
| |
167 | |
168 return delegate_view; | |
169 } | |
170 | |
155 private: | 171 private: |
156 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTest); | 172 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTest); |
157 }; | 173 }; |
158 | 174 |
159 // Verifies that the delegate is notified when the user selects to accept or | 175 // Verifies that the delegate is notified when the user selects to accept or |
160 // cancel the install. | 176 // cancel the install. |
161 IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) { | 177 IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) { |
162 { | 178 { |
179 // User presses install. | |
163 ExtensionInstallPromptTestHelper helper; | 180 ExtensionInstallPromptTestHelper helper; |
164 scoped_ptr<ExtensionInstallDialogView> dialog( | 181 views::DialogDelegateView* delegate_view = CreateAndShowPrompt(&helper); |
165 new ExtensionInstallDialogView(profile(), web_contents(), | 182 delegate_view->GetDialogClientView()->AcceptWindow(); |
msw
2016/02/11 18:08:58
Can you stick with DialogDelegateView::Accept/Canc
Evan Stade
2016/02/11 20:02:11
that seems like worse coverage. The test seems lik
| |
166 helper.GetCallback(), | |
167 CreatePrompt())); | |
168 views::DialogDelegateView* delegate_view = dialog.get(); | |
169 | |
170 delegate_view->Accept(); | |
171 delegate_view->OnClosed(); | |
172 dialog.reset(); | |
173 | |
174 EXPECT_EQ(ExtensionInstallPrompt::Result::ACCEPTED, helper.result()); | 183 EXPECT_EQ(ExtensionInstallPrompt::Result::ACCEPTED, helper.result()); |
175 } | 184 } |
176 | |
177 { | 185 { |
178 // The user cancels the install. | 186 // User presses cancel. |
179 ExtensionInstallPromptTestHelper helper; | 187 ExtensionInstallPromptTestHelper helper; |
180 scoped_ptr<ExtensionInstallDialogView> dialog( | 188 views::DialogDelegateView* delegate_view = CreateAndShowPrompt(&helper); |
181 new ExtensionInstallDialogView(profile(), web_contents(), | 189 delegate_view->GetDialogClientView()->CancelWindow(); |
182 helper.GetCallback(), | |
183 CreatePrompt())); | |
184 views::DialogDelegateView* delegate_view = dialog.get(); | |
185 | |
186 delegate_view->Cancel(); | |
187 delegate_view->OnClosed(); | |
188 dialog.reset(); | |
189 | |
190 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result()); | 190 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result()); |
191 } | 191 } |
192 | |
193 { | 192 { |
194 // Corner case: Dialog is closed without the user explicitly choosing to | 193 // Dialog is closed without the user explicitly choosing to proceed or |
195 // proceed or cancel. | 194 // cancel. |
196 ExtensionInstallPromptTestHelper helper; | 195 ExtensionInstallPromptTestHelper helper; |
197 scoped_ptr<ExtensionInstallDialogView> dialog( | 196 views::DialogDelegateView* delegate_view = CreateAndShowPrompt(&helper); |
198 new ExtensionInstallDialogView(profile(), web_contents(), | 197 delegate_view->GetWidget()->Close(); |
199 helper.GetCallback(), | |
200 CreatePrompt())); | |
201 dialog.reset(); | |
202 | |
203 // TODO(devlin): Should this be ABORTED? | 198 // TODO(devlin): Should this be ABORTED? |
204 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result()); | 199 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result()); |
205 } | 200 } |
206 } | 201 } |
OLD | NEW |