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

Side by Side Diff: content/browser/payments/payment_app_browsertest.cc

Issue 2718013004: PaymentApp: Implement respondWith() in PaymentRequestEvent. (content side) (Closed)
Patch Set: rebase Created 3 years, 8 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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "components/payments/content/payment_app.mojom.h" 8 #include "components/payments/content/payment_app.mojom.h"
9 #include "content/public/browser/payment_app_provider.h" 9 #include "content/public/browser/payment_app_provider.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.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 "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace content { 19 namespace content {
20 namespace { 20 namespace {
21 21
22 void GetAllManifestsCallback(const base::Closure& done_callback, 22 void GetAllManifestsCallback(const base::Closure& done_callback,
23 PaymentAppProvider::Manifests* out_manifests, 23 PaymentAppProvider::Manifests* out_manifests,
24 PaymentAppProvider::Manifests manifests) { 24 PaymentAppProvider::Manifests manifests) {
25 *out_manifests = std::move(manifests); 25 *out_manifests = std::move(manifests);
26 done_callback.Run(); 26 done_callback.Run();
27 } 27 }
28 28
29 void InvokePaymentAppCallback(
30 const base::Closure& done_callback,
31 payments::mojom::PaymentAppResponsePtr* out_response,
32 payments::mojom::PaymentAppResponsePtr response) {
33 *out_response = std::move(response);
34 done_callback.Run();
35 }
36
29 } // namespace 37 } // namespace
30 38
31 class PaymentAppBrowserTest : public ContentBrowserTest { 39 class PaymentAppBrowserTest : public ContentBrowserTest {
32 public: 40 public:
33 PaymentAppBrowserTest() {} 41 PaymentAppBrowserTest() {}
34 ~PaymentAppBrowserTest() override {} 42 ~PaymentAppBrowserTest() override {}
35 43
36 void SetUpCommandLine(base::CommandLine* command_line) override { 44 void SetUpCommandLine(base::CommandLine* command_line) override {
37 command_line->AppendSwitch( 45 command_line->AppendSwitch(
38 switches::kEnableExperimentalWebPlatformFeatures); 46 switches::kEnableExperimentalWebPlatformFeatures);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 run_loop.Run(); 84 run_loop.Run();
77 85
78 std::vector<int64_t> ids; 86 std::vector<int64_t> ids;
79 for (const auto& manifest : manifests) { 87 for (const auto& manifest : manifests) {
80 ids.push_back(manifest.first); 88 ids.push_back(manifest.first);
81 } 89 }
82 90
83 return ids; 91 return ids;
84 } 92 }
85 93
86 void InvokePaymentApp(int64_t registration_id) { 94 payments::mojom::PaymentAppResponsePtr InvokePaymentApp(
95 int64_t registration_id) {
87 payments::mojom::PaymentAppRequestPtr app_request = 96 payments::mojom::PaymentAppRequestPtr app_request =
88 payments::mojom::PaymentAppRequest::New(); 97 payments::mojom::PaymentAppRequest::New();
89 app_request->methodData.push_back( 98 app_request->methodData.push_back(
90 payments::mojom::PaymentMethodData::New()); 99 payments::mojom::PaymentMethodData::New());
91 app_request->total = payments::mojom::PaymentItem::New(); 100 app_request->total = payments::mojom::PaymentItem::New();
92 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); 101 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New();
102
103 base::RunLoop run_loop;
104 payments::mojom::PaymentAppResponsePtr response;
93 PaymentAppProvider::GetInstance()->InvokePaymentApp( 105 PaymentAppProvider::GetInstance()->InvokePaymentApp(
94 shell()->web_contents()->GetBrowserContext(), registration_id, 106 shell()->web_contents()->GetBrowserContext(), registration_id,
95 std::move(app_request)); 107 std::move(app_request),
108 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(),
109 &response));
110 run_loop.Run();
111
112 return response;
96 } 113 }
97 114
98 private: 115 private:
99 std::unique_ptr<net::EmbeddedTestServer> https_server_; 116 std::unique_ptr<net::EmbeddedTestServer> https_server_;
100 117
101 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); 118 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
102 }; 119 };
103 120
104 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) { 121 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
105 RegisterPaymentApp(); 122 RegisterPaymentApp();
106 123
107 std::vector<int64_t> ids = GetAllPaymentAppIDs(); 124 std::vector<int64_t> ids = GetAllPaymentAppIDs();
108 ASSERT_EQ(1U, ids.size()); 125 ASSERT_EQ(1U, ids.size());
109 126
110 InvokePaymentApp(ids[0]); 127 payments::mojom::PaymentAppResponsePtr response(InvokePaymentApp(ids[0]));
111 128 ASSERT_EQ("test", response->method_name);
112 ASSERT_EQ("payment_app_window_ready", PopConsoleString());
113 ASSERT_EQ("payment_app_response", PopConsoleString());
114 } 129 }
115 130
116 } // namespace content 131 } // namespace content
OLDNEW
« no previous file with comments | « components/payments/content/payment_app.mojom ('k') | content/browser/payments/payment_app_content_unittest_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698