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

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(bool* called,
12 payments::mojom::PaymentAppManifestError* out_error,
please use gerrit instead 2016/12/16 21:41:21 #include "components/payments/payment_app.mojom.h"
zino 2016/12/17 17:11:54 Done.
13 payments::mojom::PaymentAppManifestError error) {
14 *called = true;
15 *out_error = error;
16 }
17
18 void GetAllManifestsCallback(bool* called,
19 PaymentAppContext::Manifests* out_manifests,
please use gerrit instead 2016/12/16 21:41:21 #include "content/public/browser/payment_app_conte
zino 2016/12/17 17:11:54 Done.
20 PaymentAppContext::Manifests manifests) {
21 *called = true;
22 *out_manifests = std::move(manifests);
please use gerrit instead 2016/12/16 21:41:21 #include <utility>
zino 2016/12/17 17:11:54 Done.
23 }
24
25 } // namespace
26
27 class PaymentAppContextTest : public PaymentAppContentUnitTestBase {
28 public:
29 PaymentAppContextTest() {}
30 ~PaymentAppContextTest() override {}
31
32 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) {
33 GetPaymentAppContext()->GetAllManifests(callback);
34 base::RunLoop().RunUntilIdle();
35 }
36
37 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
please use gerrit instead 2016/12/16 21:41:21 #include "url/gurl.h"
zino 2016/12/17 17:11:54 Done.
38 PaymentAppManager* manager =
please use gerrit instead 2016/12/16 21:41:21 class PaymentAppManager; (forward declare on top
zino 2016/12/17 17:11:54 Done.
39 CreatePaymentAppManager(scope_url, sw_script_url);
40
41 payments::mojom::PaymentAppOptionPtr option =
42 payments::mojom::PaymentAppOption::New();
43 option->label = "Visa ****";
44 option->id = "payment-app-id";
45 option->icon = std::string("payment-app-icon");
please use gerrit instead 2016/12/16 21:41:21 I doubt you need to do std::string(), but if you d
zino 2016/12/17 17:11:54 There is no way to set const char*. The option->ic
46 option->enabled_methods.push_back("visa");
47
48 payments::mojom::PaymentAppManifestPtr manifest =
49 payments::mojom::PaymentAppManifest::New();
50 manifest->icon = std::string("payment-app-icon");
51 manifest->label = scope_url.spec();
52 manifest->options.push_back(std::move(option));
53
54 payments::mojom::PaymentAppManifestError error = payments::mojom::
55 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
56 bool called = false;
57 SetManifest(manager, scope_url.spec(), std::move(manifest),
58 base::Bind(&SetManifestCallback, &called, &error));
59 ASSERT_TRUE(called);
60
61 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE);
62 }
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest);
please use gerrit instead 2016/12/16 21:41:21 #include "base/macros.h"
zino 2016/12/17 17:11:54 Done.
66 };
67
68 TEST_F(PaymentAppContextTest, Test) {
please use gerrit instead 2016/12/16 21:41:21 #include "testing/gtest/include/gtest/gtest.h"
zino 2016/12/17 17:11:54 Done.
69 static const struct {
70 const char* scopeUrl;
71 const char* scriptUrl;
72 } kPaymentAppInfo[] = {
73 {"https://example.com/a", "https://example.com/a/script.js"},
74 {"https://example.com/b", "https://example.com/b/script.js"},
75 {"https://example.com/c", "https://example.com/c/script.js"}};
76
77 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++)
please use gerrit instead 2016/12/16 21:41:21 #include <cstddef>
please use gerrit instead 2016/12/16 21:41:22 Need {} for the for-loop.
zino 2016/12/17 17:11:54 Done.
zino 2016/12/17 17:11:54 Done.
78 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl),
79 GURL(kPaymentAppInfo[i].scriptUrl));
80
81 PaymentAppContext::Manifests manifests;
82 bool called = false;
83 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests));
84 ASSERT_TRUE(called);
85
86 ASSERT_EQ(manifests.size(), 3U);
87 size_t i = 0;
88 for (const auto& manifest : manifests) {
89 EXPECT_EQ(manifest.second->icon, std::string("payment-app-icon"));
90 EXPECT_EQ(manifest.second->label, kPaymentAppInfo[i++].scopeUrl);
91 ASSERT_EQ(manifest.second->options.size(), 1U);
92 EXPECT_EQ(manifest.second->options[0]->icon,
93 std::string("payment-app-icon"));
94 EXPECT_EQ(manifest.second->options[0]->label, "Visa ****");
95 EXPECT_EQ(manifest.second->options[0]->id, "payment-app-id");
96 ASSERT_EQ(manifest.second->options[0]->enabled_methods.size(), 1U);
97 EXPECT_EQ(manifest.second->options[0]->enabled_methods[0], "visa");
98 }
99 }
100
101 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698