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

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

Issue 2649683002: [Payments] Improve the closing of the PR dialog. (Closed)
Patch Set: addressed comments from sky 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_ 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_ 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "components/payments/payment_request.mojom.h" 15 #include "components/payments/payment_request.mojom.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h" 16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "ui/views/widget/widget_observer.h"
17 18
18 namespace content { 19 namespace content {
19 class WebContents; 20 class WebContents;
20 } // namespace content 21 } // namespace content
21 22
23 namespace views {
24 class Widget;
25 }
26
22 namespace payments { 27 namespace payments {
23 28
24 class PaymentRequest; 29 class PaymentRequest;
25 30
26 // Base class for any interactive PaymentRequest test that will need to open 31 // Base class for any interactive PaymentRequest test that will need to open
27 // the UI and interact with it. 32 // the UI and interact with it.
28 class PaymentRequestInteractiveTestBase 33 class PaymentRequestInteractiveTestBase
29 : public InProcessBrowserTest, 34 : public InProcessBrowserTest,
30 public PaymentRequestDialog::ObserverForTest { 35 public PaymentRequestDialogView::ObserverForTest,
36 public views::WidgetObserver {
31 protected: 37 protected:
32 // Test will open a browser window to |test_file_path| (relative to 38 // Test will open a browser window to |test_file_path| (relative to
33 // chrome/test/data/payments). 39 // chrome/test/data/payments).
34 explicit PaymentRequestInteractiveTestBase(const std::string& test_file_path); 40 explicit PaymentRequestInteractiveTestBase(const std::string& test_file_path);
35 ~PaymentRequestInteractiveTestBase() override; 41 ~PaymentRequestInteractiveTestBase() override;
36 42
37 void SetUpCommandLine(base::CommandLine* command_line) override; 43 void SetUpCommandLine(base::CommandLine* command_line) override;
38 void SetUpOnMainThread() override; 44 void SetUpOnMainThread() override;
39 45
40 // PaymentRequestDialog::ObserverForTest 46 // PaymentRequestDialogView::ObserverForTest
41 void OnDialogOpened() override; 47 void OnDialogOpened() override;
42 48
49 // views::WidgetObserver
50 // Effective way to be warned of all dialog closures.
51 void OnWidgetDestroyed(views::Widget* widget) override;
52
43 // Will call JavaScript to invoke the PaymentRequest dialog and verify that 53 // Will call JavaScript to invoke the PaymentRequest dialog and verify that
44 // it's open. 54 // it's open.
45 void InvokePaymentRequestUI(); 55 void InvokePaymentRequestUI();
46 56
47 // Convenience method to get a list of PaymentRequest associated with 57 // Convenience method to get a list of PaymentRequest associated with
48 // |web_contents|. 58 // |web_contents|.
49 const std::vector<PaymentRequest*> GetPaymentRequests( 59 const std::vector<PaymentRequest*> GetPaymentRequests(
50 content::WebContents* web_contents); 60 content::WebContents* web_contents);
51 61
52 content::WebContents* GetActiveWebContents(); 62 content::WebContents* GetActiveWebContents();
53 63
54 void CreatePaymentRequestForTest( 64 void CreatePaymentRequestForTest(
55 content::WebContents* web_contents, 65 content::WebContents* web_contents,
56 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); 66 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
57 67
58 net::EmbeddedTestServer* https_server() { return https_server_.get(); } 68 net::EmbeddedTestServer* https_server() { return https_server_.get(); }
59 69
60 private:
61 // Various events that can be waited on by the DialogEventObserver. 70 // Various events that can be waited on by the DialogEventObserver.
62 enum DialogEvent { 71 enum DialogEvent {
63 DIALOG_OPENED, 72 DIALOG_OPENED,
73 DIALOG_CLOSED,
64 }; 74 };
65 75
66 // DialogEventObserver is used to wait on specific events that may have 76 // 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 77 // occured before the call to Wait(), or after, in which case a RunLoop is
68 // used. 78 // used.
69 // 79 //
70 // Usage: 80 // Usage:
71 // observer_.reset(new DialogEventObserver([DialogEvent])); 81 // observer_.reset(new DialogEventObserver([DialogEvent]));
72 // 82 //
73 // Do stuff, which (a)synchronously calls observer_->Observe([DialogEvent]). 83 // Do stuff, which (a)synchronously calls observer_->Observe([DialogEvent]).
(...skipping 13 matching lines...) Expand all
87 void Observe(DialogEvent event); 97 void Observe(DialogEvent event);
88 98
89 private: 99 private:
90 DialogEvent event_; 100 DialogEvent event_;
91 bool seen_; 101 bool seen_;
92 base::RunLoop run_loop_; 102 base::RunLoop run_loop_;
93 103
94 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver); 104 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver);
95 }; 105 };
96 106
107 // Resets the event observer for a given |event|.
108 void ResetEventObserver(DialogEvent event);
109 // Wait for the event passed to ResetEventObserver() to occur.
110 void WaitForObservedEvent();
111
112 private:
113 std::unique_ptr<DialogEventObserver> event_observer_;
97 const std::string test_file_path_; 114 const std::string test_file_path_;
98 std::unique_ptr<net::EmbeddedTestServer> https_server_; 115 std::unique_ptr<net::EmbeddedTestServer> https_server_;
99 std::unique_ptr<DialogEventObserver> event_observer_;
100 116
101 DISALLOW_COPY_AND_ASSIGN(PaymentRequestInteractiveTestBase); 117 DISALLOW_COPY_AND_ASSIGN(PaymentRequestInteractiveTestBase);
102 }; 118 };
103 119
104 } // namespace payments 120 } // namespace payments
105 121
106 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_B ASE_H_ 122 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_B ASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698