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

Side by Side Diff: content/browser/payments/payment_app_manager_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
« no previous file with comments | « content/browser/payments/payment_app_context_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 5 #include <utility>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "components/payments/payment_app.mojom.h" 8 #include "components/payments/payment_app.mojom.h"
9 #include "content/browser/payments/payment_app_content_unittest_base.h" 9 #include "content/browser/payments/payment_app_content_unittest_base.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 using payments::mojom::PaymentAppManifestError;
14 using payments::mojom::PaymentAppManifestPtr;
15
13 namespace content { 16 namespace content {
14 namespace { 17 namespace {
15 18
16 const char kServiceWorkerPattern[] = "https://example.com/a"; 19 const char kServiceWorkerPattern[] = "https://example.com/a";
17 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; 20 const char kServiceWorkerScript[] = "https://example.com/a/script.js";
18 const char kUnregisteredServiceWorkerPattern[] = 21 const char kUnregisteredServiceWorkerPattern[] =
19 "https://example.com/unregistered"; 22 "https://example.com/unregistered";
20 23
21 void SetManifestCallback(bool* called, 24 void SetManifestCallback(bool* called,
22 payments::mojom::PaymentAppManifestError* out_error, 25 PaymentAppManifestError* out_error,
23 payments::mojom::PaymentAppManifestError error) { 26 PaymentAppManifestError error) {
24 *called = true; 27 *called = true;
25 *out_error = error; 28 *out_error = error;
26 } 29 }
27 30
28 void GetManifestCallback(bool* called, 31 void GetManifestCallback(bool* called,
29 payments::mojom::PaymentAppManifestPtr* out_manifest, 32 PaymentAppManifestPtr* out_manifest,
30 payments::mojom::PaymentAppManifestError* out_error, 33 PaymentAppManifestError* out_error,
31 payments::mojom::PaymentAppManifestPtr manifest, 34 PaymentAppManifestPtr manifest,
32 payments::mojom::PaymentAppManifestError error) { 35 PaymentAppManifestError error) {
33 *called = true; 36 *called = true;
34 *out_manifest = std::move(manifest); 37 *out_manifest = std::move(manifest);
35 *out_error = error; 38 *out_error = error;
36 } 39 }
37 40
38 payments::mojom::PaymentAppManifestPtr CreatePaymentAppManifestForTest() {
39 payments::mojom::PaymentAppOptionPtr option =
40 payments::mojom::PaymentAppOption::New();
41 option->name = "Visa ****";
42 option->id = "payment-app-id";
43 option->icon = std::string("payment-app-icon");
44 option->enabled_methods.push_back("visa");
45
46 payments::mojom::PaymentAppManifestPtr manifest =
47 payments::mojom::PaymentAppManifest::New();
48 manifest->icon = std::string("payment-app-icon");
49 manifest->name = "Payment App";
50 manifest->options.push_back(std::move(option));
51
52 return manifest;
53 }
54
55 } // namespace 41 } // namespace
56 42
57 class PaymentAppManagerTest : public PaymentAppContentUnitTestBase { 43 class PaymentAppManagerTest : public PaymentAppContentUnitTestBase {
58 public: 44 public:
59 PaymentAppManagerTest() { 45 PaymentAppManagerTest() {
60 manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern), 46 manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern),
61 GURL(kServiceWorkerScript)); 47 GURL(kServiceWorkerScript));
62 EXPECT_NE(manager_, nullptr); 48 EXPECT_NE(nullptr, manager_);
63 } 49 }
64 50
65 PaymentAppManager* payment_app_manager() const { return manager_; } 51 PaymentAppManager* payment_app_manager() const { return manager_; }
66 52
67 private: 53 private:
68 // Owned by payment_app_context_. 54 // Owned by payment_app_context_.
69 PaymentAppManager* manager_; 55 PaymentAppManager* manager_;
70 56
71 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); 57 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest);
72 }; 58 };
73 59
74 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { 60 TEST_F(PaymentAppManagerTest, SetAndGetManifest) {
75 bool called = false; 61 bool called = false;
76 payments::mojom::PaymentAppManifestError error = payments::mojom:: 62 PaymentAppManifestError error =
77 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 63 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
78 SetManifest(payment_app_manager(), kServiceWorkerPattern, 64 SetManifest(payment_app_manager(), kServiceWorkerPattern,
79 CreatePaymentAppManifestForTest(), 65 CreatePaymentAppManifestForTest(kServiceWorkerPattern),
80 base::Bind(&SetManifestCallback, &called, &error)); 66 base::Bind(&SetManifestCallback, &called, &error));
81 ASSERT_TRUE(called); 67 ASSERT_TRUE(called);
82 68
83 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); 69 ASSERT_EQ(PaymentAppManifestError::NONE, error);
84 70
85 called = false; 71 called = false;
86 payments::mojom::PaymentAppManifestPtr read_manifest; 72 PaymentAppManifestPtr read_manifest;
87 payments::mojom::PaymentAppManifestError read_error = payments::mojom:: 73 PaymentAppManifestError read_error =
88 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 74 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
89 GetManifest( 75 GetManifest(
90 payment_app_manager(), kServiceWorkerPattern, 76 payment_app_manager(), kServiceWorkerPattern,
91 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); 77 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error));
92 ASSERT_TRUE(called); 78 ASSERT_TRUE(called);
93 79
94 ASSERT_EQ(read_error, payments::mojom::PaymentAppManifestError::NONE); 80 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error);
95 EXPECT_EQ(read_manifest->icon.value(), "payment-app-icon"); 81 EXPECT_EQ("payment-app-icon", read_manifest->icon.value());
96 EXPECT_EQ(read_manifest->name, "Payment App"); 82 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name);
97 ASSERT_EQ(read_manifest->options.size(), 1U); 83 ASSERT_EQ(1U, read_manifest->options.size());
98 EXPECT_EQ(read_manifest->options[0]->icon.value(), "payment-app-icon"); 84 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value());
99 EXPECT_EQ(read_manifest->options[0]->name, "Visa ****"); 85 EXPECT_EQ("Visa ****", read_manifest->options[0]->name);
100 EXPECT_EQ(read_manifest->options[0]->id, "payment-app-id"); 86 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id);
101 ASSERT_EQ(read_manifest->options[0]->enabled_methods.size(), 1U); 87 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size());
102 EXPECT_EQ(read_manifest->options[0]->enabled_methods[0], "visa"); 88 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]);
103 } 89 }
104 90
105 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { 91 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) {
106 bool called = false; 92 bool called = false;
107 payments::mojom::PaymentAppManifestError error = 93 PaymentAppManifestError error = PaymentAppManifestError::NONE;
108 payments::mojom::PaymentAppManifestError::NONE;
109 SetManifest(payment_app_manager(), kUnregisteredServiceWorkerPattern, 94 SetManifest(payment_app_manager(), kUnregisteredServiceWorkerPattern,
110 CreatePaymentAppManifestForTest(), 95 CreatePaymentAppManifestForTest(kServiceWorkerPattern),
111 base::Bind(&SetManifestCallback, &called, &error)); 96 base::Bind(&SetManifestCallback, &called, &error));
112 ASSERT_TRUE(called); 97 ASSERT_TRUE(called);
113 98
114 EXPECT_EQ(error, payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); 99 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error);
115 } 100 }
116 101
117 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { 102 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) {
118 bool called = false; 103 bool called = false;
119 payments::mojom::PaymentAppManifestPtr read_manifest; 104 PaymentAppManifestPtr read_manifest;
120 payments::mojom::PaymentAppManifestError read_error = 105 PaymentAppManifestError read_error = PaymentAppManifestError::NONE;
121 payments::mojom::PaymentAppManifestError::NONE;
122 GetManifest( 106 GetManifest(
123 payment_app_manager(), kUnregisteredServiceWorkerPattern, 107 payment_app_manager(), kUnregisteredServiceWorkerPattern,
124 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); 108 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error));
125 ASSERT_TRUE(called); 109 ASSERT_TRUE(called);
126 110
127 EXPECT_EQ(read_error, 111 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error);
128 payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER);
129 } 112 }
130 113
131 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { 114 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) {
132 bool called = false; 115 bool called = false;
133 payments::mojom::PaymentAppManifestPtr read_manifest; 116 PaymentAppManifestPtr read_manifest;
134 payments::mojom::PaymentAppManifestError read_error = 117 PaymentAppManifestError read_error = PaymentAppManifestError::NONE;
135 payments::mojom::PaymentAppManifestError::NONE;
136 GetManifest( 118 GetManifest(
137 payment_app_manager(), kServiceWorkerPattern, 119 payment_app_manager(), kServiceWorkerPattern,
138 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); 120 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error));
139 ASSERT_TRUE(called); 121 ASSERT_TRUE(called);
140 122
141 EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: 123 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED,
142 MANIFEST_STORAGE_OPERATION_FAILED); 124 read_error);
143 } 125 }
144 126
145 } // namespace content 127 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_context_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698