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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_interactive_uitest_base.h

Issue 2631133003: [Payments] Introduce basic interactive browsertests for Payment Request (Closed)
Patch Set: ObserverForTest Created 3 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_
6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_
7
8 #include <vector>
9
10 #include "base/command_line.h"
11 #include "base/macros.h"
12 #include "base/run_loop.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "components/payments/payment_request.mojom.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17
18 namespace content {
19 class WebContents;
20 } // namespace content
21
22 namespace payments {
23
24 class PaymentRequest;
25
26 // Base class for any interactive PaymentRequest test that will need to open
27 // the UI and interact with it.
28 class PaymentRequestInteractiveTestBase
29 : public InProcessBrowserTest,
30 public PaymentRequestDialog::ObserverForTest {
31 protected:
32 // Test will open a browser window to |test_file_path| (relative to
33 // chrome/test/data/payments).
34 explicit PaymentRequestInteractiveTestBase(const std::string& test_file_path);
35 ~PaymentRequestInteractiveTestBase() override;
36
37 void SetUpCommandLine(base::CommandLine* command_line) override;
38 void SetUpOnMainThread() override;
39
40 // PaymentRequestDialog::ObserverForTest
41 void OnDialogOpened() override;
42
43 // Will call JavaScript to invoke the PaymentRequest dialog and verify that
44 // it's open.
45 void InvokePaymentRequestUI();
46
47 // Convenience method to get a list of PaymentRequest associated with
48 // |web_contents|.
49 const std::vector<PaymentRequest*> GetPaymentRequests(
50 content::WebContents* web_contents);
51
52 content::WebContents* GetActiveWebContents();
53
54 void CreatePaymentRequestForTest(
55 content::WebContents* web_contents,
56 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
57
58 net::EmbeddedTestServer* https_server() { return https_server_.get(); }
59
60 private:
61 // Various events that can be waited on by the DialogEventObserver.
62 enum DialogEvent {
63 DIALOG_OPENED,
64 };
65
66 // DialogEventObserver is used to wait on specific events that may have
67 // occured before the call to Wait(), or after, in which case a RunLoop is
68 // used.
69 //
70 // Usage:
71 // observer_.reset(new DialogEventObserver([DialogEvent]));
72 //
73 // Do stuff, which (a)synchronously calls observer_->Observe([DialogEvent]).
74 //
75 // observer_->Wait(); <- Will either return right away if event was observed,
76 // <- or use a RunLoop's Run/Quit to wait for the event.
77 class DialogEventObserver {
78 public:
79 explicit DialogEventObserver(DialogEvent event);
80 ~DialogEventObserver();
81
82 // Either returns right away if the event was observed between this object's
83 // construction and this call to Wait(), or use a RunLoop to wait for it.
84 void Wait();
85
86 // Observes the event (quits the RunLoop if it was running).
87 void Observe(DialogEvent event);
88
89 private:
90 DialogEvent event_;
91 bool seen_;
92 base::RunLoop run_loop_;
93
94 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver);
95 };
96
97 const std::string test_file_path_;
98 std::unique_ptr<net::EmbeddedTestServer> https_server_;
99 std::unique_ptr<DialogEventObserver> event_observer_;
100
101 DISALLOW_COPY_AND_ASSIGN(PaymentRequestInteractiveTestBase);
102 };
103
104 } // namespace payments
105
106 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_B ASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698