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

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

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (Closed)
Patch Set: Created 4 years 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 2016 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 #include "base/run_loop.h"
6 #include "content/browser/payments/payment_app_content_unittest_base.h"
7
8 namespace content {
9 namespace {
10
11 void SetManifestCallback(payments::mojom::PaymentAppManifestError* out_error,
12 payments::mojom::PaymentAppManifestError error) {
13 *out_error = error;
14 }
15
16 void GetAllManifestsCallback(PaymentAppContext::Manifests* out_manifests,
17 PaymentAppContext::Manifests manifests) {
18 *out_manifests = std::move(manifests);
19 }
20
21 } // namespace
22
23 class PaymentAppContextTest : public PaymentAppContentUnitTestBase {
24 public:
25 PaymentAppContextTest() {}
please use gerrit instead 2016/12/12 20:17:39 Need a destructor as well.
zino 2016/12/16 19:45:41 Done.
26
27 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) {
28 GetPaymentAppContext()->GetAllManifests(callback);
29 base::RunLoop().RunUntilIdle();
30 }
31
32 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
33 PaymentAppManager* manager =
34 CreatePaymentAppManager(scope_url, sw_script_url);
35
36 payments::mojom::PaymentAppOptionPtr option =
37 payments::mojom::PaymentAppOption::New();
38 option->label = "Visa ****";
39 option->id = "payment-app-id";
40 option->icon = std::string("payment-app-icon");
41 option->enabled_methods.push_back("visa");
42
43 payments::mojom::PaymentAppManifestPtr manifest =
44 payments::mojom::PaymentAppManifest::New();
45 manifest->icon = std::string("payment-app-icon");
46 manifest->label = scope_url.spec();
47 manifest->options.push_back(std::move(option));
48
49 payments::mojom::PaymentAppManifestError error;
50 SetManifest(manager, scope_url.spec(), std::move(manifest),
51 base::Bind(&SetManifestCallback, &error));
52 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE);
53 }
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest);
57 };
58
59 TEST_F(PaymentAppContextTest, Test) {
60 const char* kPaymentAppInfo[][2] = {
61 {"https://example.com/a", "https://example.com/a/script.js"},
62 {"https://example.com/b", "https://example.com/b/script.js"},
63 {"https://example.com/c", "https://example.com/c/script.js"},
64 };
please use gerrit instead 2016/12/12 20:17:39 The standard way to create test data list is: sta
zino 2016/12/16 19:45:40 Done.
65
66 for (int i = 0; i < 3; i++) {
67 CreatePaymentApp(GURL(kPaymentAppInfo[i][0]), GURL(kPaymentAppInfo[i][1]));
68 }
69
70 PaymentAppContext::Manifests manifests;
71 GetAllManifests(base::Bind(&GetAllManifestsCallback, &manifests));
72
73 ASSERT_EQ(manifests.size(), 3U);
74 int i = 0;
75 for (auto& manifest : manifests) {
please use gerrit instead 2016/12/12 20:17:39 const auto&
zino 2016/12/16 19:45:41 Done.
76 EXPECT_EQ(manifest.second->icon, std::string("payment-app-icon"));
please use gerrit instead 2016/12/12 20:17:39 Is std::string() wrapper necessary? I see that you
zino 2016/12/16 19:45:40 The type is base::Optional<std::string>. https://c
77 EXPECT_EQ(manifest.second->label, kPaymentAppInfo[i++][0]);
78 ASSERT_EQ(manifest.second->options.size(), 1U);
79 EXPECT_EQ(manifest.second->options[0]->icon,
80 std::string("payment-app-icon"));
81 EXPECT_EQ(manifest.second->options[0]->label, "Visa ****");
82 EXPECT_EQ(manifest.second->options[0]->id, "payment-app-id");
83 ASSERT_EQ(manifest.second->options[0]->enabled_methods.size(), 1U);
84 EXPECT_EQ(manifest.second->options[0]->enabled_methods[0], "visa");
85 }
86 }
87
88 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698