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

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

Issue 2586203003: PaymentApp: Remove scope_url parameter from Get/SetManifest methods. (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
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 namespace content { 13 namespace content {
14 namespace { 14 namespace {
15 15
16 const char kServiceWorkerPattern[] = "https://example.com/a"; 16 const char kServiceWorkerPattern[] = "https://example.com/a";
17 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; 17 const char kServiceWorkerScript[] = "https://example.com/a/script.js";
18 const char kUnregisteredServiceWorkerPattern[] =
19 "https://example.com/unregistered";
20 18
21 void SetManifestCallback(bool* called, 19 void SetManifestCallback(bool* called,
22 payments::mojom::PaymentAppManifestError* out_error, 20 payments::mojom::PaymentAppManifestError* out_error,
23 payments::mojom::PaymentAppManifestError error) { 21 payments::mojom::PaymentAppManifestError error) {
24 *called = true; 22 *called = true;
25 *out_error = error; 23 *out_error = error;
26 } 24 }
27 25
28 void GetManifestCallback(bool* called, 26 void GetManifestCallback(bool* called,
29 payments::mojom::PaymentAppManifestPtr* out_manifest, 27 payments::mojom::PaymentAppManifestPtr* out_manifest,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Owned by payment_app_context_. 66 // Owned by payment_app_context_.
69 PaymentAppManager* manager_; 67 PaymentAppManager* manager_;
70 68
71 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); 69 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest);
72 }; 70 };
73 71
74 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { 72 TEST_F(PaymentAppManagerTest, SetAndGetManifest) {
75 bool called = false; 73 bool called = false;
76 payments::mojom::PaymentAppManifestError error = payments::mojom:: 74 payments::mojom::PaymentAppManifestError error = payments::mojom::
77 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 75 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
78 SetManifest(payment_app_manager(), kServiceWorkerPattern, 76 SetManifest(payment_app_manager(), CreatePaymentAppManifestForTest(),
79 CreatePaymentAppManifestForTest(),
80 base::Bind(&SetManifestCallback, &called, &error)); 77 base::Bind(&SetManifestCallback, &called, &error));
81 ASSERT_TRUE(called); 78 ASSERT_TRUE(called);
82 79
83 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, error); 80 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, error);
84 81
85 called = false; 82 called = false;
86 payments::mojom::PaymentAppManifestPtr read_manifest; 83 payments::mojom::PaymentAppManifestPtr read_manifest;
87 payments::mojom::PaymentAppManifestError read_error = payments::mojom:: 84 payments::mojom::PaymentAppManifestError read_error = payments::mojom::
88 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; 85 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
89 GetManifest( 86 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
90 payment_app_manager(), kServiceWorkerPattern, 87 &read_manifest, &read_error));
91 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error));
92 ASSERT_TRUE(called); 88 ASSERT_TRUE(called);
93 89
94 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); 90 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error);
95 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); 91 EXPECT_EQ("payment-app-icon", read_manifest->icon.value());
96 EXPECT_EQ("Payment App", read_manifest->name); 92 EXPECT_EQ("Payment App", read_manifest->name);
97 ASSERT_EQ(1U, read_manifest->options.size()); 93 ASSERT_EQ(1U, read_manifest->options.size());
98 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); 94 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value());
99 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); 95 EXPECT_EQ("Visa ****", read_manifest->options[0]->name);
100 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); 96 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id);
101 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); 97 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size());
102 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); 98 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]);
103 } 99 }
104 100
105 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { 101 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) {
106 bool called = false; 102 bool called = false;
107 payments::mojom::PaymentAppManifestError error = 103 payments::mojom::PaymentAppManifestError error =
108 payments::mojom::PaymentAppManifestError::NONE; 104 payments::mojom::PaymentAppManifestError::NONE;
109 SetManifest(payment_app_manager(), kUnregisteredServiceWorkerPattern, 105 UnregisterServiceWorker(GURL(kServiceWorkerPattern));
110 CreatePaymentAppManifestForTest(), 106 SetManifest(payment_app_manager(), CreatePaymentAppManifestForTest(),
111 base::Bind(&SetManifestCallback, &called, &error)); 107 base::Bind(&SetManifestCallback, &called, &error));
112 ASSERT_TRUE(called); 108 ASSERT_TRUE(called);
113 109
114 EXPECT_EQ(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER, error); 110 EXPECT_EQ(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER, error);
115 } 111 }
116 112
117 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { 113 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) {
118 bool called = false; 114 bool called = false;
119 payments::mojom::PaymentAppManifestPtr read_manifest; 115 payments::mojom::PaymentAppManifestPtr read_manifest;
120 payments::mojom::PaymentAppManifestError read_error = 116 payments::mojom::PaymentAppManifestError read_error =
121 payments::mojom::PaymentAppManifestError::NONE; 117 payments::mojom::PaymentAppManifestError::NONE;
122 GetManifest( 118 UnregisterServiceWorker(GURL(kServiceWorkerPattern));
123 payment_app_manager(), kUnregisteredServiceWorkerPattern, 119 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
124 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); 120 &read_manifest, &read_error));
125 ASSERT_TRUE(called); 121 ASSERT_TRUE(called);
126 122
127 EXPECT_EQ(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER, 123 EXPECT_EQ(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER,
128 read_error); 124 read_error);
129 } 125 }
130 126
131 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { 127 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) {
132 bool called = false; 128 bool called = false;
133 payments::mojom::PaymentAppManifestPtr read_manifest; 129 payments::mojom::PaymentAppManifestPtr read_manifest;
134 payments::mojom::PaymentAppManifestError read_error = 130 payments::mojom::PaymentAppManifestError read_error =
135 payments::mojom::PaymentAppManifestError::NONE; 131 payments::mojom::PaymentAppManifestError::NONE;
136 GetManifest( 132 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
137 payment_app_manager(), kServiceWorkerPattern, 133 &read_manifest, &read_error));
138 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error));
139 ASSERT_TRUE(called); 134 ASSERT_TRUE(called);
140 135
141 EXPECT_EQ(payments::mojom::PaymentAppManifestError:: 136 EXPECT_EQ(payments::mojom::PaymentAppManifestError::
142 MANIFEST_STORAGE_OPERATION_FAILED, 137 MANIFEST_STORAGE_OPERATION_FAILED,
143 read_error); 138 read_error);
144 } 139 }
145 140
146 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698