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

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

Issue 2610163002: PaymentApp: Implement InvokePaymentApp() in browser side. (Closed)
Patch Set: fix bot error 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <cstddef> 5 #include <cstddef>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 public: 43 public:
44 PaymentAppProviderTest() {} 44 PaymentAppProviderTest() {}
45 ~PaymentAppProviderTest() override {} 45 ~PaymentAppProviderTest() override {}
46 46
47 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { 47 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) {
48 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), 48 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(),
49 callback); 49 callback);
50 base::RunLoop().RunUntilIdle(); 50 base::RunLoop().RunUntilIdle();
51 } 51 }
52 52
53 void InvokePaymentApp(int64_t registration_id,
54 payments::mojom::PaymentAppRequestDataPtr data) {
55 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp(
56 browser_context(), registration_id, std::move(data));
57 base::RunLoop().RunUntilIdle();
58 }
59
53 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { 60 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
54 PaymentAppManager* manager = 61 PaymentAppManager* manager =
55 CreatePaymentAppManager(scope_url, sw_script_url); 62 CreatePaymentAppManager(scope_url, sw_script_url);
56 63
57 PaymentAppManifestError error = 64 PaymentAppManifestError error =
58 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 65 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
59 bool called = false; 66 bool called = false;
60 SetManifest(manager, CreatePaymentAppManifestForTest(scope_url.spec()), 67 SetManifest(manager, CreatePaymentAppManifestForTest(scope_url.spec()),
61 base::Bind(&SetManifestCallback, &called, &error)); 68 base::Bind(&SetManifestCallback, &called, &error));
62 ASSERT_TRUE(called); 69 ASSERT_TRUE(called);
63 70
64 ASSERT_EQ(PaymentAppManifestError::NONE, error); 71 ASSERT_EQ(PaymentAppManifestError::NONE, error);
65 } 72 }
66 73
67 private: 74 private:
68 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest); 75 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest);
69 }; 76 };
70 77
71 TEST_F(PaymentAppProviderTest, Test) { 78 TEST_F(PaymentAppProviderTest, GetAllManifestsTest) {
72 static const struct { 79 static const struct {
73 const char* scopeUrl; 80 const char* scopeUrl;
74 const char* scriptUrl; 81 const char* scriptUrl;
75 } kPaymentAppInfo[] = { 82 } kPaymentAppInfo[] = {
76 {"https://example.com/a", "https://example.com/a/script.js"}, 83 {"https://example.com/a", "https://example.com/a/script.js"},
77 {"https://example.com/b", "https://example.com/b/script.js"}, 84 {"https://example.com/b", "https://example.com/b/script.js"},
78 {"https://example.com/c", "https://example.com/c/script.js"}}; 85 {"https://example.com/c", "https://example.com/c/script.js"}};
79 86
80 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { 87 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) {
81 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), 88 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl),
(...skipping 12 matching lines...) Expand all
94 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name); 101 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name);
95 ASSERT_EQ(1U, manifest.second->options.size()); 102 ASSERT_EQ(1U, manifest.second->options.size());
96 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value()); 103 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value());
97 EXPECT_EQ("Visa ****", manifest.second->options[0]->name); 104 EXPECT_EQ("Visa ****", manifest.second->options[0]->name);
98 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id); 105 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id);
99 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size()); 106 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size());
100 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]); 107 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]);
101 } 108 }
102 } 109 }
103 110
111 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) {
112 static const struct {
113 const char* scopeUrl;
114 const char* scriptUrl;
115 } kPaymentAppInfo[] = {
116 {"https://example.com/a", "https://example.com/a/script.js"},
117 {"https://example.com/b", "https://example.com/b/script.js"},
118 {"https://example.com/c", "https://example.com/c/script.js"}};
119
120 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) {
121 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl),
122 GURL(kPaymentAppInfo[i].scriptUrl));
123 }
124
125 PaymentAppProvider::Manifests manifests;
126 bool called = false;
127 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests));
128 ASSERT_TRUE(called);
129 ASSERT_EQ(3U, manifests.size());
130
131 payments::mojom::PaymentAppRequestDataPtr data =
132 payments::mojom::PaymentAppRequestData::New();
133 data->methodData.push_back(payments::mojom::PaymentMethodData::New());
134 data->total = payments::mojom::PaymentItem::New();
135 data->total->amount = payments::mojom::PaymentCurrencyAmount::New();
136
137 ResetPaymentAppInvoked();
please use gerrit instead 2017/01/16 16:46:15 nit: This call is not necessary now that your init
138 EXPECT_FALSE(payment_app_invoked());
139 InvokePaymentApp(manifests[1].first, std::move(data));
140
141 ASSERT_TRUE(payment_app_invoked());
142 EXPECT_EQ(manifests[1].first, last_sw_registration_id());
143 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url());
144 }
145
104 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_provider_impl.cc ('k') | content/browser/service_worker/embedded_worker_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698