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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
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/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" 17 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
17 #include "chrome/common/extensions/extension_test_util.h" 18 #include "chrome/common/extensions/extension_test_util.h"
18 #include "components/constrained_window/constrained_window_views.h" 19 #include "components/constrained_window/constrained_window_views.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
21 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
22 #include "extensions/common/permissions/permission_message_provider.h" 23 #include "extensions/common/permissions/permission_message_provider.h"
23 #include "extensions/common/permissions/permissions_data.h" 24 #include "extensions/common/permissions/permissions_data.h"
24 #include "extensions/common/test_util.h" 25 #include "extensions/common/test_util.h"
25 #include "ui/views/controls/scroll_view.h" 26 #include "ui/views/controls/scroll_view.h"
26 #include "ui/views/view.h" 27 #include "ui/views/view.h"
27 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
28 29
29 using extensions::PermissionIDSet; 30 using extensions::PermissionIDSet;
30 using extensions::PermissionMessage; 31 using extensions::PermissionMessage;
31 using extensions::PermissionMessages; 32 using extensions::PermissionMessages;
32 33
33 // A simple delegate implementation that counts the number of times
34 // |InstallUIProceed| and |InstallUIAbort| are called.
35 class MockExtensionInstallPromptDelegate
36 : public ExtensionInstallPrompt::Delegate {
37 public:
38 MockExtensionInstallPromptDelegate()
39 : proceed_count_(0),
40 abort_count_(0) {}
41
42 // ExtensionInstallPrompt::Delegate overrides.
43 void InstallUIProceed() override;
44 void InstallUIAbort(bool user_initiated) override;
45
46 int proceed_count() { return proceed_count_; }
47 int abort_count() { return abort_count_; }
48
49 protected:
50 int proceed_count_;
51 int abort_count_;
52 };
53
54 void MockExtensionInstallPromptDelegate::InstallUIProceed() {
55 ++proceed_count_;
56 }
57
58 void MockExtensionInstallPromptDelegate::InstallUIAbort(bool user_initiated) {
59 ++abort_count_;
60 }
61
62 class ExtensionInstallDialogViewTestBase : public ExtensionBrowserTest { 34 class ExtensionInstallDialogViewTestBase : public ExtensionBrowserTest {
63 protected: 35 protected:
64 explicit ExtensionInstallDialogViewTestBase( 36 explicit ExtensionInstallDialogViewTestBase(
65 ExtensionInstallPrompt::PromptType prompt_type); 37 ExtensionInstallPrompt::PromptType prompt_type);
66 ~ExtensionInstallDialogViewTestBase() override {} 38 ~ExtensionInstallDialogViewTestBase() override {}
67 39
68 void SetUpOnMainThread() override; 40 void SetUpOnMainThread() override;
69 41
70 // Creates and returns an install prompt of |prompt_type_|, optionally setting 42 // Creates and returns an install prompt of |prompt_type_|, optionally setting
71 // |permissions|. 43 // |permissions|.
72 scoped_ptr<ExtensionInstallPrompt::Prompt> CreatePrompt(); 44 scoped_ptr<ExtensionInstallPrompt::Prompt> CreatePrompt();
73 scoped_ptr<ExtensionInstallPrompt::Prompt> CreatePrompt( 45 scoped_ptr<ExtensionInstallPrompt::Prompt> CreatePrompt(
74 const PermissionMessages& permissions); 46 const PermissionMessages& permissions);
75 47
76 content::WebContents* web_contents() { return web_contents_; } 48 content::WebContents* web_contents() { return web_contents_; }
77 MockExtensionInstallPromptDelegate* delegate() { return &delegate_; }
78 49
79 private: 50 private:
80 const extensions::Extension* extension_; 51 const extensions::Extension* extension_;
81 ExtensionInstallPrompt::PromptType prompt_type_; 52 ExtensionInstallPrompt::PromptType prompt_type_;
82 content::WebContents* web_contents_; 53 content::WebContents* web_contents_;
83 MockExtensionInstallPromptDelegate delegate_;
84 54
85 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTestBase); 55 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTestBase);
86 }; 56 };
87 57
88 ExtensionInstallDialogViewTestBase::ExtensionInstallDialogViewTestBase( 58 ExtensionInstallDialogViewTestBase::ExtensionInstallDialogViewTestBase(
89 ExtensionInstallPrompt::PromptType prompt_type) 59 ExtensionInstallPrompt::PromptType prompt_type)
90 : extension_(NULL), prompt_type_(prompt_type), web_contents_(NULL) {} 60 : extension_(NULL), prompt_type_(prompt_type), web_contents_(NULL) {}
91 61
92 void ExtensionInstallDialogViewTestBase::SetUpOnMainThread() { 62 void ExtensionInstallDialogViewTestBase::SetUpOnMainThread() {
93 ExtensionBrowserTest::SetUpOnMainThread(); 63 ExtensionBrowserTest::SetUpOnMainThread();
(...skipping 30 matching lines...) Expand all
124 }; 94 };
125 95
126 ScrollbarTest::ScrollbarTest() 96 ScrollbarTest::ScrollbarTest()
127 : ExtensionInstallDialogViewTestBase( 97 : ExtensionInstallDialogViewTestBase(
128 ExtensionInstallPrompt::PERMISSIONS_PROMPT) { 98 ExtensionInstallPrompt::PERMISSIONS_PROMPT) {
129 } 99 }
130 100
131 bool ScrollbarTest::IsScrollbarVisible( 101 bool ScrollbarTest::IsScrollbarVisible(
132 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) { 102 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) {
133 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( 103 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView(
134 profile(), web_contents(), delegate(), std::move(prompt)); 104 profile(), web_contents(), ExtensionInstallPrompt::DoneCallback(),
105 std::move(prompt));
135 106
136 // Create the modal view around the install dialog view. 107 // Create the modal view around the install dialog view.
137 views::Widget* modal = constrained_window::CreateBrowserModalDialogViews( 108 views::Widget* modal = constrained_window::CreateBrowserModalDialogViews(
138 dialog, web_contents()->GetTopLevelNativeWindow()); 109 dialog, web_contents()->GetTopLevelNativeWindow());
139 modal->Show(); 110 modal->Show();
140 content::RunAllBlockingPoolTasksUntilIdle(); 111 content::RunAllBlockingPoolTasksUntilIdle();
141 112
142 // Check if the vertical scrollbar is visible. 113 // Check if the vertical scrollbar is visible.
143 return dialog->scroll_view()->vertical_scroll_bar()->visible(); 114 return dialog->scroll_view()->vertical_scroll_bar()->visible();
144 } 115 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ~ExtensionInstallDialogViewTest() override {} 153 ~ExtensionInstallDialogViewTest() override {}
183 154
184 private: 155 private:
185 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTest); 156 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogViewTest);
186 }; 157 };
187 158
188 // Verifies that the delegate is notified when the user selects to accept or 159 // Verifies that the delegate is notified when the user selects to accept or
189 // cancel the install. 160 // cancel the install.
190 IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) { 161 IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) {
191 { 162 {
192 // The user confirms the install. 163 ExtensionInstallPromptTestHelper helper;
193 MockExtensionInstallPromptDelegate delegate;
194 scoped_ptr<ExtensionInstallDialogView> dialog( 164 scoped_ptr<ExtensionInstallDialogView> dialog(
195 new ExtensionInstallDialogView(profile(), web_contents(), &delegate, 165 new ExtensionInstallDialogView(profile(), web_contents(),
166 helper.GetCallback(),
196 CreatePrompt())); 167 CreatePrompt()));
197 views::DialogDelegateView* delegate_view = dialog.get(); 168 views::DialogDelegateView* delegate_view = dialog.get();
198 169
199 delegate_view->Accept(); 170 delegate_view->Accept();
200 delegate_view->OnClosed(); 171 delegate_view->OnClosed();
201 dialog.reset(); 172 dialog.reset();
202 173
203 EXPECT_EQ(0, delegate.abort_count()); 174 EXPECT_EQ(ExtensionInstallPrompt::Result::ACCEPTED, helper.result());
204 EXPECT_EQ(1, delegate.proceed_count());
205 } 175 }
206 176
207 { 177 {
208 // The user cancels the install. 178 // The user cancels the install.
209 MockExtensionInstallPromptDelegate delegate; 179 ExtensionInstallPromptTestHelper helper;
210 scoped_ptr<ExtensionInstallDialogView> dialog( 180 scoped_ptr<ExtensionInstallDialogView> dialog(
211 new ExtensionInstallDialogView(profile(), web_contents(), &delegate, 181 new ExtensionInstallDialogView(profile(), web_contents(),
182 helper.GetCallback(),
212 CreatePrompt())); 183 CreatePrompt()));
213 views::DialogDelegateView* delegate_view = dialog.get(); 184 views::DialogDelegateView* delegate_view = dialog.get();
214 185
215 delegate_view->Cancel(); 186 delegate_view->Cancel();
216 delegate_view->OnClosed(); 187 delegate_view->OnClosed();
217 dialog.reset(); 188 dialog.reset();
218 189
219 EXPECT_EQ(1, delegate.abort_count()); 190 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result());
220 EXPECT_EQ(0, delegate.proceed_count());
221 } 191 }
222 192
223 { 193 {
224 // Corner case: Dialog is closed without the user explicitly choosing to 194 // Corner case: Dialog is closed without the user explicitly choosing to
225 // proceed or cancel. 195 // proceed or cancel.
226 MockExtensionInstallPromptDelegate delegate; 196 ExtensionInstallPromptTestHelper helper;
227 scoped_ptr<ExtensionInstallDialogView> dialog( 197 scoped_ptr<ExtensionInstallDialogView> dialog(
228 new ExtensionInstallDialogView(profile(), web_contents(), &delegate, 198 new ExtensionInstallDialogView(profile(), web_contents(),
199 helper.GetCallback(),
229 CreatePrompt())); 200 CreatePrompt()));
230 dialog.reset(); 201 dialog.reset();
231 202
232 EXPECT_EQ(1, delegate.abort_count()); 203 // TODO(devlin): Should this be ABORTED?
233 EXPECT_EQ(0, delegate.proceed_count()); 204 EXPECT_EQ(ExtensionInstallPrompt::Result::USER_CANCELED, helper.result());
234 } 205 }
235 } 206 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_install_dialog_view.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698