OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/run_loop.h" | |
6 #include "base/strings/utf_string_conversions.h" | |
7 #include "chrome/browser/extensions/extension_browsertest.h" | |
8 #include "chrome/browser/extensions/extension_icon_manager.h" | |
9 #include "chrome/browser/extensions/extension_install_prompt.h" | |
10 #include "chrome/browser/extensions/extension_install_prompt_experiment.h" | |
11 #include "chrome/browser/ui/browser.h" | |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
13 #include "chrome/browser/ui/views/constrained_window_views.h" | |
14 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h" | |
15 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | |
16 #include "chrome/common/extensions/extension_test_util.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "extensions/common/extension.h" | |
19 #include "extensions/common/permissions/permissions_data.h" | |
20 #include "extensions/common/test_util.h" | |
21 #include "ui/views/view.h" | |
22 | |
23 // A simple delegate implementation that counts the number of times | |
24 // |InstallUIProceed| and |InstallUIAbort| are called. | |
25 class MockExtensionInstallPromptDelegate | |
26 : public ExtensionInstallPrompt::Delegate { | |
27 public: | |
28 MockExtensionInstallPromptDelegate() | |
29 : proceed_count_(0), | |
30 abort_count_(0) {} | |
31 | |
32 // ExtensionInstallPrompt::Delegate overrides. | |
33 virtual void InstallUIProceed() OVERRIDE; | |
34 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | |
35 | |
36 int proceed_count() { return proceed_count_; } | |
37 int abort_count() { return abort_count_; } | |
38 | |
39 protected: | |
40 int proceed_count_; | |
41 int abort_count_; | |
42 }; | |
43 | |
44 void MockExtensionInstallPromptDelegate::InstallUIProceed() { | |
45 ++proceed_count_; | |
46 } | |
47 | |
48 void MockExtensionInstallPromptDelegate::InstallUIAbort(bool user_initiated) { | |
49 ++abort_count_; | |
50 } | |
51 | |
52 // This lets us construct the parent for the prompt we're constructing in our | |
53 // tests. | |
54 class MockExtensionInstallPrompt : public ExtensionInstallPrompt { | |
55 public: | |
56 explicit MockExtensionInstallPrompt(content::WebContents* web_contents) : | |
57 ExtensionInstallPrompt(web_contents), | |
Finnur
2014/07/16 10:36:12
Weird indentation (also colon should be at the beg
Chris Thompson
2014/07/16 20:13:29
Done.
| |
58 prompt_(NULL) {} | |
59 virtual ~MockExtensionInstallPrompt() {} | |
60 void set_prompt(ExtensionInstallPrompt::Prompt* prompt) { | |
61 prompt_ = prompt; | |
62 } | |
63 ExtensionInstallPrompt::Prompt* get_prompt() { | |
64 return prompt_; | |
65 } | |
66 | |
67 private: | |
68 ExtensionInstallPrompt::Prompt* prompt_; | |
69 }; | |
70 | |
71 class ScrollbarTest : public ExtensionBrowserTest { | |
Finnur
2014/07/16 10:36:12
Thank you so much for adding a test for this...
Chris Thompson
2014/07/16 20:13:29
Acknowledged. If I had more time I'd want to try p
Finnur
2014/07/17 10:12:14
That would be fantastic!
| |
72 protected: | |
73 ScrollbarTest(); | |
74 virtual ~ScrollbarTest() {} | |
75 | |
76 virtual void SetUpOnMainThread() OVERRIDE; | |
77 | |
78 void SetPromptPermissions(std::vector<base::string16> permissions); | |
79 void SetPromptDetails(std::vector<base::string16> details); | |
80 void SetPromptRetainedFiles(std::vector<base::FilePath> files); | |
81 | |
82 bool IsScrollbarVisible(); | |
83 | |
84 private: | |
85 const extensions::Extension* extension_; | |
86 MockExtensionInstallPrompt* install_prompt_; | |
87 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_; | |
88 content::WebContents* web_contents_; | |
89 }; | |
90 | |
91 ScrollbarTest::ScrollbarTest() : | |
92 extension_(NULL), | |
93 install_prompt_(NULL), | |
94 prompt_(new ExtensionInstallPrompt::Prompt( | |
95 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), | |
96 web_contents_(NULL) {} | |
97 | |
98 void ScrollbarTest::SetUpOnMainThread() { | |
99 ExtensionBrowserTest::SetUpOnMainThread(); | |
100 extension_ = ExtensionBrowserTest::LoadExtension( | |
101 test_data_dir_.AppendASCII("permissions_scrollbar_regression")); | |
102 | |
103 web_contents_ = browser()->tab_strip_model()->GetWebContentsAt(0); | |
104 | |
105 install_prompt_ = new MockExtensionInstallPrompt(web_contents_); | |
106 install_prompt_->set_prompt(prompt_); | |
107 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | |
108 prompt_->set_extension(extension_); | |
109 | |
110 scoped_ptr<ExtensionIconManager> icon_manager(new ExtensionIconManager()); | |
111 const SkBitmap icon_bitmap = icon_manager->GetIcon(extension_->id()); | |
112 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(icon_bitmap); | |
113 prompt_->set_icon(icon); | |
114 | |
115 this->SetPromptPermissions(std::vector<base::string16>()); | |
116 this->SetPromptDetails(std::vector<base::string16>()); | |
117 this->SetPromptRetainedFiles(std::vector<base::FilePath>()); | |
118 } | |
119 | |
120 void ScrollbarTest::SetPromptPermissions( | |
121 std::vector<base::string16> permissions) { | |
122 prompt_->SetPermissions(permissions); | |
123 } | |
124 | |
125 void ScrollbarTest::SetPromptDetails( | |
126 std::vector<base::string16> details) { | |
127 prompt_->SetPermissionsDetails(details); | |
128 } | |
129 | |
130 void ScrollbarTest::SetPromptRetainedFiles( | |
131 std::vector<base::FilePath> files) { | |
132 prompt_->set_retained_files(files); | |
133 } | |
134 | |
135 bool ScrollbarTest::IsScrollbarVisible() { | |
136 ExtensionInstallPrompt::ShowParams show_params(web_contents_); | |
137 MockExtensionInstallPromptDelegate delegate; | |
138 ExtensionInstallDialogView* dialog = | |
139 new ExtensionInstallDialogView(show_params.navigator, &delegate, prompt_); | |
140 | |
141 // Create the modal view around the install dialog view. | |
142 views::Widget* modal = | |
143 CreateBrowserModalDialogViews(dialog, show_params.parent_window); | |
144 modal->Show(); | |
145 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
146 base::RunLoop().RunUntilIdle(); | |
147 | |
148 // Check if the vertical scrollbar is visible. | |
149 const views::ScrollBar* scrollbar = | |
150 dialog->scroll_view()->vertical_scroll_bar(); | |
151 return scrollbar->visible(); | |
Finnur
2014/07/16 10:36:12
Just...
return dialog->scroll_view()->vertical_scr
Chris Thompson
2014/07/16 20:13:29
Missed this when I changed it to return the boolea
| |
152 } | |
153 | |
154 // Tests that a scrollbar _is_ shown for an excessively long extension | |
155 // install prompt. | |
156 IN_PROC_BROWSER_TEST_F(ScrollbarTest, LongPromptScrollbar) { | |
157 base::string16 permission_string(base::ASCIIToUTF16("Test")); | |
158 std::vector<base::string16> permissions; | |
159 std::vector<base::string16> details; | |
160 for (int i = 0; i < 20; i++) { | |
161 permissions.push_back(permission_string); | |
162 details.push_back(base::string16()); | |
163 } | |
164 this->SetPromptPermissions(permissions); | |
165 this->SetPromptDetails(details); | |
166 ASSERT_TRUE(IsScrollbarVisible()) << "Scrollbar was not visible"; | |
Finnur
2014/07/16 10:36:12
nit: s/was/is/
Chris Thompson
2014/07/16 20:13:29
Done.
| |
167 } | |
168 | |
169 // Tests that a scrollbar isn't shown for this regression case. | |
170 // See crbug.com/385570 for details. | |
171 IN_PROC_BROWSER_TEST_F(ScrollbarTest, ScrollbarRegression) { | |
172 base::string16 permission_string(base::ASCIIToUTF16( | |
173 "Read and modify your data on *.facebook.com")); | |
174 std::vector<base::string16> permissions; | |
175 permissions.push_back(permission_string); | |
176 this->SetPromptPermissions(permissions); | |
177 std::vector<base::string16> details; | |
178 details.push_back(base::string16()); | |
179 this->SetPromptDetails(details); | |
180 ASSERT_FALSE(IsScrollbarVisible()) << "Scrollbar was visible"; | |
Finnur
2014/07/16 10:36:12
nit: s/was/is/
Chris Thompson
2014/07/16 20:13:29
Done.
| |
181 } | |
OLD | NEW |