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

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

Issue 2585303002: PaymentApp: Fix params order of EXPECT/ASSERTs in unit tests. (Closed)
Patch Set: PaymentApp: Fix params order of EXPECT/ASSERTs in unit tests. 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
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"
11 #include "components/payments/payment_app.mojom.h" 11 #include "components/payments/payment_app.mojom.h"
12 #include "content/browser/payments/payment_app_content_unittest_base.h" 12 #include "content/browser/payments/payment_app_content_unittest_base.h"
13 #include "content/browser/payments/payment_app_context_impl.h" 13 #include "content/browser/payments/payment_app_context_impl.h"
14 #include "content/public/browser/payment_app_context.h" 14 #include "content/public/browser/payment_app_context.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 using payments::mojom::PaymentAppManifestError;
19 using payments::mojom::PaymentAppManifestPtr;
20
18 namespace content { 21 namespace content {
19 22
20 class PaymentAppManager; 23 class PaymentAppManager;
21 24
22 namespace { 25 namespace {
23 26
24 void SetManifestCallback(bool* called, 27 void SetManifestCallback(bool* called,
25 payments::mojom::PaymentAppManifestError* out_error, 28 PaymentAppManifestError* out_error,
26 payments::mojom::PaymentAppManifestError error) { 29 PaymentAppManifestError error) {
27 *called = true; 30 *called = true;
28 *out_error = error; 31 *out_error = error;
29 } 32 }
30 33
31 void GetAllManifestsCallback(bool* called, 34 void GetAllManifestsCallback(bool* called,
32 PaymentAppContext::Manifests* out_manifests, 35 PaymentAppContext::Manifests* out_manifests,
33 PaymentAppContext::Manifests manifests) { 36 PaymentAppContext::Manifests manifests) {
34 *called = true; 37 *called = true;
35 *out_manifests = std::move(manifests); 38 *out_manifests = std::move(manifests);
36 } 39 }
37 40
38 } // namespace 41 } // namespace
39 42
40 class PaymentAppContextTest : public PaymentAppContentUnitTestBase { 43 class PaymentAppContextTest : public PaymentAppContentUnitTestBase {
41 public: 44 public:
42 PaymentAppContextTest() {} 45 PaymentAppContextTest() {}
43 ~PaymentAppContextTest() override {} 46 ~PaymentAppContextTest() override {}
44 47
45 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) { 48 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) {
46 payment_app_context()->GetAllManifests(callback); 49 payment_app_context()->GetAllManifests(callback);
47 base::RunLoop().RunUntilIdle(); 50 base::RunLoop().RunUntilIdle();
48 } 51 }
49 52
50 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { 53 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
51 PaymentAppManager* manager = 54 PaymentAppManager* manager =
52 CreatePaymentAppManager(scope_url, sw_script_url); 55 CreatePaymentAppManager(scope_url, sw_script_url);
53 56
54 payments::mojom::PaymentAppOptionPtr option = 57 PaymentAppManifestError error =
55 payments::mojom::PaymentAppOption::New();
56 option->name = "Visa ****";
57 option->id = "payment-app-id";
58 option->icon = std::string("payment-app-icon");
59 option->enabled_methods.push_back("visa");
60
61 payments::mojom::PaymentAppManifestPtr manifest =
62 payments::mojom::PaymentAppManifest::New();
63 manifest->icon = std::string("payment-app-icon");
64 manifest->name = scope_url.spec();
65 manifest->options.push_back(std::move(option));
66
67 payments::mojom::PaymentAppManifestError error = payments::mojom::
68 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 58 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
69 bool called = false; 59 bool called = false;
70 SetManifest(manager, scope_url.spec(), std::move(manifest), 60 SetManifest(manager, scope_url.spec(),
61 CreatePaymentAppManifestForTest(scope_url.spec()),
71 base::Bind(&SetManifestCallback, &called, &error)); 62 base::Bind(&SetManifestCallback, &called, &error));
72 ASSERT_TRUE(called); 63 ASSERT_TRUE(called);
73 64
74 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); 65 ASSERT_EQ(PaymentAppManifestError::NONE, error);
75 } 66 }
76 67
77 private: 68 private:
78 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest); 69 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest);
79 }; 70 };
80 71
81 TEST_F(PaymentAppContextTest, Test) { 72 TEST_F(PaymentAppContextTest, Test) {
82 static const struct { 73 static const struct {
83 const char* scopeUrl; 74 const char* scopeUrl;
84 const char* scriptUrl; 75 const char* scriptUrl;
85 } kPaymentAppInfo[] = { 76 } kPaymentAppInfo[] = {
86 {"https://example.com/a", "https://example.com/a/script.js"}, 77 {"https://example.com/a", "https://example.com/a/script.js"},
87 {"https://example.com/b", "https://example.com/b/script.js"}, 78 {"https://example.com/b", "https://example.com/b/script.js"},
88 {"https://example.com/c", "https://example.com/c/script.js"}}; 79 {"https://example.com/c", "https://example.com/c/script.js"}};
89 80
90 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { 81 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) {
91 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), 82 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl),
92 GURL(kPaymentAppInfo[i].scriptUrl)); 83 GURL(kPaymentAppInfo[i].scriptUrl));
93 } 84 }
94 85
95 PaymentAppContext::Manifests manifests; 86 PaymentAppContext::Manifests manifests;
96 bool called = false; 87 bool called = false;
97 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); 88 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests));
98 ASSERT_TRUE(called); 89 ASSERT_TRUE(called);
99 90
100 ASSERT_EQ(manifests.size(), 3U); 91 ASSERT_EQ(3U, manifests.size());
101 size_t i = 0; 92 size_t i = 0;
102 for (const auto& manifest : manifests) { 93 for (const auto& manifest : manifests) {
103 EXPECT_EQ(manifest.second->icon.value(), "payment-app-icon"); 94 EXPECT_EQ("payment-app-icon", manifest.second->icon.value());
104 EXPECT_EQ(manifest.second->name, kPaymentAppInfo[i++].scopeUrl); 95 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name);
105 ASSERT_EQ(manifest.second->options.size(), 1U); 96 ASSERT_EQ(1U, manifest.second->options.size());
106 EXPECT_EQ(manifest.second->options[0]->icon.value(), "payment-app-icon"); 97 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value());
107 EXPECT_EQ(manifest.second->options[0]->name, "Visa ****"); 98 EXPECT_EQ("Visa ****", manifest.second->options[0]->name);
108 EXPECT_EQ(manifest.second->options[0]->id, "payment-app-id"); 99 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id);
109 ASSERT_EQ(manifest.second->options[0]->enabled_methods.size(), 1U); 100 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size());
110 EXPECT_EQ(manifest.second->options[0]->enabled_methods[0], "visa"); 101 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]);
111 } 102 }
112 } 103 }
113 104
114 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698