Chromium Code Reviews| 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_icon_manager.h" | 8 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt_experiment.h" | 10 #include "chrome/browser/extensions/extension_install_prompt_experiment.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 prompt_ = prompt; | 62 prompt_ = prompt; |
| 63 } | 63 } |
| 64 ExtensionInstallPrompt::Prompt* get_prompt() { | 64 ExtensionInstallPrompt::Prompt* get_prompt() { |
| 65 return prompt_; | 65 return prompt_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 ExtensionInstallPrompt::Prompt* prompt_; | 69 ExtensionInstallPrompt::Prompt* prompt_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 class ScrollbarTest : public ExtensionBrowserTest { | 72 class ExtensionInstallDialogViewTestBase : public ExtensionBrowserTest { |
| 73 protected: | 73 protected: |
| 74 ScrollbarTest(); | 74 ExtensionInstallDialogViewTestBase( |
|
tapted
2014/09/08 07:42:20
nit: explicit
tmdiep
2014/09/08 08:26:08
Done.
| |
| 75 virtual ~ScrollbarTest() {} | 75 ExtensionInstallPrompt::PromptType prompt_type); |
| 76 virtual ~ExtensionInstallDialogViewTestBase() {} | |
| 76 | 77 |
| 77 virtual void SetUpOnMainThread() OVERRIDE; | 78 virtual void SetUpOnMainThread() OVERRIDE; |
| 78 | 79 |
| 80 ExtensionInstallPrompt::Prompt* prompt() { return prompt_.get(); } | |
| 81 content::WebContents* web_contents() { return web_contents_; } | |
| 82 MockExtensionInstallPromptDelegate* delegate() { return &delegate_; } | |
| 83 | |
| 79 void SetPromptPermissions(std::vector<base::string16> permissions); | 84 void SetPromptPermissions(std::vector<base::string16> permissions); |
| 80 void SetPromptDetails(std::vector<base::string16> details); | 85 void SetPromptDetails(std::vector<base::string16> details); |
| 81 void SetPromptRetainedFiles(std::vector<base::FilePath> files); | 86 void SetPromptRetainedFiles(std::vector<base::FilePath> files); |
| 82 | 87 |
| 83 bool IsScrollbarVisible(); | |
| 84 | |
| 85 private: | 88 private: |
| 86 const extensions::Extension* extension_; | 89 const extensions::Extension* extension_; |
| 87 MockExtensionInstallPrompt* install_prompt_; | 90 MockExtensionInstallPrompt* install_prompt_; |
| 88 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_; | 91 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_; |
| 89 content::WebContents* web_contents_; | 92 content::WebContents* web_contents_; |
| 93 MockExtensionInstallPromptDelegate delegate_; | |
| 90 }; | 94 }; |
|
tapted
2014/09/08 07:42:21
nit: DISALLOW_COPY_AND_ASSIGN(..). The two new cla
tmdiep
2014/09/08 08:26:08
Done.
| |
| 91 | 95 |
| 92 ScrollbarTest::ScrollbarTest() : | 96 ExtensionInstallDialogViewTestBase::ExtensionInstallDialogViewTestBase( |
| 93 extension_(NULL), | 97 ExtensionInstallPrompt::PromptType prompt_type) |
| 94 install_prompt_(NULL), | 98 : extension_(NULL), |
| 95 prompt_(new ExtensionInstallPrompt::Prompt( | 99 install_prompt_(NULL), |
| 96 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), | 100 prompt_(new ExtensionInstallPrompt::Prompt(prompt_type)), |
| 97 web_contents_(NULL) {} | 101 web_contents_(NULL) { |
| 102 } | |
| 98 | 103 |
| 99 void ScrollbarTest::SetUpOnMainThread() { | 104 void ExtensionInstallDialogViewTestBase::SetUpOnMainThread() { |
| 100 ExtensionBrowserTest::SetUpOnMainThread(); | 105 ExtensionBrowserTest::SetUpOnMainThread(); |
| 106 | |
| 101 extension_ = ExtensionBrowserTest::LoadExtension(test_data_dir_.AppendASCII( | 107 extension_ = ExtensionBrowserTest::LoadExtension(test_data_dir_.AppendASCII( |
| 102 "install_prompt/permissions_scrollbar_regression")); | 108 "install_prompt/permissions_scrollbar_regression")); |
| 103 | 109 |
| 104 web_contents_ = browser()->tab_strip_model()->GetWebContentsAt(0); | 110 web_contents_ = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 105 | 111 |
| 106 install_prompt_ = new MockExtensionInstallPrompt(web_contents_); | 112 install_prompt_ = new MockExtensionInstallPrompt(web_contents_); |
| 107 install_prompt_->set_prompt(prompt_.get()); | 113 install_prompt_->set_prompt(prompt_.get()); |
| 108 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 114 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
| 109 prompt_->set_extension(extension_); | 115 prompt_->set_extension(extension_); |
| 110 | 116 |
| 111 scoped_ptr<ExtensionIconManager> icon_manager(new ExtensionIconManager()); | 117 scoped_ptr<ExtensionIconManager> icon_manager(new ExtensionIconManager()); |
| 112 const SkBitmap icon_bitmap = icon_manager->GetIcon(extension_->id()); | 118 const SkBitmap icon_bitmap = icon_manager->GetIcon(extension_->id()); |
| 113 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(icon_bitmap); | 119 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(icon_bitmap); |
| 114 prompt_->set_icon(icon); | 120 prompt_->set_icon(icon); |
| 115 | 121 |
| 116 this->SetPromptPermissions(std::vector<base::string16>()); | 122 this->SetPromptPermissions(std::vector<base::string16>()); |
| 117 this->SetPromptDetails(std::vector<base::string16>()); | 123 this->SetPromptDetails(std::vector<base::string16>()); |
| 118 this->SetPromptRetainedFiles(std::vector<base::FilePath>()); | 124 this->SetPromptRetainedFiles(std::vector<base::FilePath>()); |
| 119 } | 125 } |
| 120 | 126 |
| 121 void ScrollbarTest::SetPromptPermissions( | 127 void ExtensionInstallDialogViewTestBase::SetPromptPermissions( |
| 122 std::vector<base::string16> permissions) { | 128 std::vector<base::string16> permissions) { |
| 123 prompt_->SetPermissions(permissions); | 129 prompt_->SetPermissions(permissions); |
| 124 } | 130 } |
| 125 | 131 |
| 126 void ScrollbarTest::SetPromptDetails( | 132 void ExtensionInstallDialogViewTestBase::SetPromptDetails( |
| 127 std::vector<base::string16> details) { | 133 std::vector<base::string16> details) { |
| 128 prompt_->SetPermissionsDetails(details); | 134 prompt_->SetPermissionsDetails(details); |
| 129 } | 135 } |
| 130 | 136 |
| 131 void ScrollbarTest::SetPromptRetainedFiles( | 137 void ExtensionInstallDialogViewTestBase::SetPromptRetainedFiles( |
| 132 std::vector<base::FilePath> files) { | 138 std::vector<base::FilePath> files) { |
| 133 prompt_->set_retained_files(files); | 139 prompt_->set_retained_files(files); |
| 134 } | 140 } |
| 135 | 141 |
| 142 class ScrollbarTest : public ExtensionInstallDialogViewTestBase { | |
| 143 protected: | |
| 144 ScrollbarTest(); | |
| 145 virtual ~ScrollbarTest() {} | |
| 146 | |
| 147 bool IsScrollbarVisible(); | |
| 148 }; | |
| 149 | |
| 150 ScrollbarTest::ScrollbarTest() | |
| 151 : ExtensionInstallDialogViewTestBase( | |
| 152 ExtensionInstallPrompt::PERMISSIONS_PROMPT) { | |
| 153 } | |
| 154 | |
| 136 bool ScrollbarTest::IsScrollbarVisible() { | 155 bool ScrollbarTest::IsScrollbarVisible() { |
| 137 ExtensionInstallPrompt::ShowParams show_params(web_contents_); | 156 ExtensionInstallPrompt::ShowParams show_params(web_contents()); |
| 138 MockExtensionInstallPromptDelegate delegate; | 157 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( |
| 139 ExtensionInstallDialogView* dialog = | 158 show_params.navigator, delegate(), prompt()); |
| 140 new ExtensionInstallDialogView(show_params.navigator, &delegate, prompt_); | |
| 141 | 159 |
| 142 // Create the modal view around the install dialog view. | 160 // Create the modal view around the install dialog view. |
| 143 views::Widget* modal = | 161 views::Widget* modal = |
| 144 CreateBrowserModalDialogViews(dialog, show_params.parent_window); | 162 CreateBrowserModalDialogViews(dialog, show_params.parent_window); |
| 145 modal->Show(); | 163 modal->Show(); |
| 146 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 164 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 147 base::RunLoop().RunUntilIdle(); | 165 base::RunLoop().RunUntilIdle(); |
| 148 | 166 |
| 149 // Check if the vertical scrollbar is visible. | 167 // Check if the vertical scrollbar is visible. |
| 150 return dialog->scroll_view()->vertical_scroll_bar()->visible(); | 168 return dialog->scroll_view()->vertical_scroll_bar()->visible(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 171 base::string16 permission_string(base::ASCIIToUTF16( | 189 base::string16 permission_string(base::ASCIIToUTF16( |
| 172 "Read and modify your data on *.facebook.com")); | 190 "Read and modify your data on *.facebook.com")); |
| 173 std::vector<base::string16> permissions; | 191 std::vector<base::string16> permissions; |
| 174 permissions.push_back(permission_string); | 192 permissions.push_back(permission_string); |
| 175 this->SetPromptPermissions(permissions); | 193 this->SetPromptPermissions(permissions); |
| 176 std::vector<base::string16> details; | 194 std::vector<base::string16> details; |
| 177 details.push_back(base::string16()); | 195 details.push_back(base::string16()); |
| 178 this->SetPromptDetails(details); | 196 this->SetPromptDetails(details); |
| 179 ASSERT_FALSE(IsScrollbarVisible()) << "Scrollbar is visible"; | 197 ASSERT_FALSE(IsScrollbarVisible()) << "Scrollbar is visible"; |
| 180 } | 198 } |
| 199 | |
| 200 class ExtensionInstallDialogViewTest | |
| 201 : public ExtensionInstallDialogViewTestBase { | |
| 202 protected: | |
| 203 ExtensionInstallDialogViewTest() | |
| 204 : ExtensionInstallDialogViewTestBase( | |
| 205 ExtensionInstallPrompt::INSTALL_PROMPT) {} | |
| 206 virtual ~ExtensionInstallDialogViewTest() {} | |
| 207 }; | |
| 208 | |
| 209 // Verifies that the delegate is notified when the user selects to accept or | |
| 210 // cancel the install. | |
| 211 IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) { | |
| 212 { | |
| 213 // The user confirms the install. | |
| 214 MockExtensionInstallPromptDelegate delegate; | |
| 215 scoped_ptr<ExtensionInstallDialogView> dialog( | |
| 216 new ExtensionInstallDialogView(web_contents(), &delegate, prompt())); | |
| 217 views::DialogDelegateView* delegate_view = | |
| 218 static_cast<views::DialogDelegateView*>(dialog.get()); | |
|
tapted
2014/09/08 07:42:20
I think you can just assign it rather than static_
tmdiep
2014/09/08 08:26:08
Done.
| |
| 219 | |
| 220 delegate_view->Accept(); | |
| 221 delegate_view->OnClosed(); | |
| 222 dialog.reset(); | |
|
tapted
2014/09/08 07:42:20
Can you let this just go out of scope?
tmdiep
2014/09/08 08:26:08
I wanted to make sure that the dialog is completel
| |
| 223 | |
| 224 ASSERT_EQ(0, delegate.abort_count()); | |
|
tapted
2014/09/08 07:42:20
nit: ASSERT->EXPECT. Typically I see ASSERT just f
tmdiep
2014/09/08 08:26:08
Done.
| |
| 225 ASSERT_EQ(1, delegate.proceed_count()); | |
| 226 } | |
| 227 | |
| 228 { | |
| 229 // The user cancels the install. | |
| 230 MockExtensionInstallPromptDelegate delegate; | |
| 231 scoped_ptr<ExtensionInstallDialogView> dialog( | |
| 232 new ExtensionInstallDialogView(web_contents(), &delegate, prompt())); | |
| 233 views::DialogDelegateView* delegate_view = | |
| 234 static_cast<views::DialogDelegateView*>(dialog.get()); | |
| 235 | |
| 236 delegate_view->Cancel(); | |
| 237 delegate_view->OnClosed(); | |
| 238 dialog.reset(); | |
| 239 | |
| 240 ASSERT_EQ(1, delegate.abort_count()); | |
| 241 ASSERT_EQ(0, delegate.proceed_count()); | |
| 242 } | |
| 243 | |
| 244 { | |
| 245 // Corner case: Dialog is closed without the user explicitly choosing to | |
| 246 // proceed or cancel. | |
| 247 MockExtensionInstallPromptDelegate delegate; | |
| 248 scoped_ptr<ExtensionInstallDialogView> dialog( | |
| 249 new ExtensionInstallDialogView(web_contents(), &delegate, prompt())); | |
| 250 views::DialogDelegateView* delegate_view = | |
| 251 static_cast<views::DialogDelegateView*>(dialog.get()); | |
| 252 | |
| 253 delegate_view->OnClosed(); | |
|
tapted
2014/09/08 07:42:20
The test might be more compelling if you can do di
tmdiep
2014/09/08 08:26:08
Yeah, I agree that it would be a better test of th
tapted
2014/09/08 09:28:56
CloseNow usually avoids being flaky (Widget::Close
| |
| 254 dialog.reset(); | |
| 255 | |
| 256 ASSERT_EQ(1, delegate.abort_count()); | |
| 257 ASSERT_EQ(0, delegate.proceed_count()); | |
| 258 } | |
| 259 } | |
| OLD | NEW |