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

Side by Side Diff: chrome/browser/ui/views/passwords/password_dialog_view_browsertest.cc

Issue 2875513003: cleanup: make WidgetClosingObserver as test support (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble_unittest.cc ('k') | ui/views/test/widget_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/test/test_browser_dialog.h" 12 #include "chrome/browser/ui/test/test_browser_dialog.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h" 14 #include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h"
15 #include "chrome/browser/ui/views/passwords/auto_signin_first_run_dialog_view.h" 15 #include "chrome/browser/ui/views/passwords/auto_signin_first_run_dialog_view.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/password_manager/core/browser/password_bubble_experiment.h" 18 #include "components/password_manager/core/browser/password_bubble_experiment.h"
19 #include "components/password_manager/core/common/password_manager_pref_names.h" 19 #include "components/password_manager/core/common/password_manager_pref_names.h"
20 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
21 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "ui/views/test/widget_test.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 using ::testing::Field; 26 using ::testing::Field;
26 27
27 namespace { 28 namespace {
28 29
29 // A helper class that will create FakeURLFetcher and record the requested URLs. 30 // A helper class that will create FakeURLFetcher and record the requested URLs.
30 class TestURLFetcherCallback { 31 class TestURLFetcherCallback {
31 public: 32 public:
32 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher( 33 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher(
33 const GURL& url, 34 const GURL& url,
34 net::URLFetcherDelegate* d, 35 net::URLFetcherDelegate* d,
35 const std::string& response_data, 36 const std::string& response_data,
36 net::HttpStatusCode response_code, 37 net::HttpStatusCode response_code,
37 net::URLRequestStatus::Status status) { 38 net::URLRequestStatus::Status status) {
38 OnRequestDone(url); 39 OnRequestDone(url);
39 return std::unique_ptr<net::FakeURLFetcher>( 40 return std::unique_ptr<net::FakeURLFetcher>(
40 new net::FakeURLFetcher(url, d, response_data, response_code, status)); 41 new net::FakeURLFetcher(url, d, response_data, response_code, status));
41 } 42 }
42 43
43 MOCK_METHOD1(OnRequestDone, void(const GURL&)); 44 MOCK_METHOD1(OnRequestDone, void(const GURL&));
44 }; 45 };
45 46
46 // A Widget observer class used to observe bubbles closing.
47 class BubbleCloseObserver : public views::WidgetObserver {
48 public:
49 explicit BubbleCloseObserver(views::DialogDelegateView* bubble);
50 ~BubbleCloseObserver() override;
51
52 bool widget_closed() const { return !widget_; }
53
54 private:
55 // WidgetObserver:
56 void OnWidgetClosing(views::Widget* widget) override;
57
58 views::Widget* widget_;
59
60 DISALLOW_COPY_AND_ASSIGN(BubbleCloseObserver);
61 };
62
63 BubbleCloseObserver::BubbleCloseObserver(views::DialogDelegateView* bubble)
64 : widget_(bubble->GetWidget()) {
65 widget_->AddObserver(this);
66 }
67
68 BubbleCloseObserver::~BubbleCloseObserver() {
69 if (widget_)
70 widget_->RemoveObserver(this);
71 }
72
73 void BubbleCloseObserver::OnWidgetClosing(views::Widget* widget) {
74 DCHECK_EQ(widget_, widget);
75 widget_->RemoveObserver(this);
76 widget_ = nullptr;
77 }
78
79 // ManagePasswordsUIController subclass to capture the dialog instance 47 // ManagePasswordsUIController subclass to capture the dialog instance
80 class TestManagePasswordsUIController : public ManagePasswordsUIController { 48 class TestManagePasswordsUIController : public ManagePasswordsUIController {
81 public: 49 public:
82 explicit TestManagePasswordsUIController(content::WebContents* web_contents); 50 explicit TestManagePasswordsUIController(content::WebContents* web_contents);
83 51
84 void OnDialogHidden() override; 52 void OnDialogHidden() override;
85 AccountChooserPrompt* CreateAccountChooser( 53 AccountChooserPrompt* CreateAccountChooser(
86 PasswordDialogController* controller) override; 54 PasswordDialogController* controller) override;
87 AutoSigninFirstRunPrompt* CreateAutoSigninPrompt( 55 AutoSigninFirstRunPrompt* CreateAutoSigninPrompt(
88 PasswordDialogController* controller) override; 56 PasswordDialogController* controller) override;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form)); 181 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form));
214 GURL icon_url("https://google.com/icon.png"); 182 GURL icon_url("https://google.com/icon.png");
215 form.icon_url = icon_url; 183 form.icon_url = icon_url;
216 form.display_name = base::ASCIIToUTF16("Peter Pan"); 184 form.display_name = base::ASCIIToUTF16("Peter Pan");
217 form.federation_origin = url::Origin(GURL("https://google.com/federation")); 185 form.federation_origin = url::Origin(GURL("https://google.com/federation"));
218 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form)); 186 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form));
219 187
220 // Prepare to capture the network request. 188 // Prepare to capture the network request.
221 TestURLFetcherCallback url_callback; 189 TestURLFetcherCallback url_callback;
222 net::FakeURLFetcherFactory factory( 190 net::FakeURLFetcherFactory factory(
223 NULL, base::Bind(&TestURLFetcherCallback::CreateURLFetcher, 191 nullptr, base::Bind(&TestURLFetcherCallback::CreateURLFetcher,
224 base::Unretained(&url_callback))); 192 base::Unretained(&url_callback)));
225 factory.SetFakeResponse(icon_url, std::string(), net::HTTP_OK, 193 factory.SetFakeResponse(icon_url, std::string(), net::HTTP_OK,
226 net::URLRequestStatus::FAILED); 194 net::URLRequestStatus::FAILED);
227 EXPECT_CALL(url_callback, OnRequestDone(icon_url)); 195 EXPECT_CALL(url_callback, OnRequestDone(icon_url));
228 196
229 SetupChooseCredentials(std::move(local_credentials), origin); 197 SetupChooseCredentials(std::move(local_credentials), origin);
230 ASSERT_TRUE(controller()->current_account_chooser()); 198 ASSERT_TRUE(controller()->current_account_chooser());
231 AccountChooserDialogView* dialog = controller()->current_account_chooser(); 199 AccountChooserDialogView* dialog = controller()->current_account_chooser();
232 EXPECT_CALL(*this, OnChooseCredential(nullptr)); 200 EXPECT_CALL(*this, OnChooseCredential(nullptr));
233 EXPECT_CALL(*controller(), OnDialogClosed()); 201 EXPECT_CALL(*controller(), OnDialogClosed());
234 dialog->GetWidget()->Close(); 202 dialog->GetWidget()->Close();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 autofill::PasswordForm form; 263 autofill::PasswordForm form;
296 form.origin = origin; 264 form.origin = origin;
297 form.display_name = base::ASCIIToUTF16("Peter"); 265 form.display_name = base::ASCIIToUTF16("Peter");
298 form.username_value = base::ASCIIToUTF16("peter@pan.test"); 266 form.username_value = base::ASCIIToUTF16("peter@pan.test");
299 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form)); 267 local_credentials.push_back(base::MakeUnique<autofill::PasswordForm>(form));
300 268
301 SetupChooseCredentials(std::move(local_credentials), origin); 269 SetupChooseCredentials(std::move(local_credentials), origin);
302 270
303 EXPECT_TRUE(controller()->current_account_chooser()); 271 EXPECT_TRUE(controller()->current_account_chooser());
304 views::DialogDelegateView* dialog = controller()->current_account_chooser(); 272 views::DialogDelegateView* dialog = controller()->current_account_chooser();
305 BubbleCloseObserver bubble_observer(dialog); 273 views::test::WidgetClosingObserver bubble_observer(dialog->GetWidget());
306 EXPECT_CALL(*this, OnChooseCredential(testing::Pointee(form))); 274 EXPECT_CALL(*this, OnChooseCredential(testing::Pointee(form)));
307 dialog->Accept(); 275 dialog->Accept();
308 EXPECT_TRUE(bubble_observer.widget_closed()); 276 EXPECT_TRUE(bubble_observer.widget_closed());
309 } 277 }
310 278
311 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, 279 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest,
312 PopupAccountChooserWithSingleCredentialReturnNonEmpty) { 280 PopupAccountChooserWithSingleCredentialReturnNonEmpty) {
313 GURL origin("https://example.com"); 281 GURL origin("https://example.com");
314 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; 282 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
315 autofill::PasswordForm form; 283 autofill::PasswordForm form;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 369
402 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) { 370 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) {
403 EXPECT_TRUE( 371 EXPECT_TRUE(
404 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( 372 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
405 browser()->profile()->GetPrefs())); 373 browser()->profile()->GetPrefs()));
406 controller()->OnPromptEnableAutoSignin(); 374 controller()->OnPromptEnableAutoSignin();
407 ASSERT_TRUE(controller()->current_autosignin_prompt()); 375 ASSERT_TRUE(controller()->current_autosignin_prompt());
408 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); 376 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState());
409 AutoSigninFirstRunDialogView* dialog = 377 AutoSigninFirstRunDialogView* dialog =
410 controller()->current_autosignin_prompt(); 378 controller()->current_autosignin_prompt();
411 BubbleCloseObserver bubble_observer(dialog); 379 views::test::WidgetClosingObserver bubble_observer(dialog->GetWidget());
412 ui::Accelerator esc(ui::VKEY_ESCAPE, 0); 380 ui::Accelerator esc(ui::VKEY_ESCAPE, 0);
413 EXPECT_CALL(*controller(), OnDialogClosed()); 381 EXPECT_CALL(*controller(), OnDialogClosed());
414 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc)); 382 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc));
415 EXPECT_TRUE(bubble_observer.widget_closed()); 383 EXPECT_TRUE(bubble_observer.widget_closed());
416 content::RunAllPendingInMessageLoop(); 384 content::RunAllPendingInMessageLoop();
417 testing::Mock::VerifyAndClearExpectations(controller()); 385 testing::Mock::VerifyAndClearExpectations(controller());
418 EXPECT_TRUE( 386 EXPECT_TRUE(
419 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( 387 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
420 browser()->profile()->GetPrefs())); 388 browser()->profile()->GetPrefs()));
421 } 389 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 RunDialog(); 466 RunDialog();
499 } 467 }
500 468
501 IN_PROC_BROWSER_TEST_F( 469 IN_PROC_BROWSER_TEST_F(
502 PasswordDialogViewTest, 470 PasswordDialogViewTest,
503 InvokeDialog_PopupAccountChooserWithSingleCredentialClickSignIn) { 471 InvokeDialog_PopupAccountChooserWithSingleCredentialClickSignIn) {
504 RunDialog(); 472 RunDialog();
505 } 473 }
506 474
507 } // namespace 475 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble_unittest.cc ('k') | ui/views/test/widget_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698