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

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

Issue 2873903003: PaymentHandler: Stop using GetAllManifests() in content side tests. (Closed)
Patch Set: PaymentHandler: Use GetAllPaymentApps() in content side. Created 3 years, 7 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
« no previous file with comments | « no previous file | content/browser/payments/payment_app_provider_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mojom/payment_app.mojom.h" 8 #include "components/payments/mojom/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 GetAllPaymentAppsCallback(const base::Closure& done_callback,
23 PaymentAppProvider::Manifests* out_manifests, 23 PaymentAppProvider::PaymentApps* out_apps,
24 PaymentAppProvider::Manifests manifests) { 24 PaymentAppProvider::PaymentApps apps) {
25 *out_manifests = std::move(manifests); 25 *out_apps = std::move(apps);
26 done_callback.Run(); 26 done_callback.Run();
27 } 27 }
28 28
29 void InvokePaymentAppCallback( 29 void InvokePaymentAppCallback(
30 const base::Closure& done_callback, 30 const base::Closure& done_callback,
31 payments::mojom::PaymentAppResponsePtr* out_response, 31 payments::mojom::PaymentAppResponsePtr* out_response,
32 payments::mojom::PaymentAppResponsePtr response) { 32 payments::mojom::PaymentAppResponsePtr response) {
33 *out_response = std::move(response); 33 *out_response = std::move(response);
34 done_callback.Run(); 34 done_callback.Run();
35 } 35 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 void RegisterPaymentApp() { 71 void RegisterPaymentApp() {
72 std::string script_result; 72 std::string script_result;
73 ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result)); 73 ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result));
74 ASSERT_EQ("registered", script_result); 74 ASSERT_EQ("registered", script_result);
75 } 75 }
76 76
77 std::vector<int64_t> GetAllPaymentAppIDs() { 77 std::vector<int64_t> GetAllPaymentAppIDs() {
78 base::RunLoop run_loop; 78 base::RunLoop run_loop;
79 PaymentAppProvider::Manifests manifests; 79 PaymentAppProvider::PaymentApps apps;
80 PaymentAppProvider::GetInstance()->GetAllManifests( 80 PaymentAppProvider::GetInstance()->GetAllPaymentApps(
81 shell()->web_contents()->GetBrowserContext(), 81 shell()->web_contents()->GetBrowserContext(),
82 base::Bind(&GetAllManifestsCallback, run_loop.QuitClosure(), 82 base::BindOnce(&GetAllPaymentAppsCallback, run_loop.QuitClosure(),
83 &manifests)); 83 &apps));
84 run_loop.Run(); 84 run_loop.Run();
85 85
86 std::vector<int64_t> ids; 86 std::vector<int64_t> ids;
87 for (const auto& manifest : manifests) { 87 for (const auto& app_info : apps) {
88 ids.push_back(manifest.first); 88 for (const auto& instrument : app_info.second) {
89 ids.push_back(instrument->registration_id);
90 }
89 } 91 }
90 92
91 return ids; 93 return ids;
92 } 94 }
93 95
94 payments::mojom::PaymentAppResponsePtr InvokePaymentApp( 96 payments::mojom::PaymentAppResponsePtr InvokePaymentApp(
95 int64_t registration_id) { 97 int64_t registration_id) {
96 payments::mojom::PaymentAppRequestPtr app_request = 98 payments::mojom::PaymentAppRequestPtr app_request =
97 payments::mojom::PaymentAppRequest::New(); 99 payments::mojom::PaymentAppRequest::New();
98 app_request->method_data.push_back( 100 app_request->method_data.push_back(
(...skipping 23 matching lines...) Expand all
122 RegisterPaymentApp(); 124 RegisterPaymentApp();
123 125
124 std::vector<int64_t> ids = GetAllPaymentAppIDs(); 126 std::vector<int64_t> ids = GetAllPaymentAppIDs();
125 ASSERT_EQ(1U, ids.size()); 127 ASSERT_EQ(1U, ids.size());
126 128
127 payments::mojom::PaymentAppResponsePtr response(InvokePaymentApp(ids[0])); 129 payments::mojom::PaymentAppResponsePtr response(InvokePaymentApp(ids[0]));
128 ASSERT_EQ("test", response->method_name); 130 ASSERT_EQ("test", response->method_name);
129 } 131 }
130 132
131 } // namespace content 133 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/payments/payment_app_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698