Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa_browsertest.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa_browsertest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9acae1a15a7f48f774a9a50bf0e0b6c1ad391fd |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa_browsertest.mm |
| @@ -0,0 +1,101 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/guid.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#import "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "components/autofill/core/browser/card_unmask_delegate.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +namespace autofill { |
| + |
| +namespace { |
| + |
| +class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl, |
| + public CardUnmaskDelegate { |
| + public: |
| + TestCardUnmaskPromptController( |
| + content::WebContents* contents, |
| + scoped_refptr<content::MessageLoopRunner> runner) |
| + : CardUnmaskPromptControllerImpl(contents), |
| + runner_(runner), |
| + weak_factory_(this) {} |
| + |
| + ~TestCardUnmaskPromptController() {} |
| + |
| + // CardUnmaskPromptController implementation. |
| + void OnUnmaskDialogClosed() override { |
| + DCHECK(runner_); |
| + CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed(); |
| + runner_->Quit(); |
| + } |
| + |
| + // CardUnmaskDelegate implementation. |
| + void OnUnmaskResponse(const base::string16& cvc, |
| + const base::string16& exp_month, |
| + const base::string16& exp_year) override {} |
| + void OnUnmaskPromptClosed() override {} |
| + |
| + void RunMessageLoop() { |
| + DCHECK(runner_); |
|
groby-ooo-7-16
2015/02/13 01:53:40
If you want to DCHECK at all, I'd say the ctor is
bondd
2015/02/13 02:37:13
Done. Removed DCHECKs.
|
| + runner_->Run(); |
| + } |
| + |
| + base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { |
| + return weak_factory_.GetWeakPtr(); |
| + } |
| + |
| + // Increase visibility for testing. |
| + CardUnmaskPromptView* view() { |
| + return CardUnmaskPromptControllerImpl::view(); |
| + } |
| + |
| + private: |
| + scoped_refptr<content::MessageLoopRunner> runner_; |
| + base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); |
| +}; |
| + |
| +class CardUnmaskPromptCocoaBrowserTest : public InProcessBrowserTest { |
| + public: |
| + CardUnmaskPromptCocoaBrowserTest() : InProcessBrowserTest() {} |
| + |
| + ~CardUnmaskPromptCocoaBrowserTest() override {} |
| + |
| + void SetUpOnMainThread() override { |
| + runner_ = new content::MessageLoopRunner; |
| + controller_ = new TestCardUnmaskPromptController( |
| + browser()->tab_strip_model()->GetActiveWebContents(), runner_); |
| + } |
| + |
| + TestCardUnmaskPromptController* controller() { return controller_; } |
| + |
| + private: |
| + // This member must outlive the controller. |
| + scoped_refptr<content::MessageLoopRunner> runner_; |
| + |
| + // The controller owns itself. |
| + TestCardUnmaskPromptController* controller_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptCocoaBrowserTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(CardUnmaskPromptCocoaBrowserTest, DisplayUI) { |
| + CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| + |
| + controller()->ShowPrompt(credit_card, controller()->GetWeakPtr()); |
| + controller()->view()->CancelForTesting(); |
| + |
| + controller()->RunMessageLoop(); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace autofill |