Chromium Code Reviews| Index: chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc |
| diff --git a/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc b/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a4af7663856675b9d04b1e941001b618940930d3 |
| --- /dev/null |
| +++ b/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc |
| @@ -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/autofill/card_unmask_prompt_view_tester.h" |
| +#include "chrome/browser/ui/browser.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 MockCardUnmaskDelegate : public CardUnmaskDelegate { |
|
bondd
2015/02/19 00:17:20
With updated code there were compile errors on OSX
Evan Stade
2015/02/19 00:52:13
yes, agreed. But you shouldn't call this MockCardU
bondd
2015/02/19 01:02:50
Done.
|
| + public: |
| + MockCardUnmaskDelegate() : weak_factory_(this) {} |
| + |
| + // CardUnmaskDelegate implementation. |
| + void OnUnmaskResponse(const UnmaskResponse& response) override {} |
| + void OnUnmaskPromptClosed() override {} |
| + |
| + base::WeakPtr<MockCardUnmaskDelegate> GetWeakPtr() { |
| + return weak_factory_.GetWeakPtr(); |
| + } |
| + |
| + private: |
| + base::WeakPtrFactory<MockCardUnmaskDelegate> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockCardUnmaskDelegate); |
| +}; |
| + |
| +class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl { |
| + public: |
| + TestCardUnmaskPromptController( |
| + content::WebContents* contents, |
| + scoped_refptr<content::MessageLoopRunner> runner) |
| + : CardUnmaskPromptControllerImpl(contents), runner_(runner) {} |
| + |
| + ~TestCardUnmaskPromptController() {} |
| + |
| + // CardUnmaskPromptController implementation. |
| + void OnUnmaskDialogClosed() override { |
| + CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed(); |
| + runner_->Quit(); |
| + } |
| + |
| + void RunMessageLoop() { runner_->Run(); } |
| + |
| + scoped_ptr<CardUnmaskPromptViewTester> GetViewTester() { |
| + return CardUnmaskPromptViewTester::For(view()).Pass(); |
| + } |
| + |
| + private: |
| + scoped_refptr<content::MessageLoopRunner> runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); |
| +}; |
| + |
| +class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest { |
| + public: |
| + CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {} |
| + |
| + ~CardUnmaskPromptViewBrowserTest() 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(CardUnmaskPromptViewBrowserTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
| + CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| + MockCardUnmaskDelegate delegate; |
| + |
| + controller()->ShowPrompt(credit_card, delegate.GetWeakPtr()); |
| + controller()->GetViewTester()->CancelForTesting(); |
| + |
| + controller()->RunMessageLoop(); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace autofill |