Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_cocoa_browsertest.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_cocoa_browsertest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e79db755be46779cc3e690229e57ccdaed613cc |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_cocoa_browsertest.mm |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
|
Evan Stade
2015/02/17 20:44:09
what makes this test file cocoa specific?
bondd
2015/02/17 23:45:11
Done. Renamed it to be platform independent. Updat
|
| +// 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/autofill/card_unmask_prompt_view_tester.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#import "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" |
|
Evan Stade
2015/02/17 20:44:09
is this used?
bondd
2015/02/17 23:45:11
Nope! Done. Probably left over from a previous pat
Evan Stade
2015/02/18 00:39:38
agreed
Evan Stade
2015/02/18 00:40:09
oops, meant to say "agreed" to the other comment (
|
| +#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 { |
| + 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() { runner_->Run(); } |
| + |
| + scoped_ptr<CardUnmaskPromptViewTester> GetViewTester() { |
| + return CardUnmaskPromptViewTester::For(view()).Pass(); |
| + } |
| + |
| + base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { |
| + return weak_factory_.GetWeakPtr(); |
| + } |
| + |
| + private: |
| + scoped_refptr<content::MessageLoopRunner> runner_; |
| + base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); |
| +}; |
| + |
| +class CardUnmaskPromptViewCocoaBrowserTest : public InProcessBrowserTest { |
| + public: |
| + CardUnmaskPromptViewCocoaBrowserTest() : InProcessBrowserTest() {} |
| + |
| + ~CardUnmaskPromptViewCocoaBrowserTest() 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(CardUnmaskPromptViewCocoaBrowserTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewCocoaBrowserTest, DisplayUI) { |
| + CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| + |
| + controller()->ShowPrompt(credit_card, controller()->GetWeakPtr()); |
| + controller()->GetViewTester()->CancelForTesting(); |
| + |
| + controller()->RunMessageLoop(); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace autofill |