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

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

Issue 2557473003: PaymentApp: Factor out functions to serialize/deserialize manifest data. (Closed)
Patch Set: test 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 "content/browser/payments/payment_app_manager.h" 5 #include "content/browser/payments/payment_app_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), 60 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())),
61 storage_partition_impl_(new StoragePartitionImpl( 61 storage_partition_impl_(new StoragePartitionImpl(
62 embedded_worker_helper_->browser_context(), base::FilePath(), 62 embedded_worker_helper_->browser_context(), base::FilePath(),
63 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 63 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
64 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) { 64 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) {
65 65
66 embedded_worker_helper_->context_wrapper()->set_storage_partition( 66 embedded_worker_helper_->context_wrapper()->set_storage_partition(
67 storage_partition_impl_.get()); 67 storage_partition_impl_.get());
68 68
69 payment_app_context_ = 69 payment_app_context_ =
70 new PaymentAppContext(embedded_worker_helper_->context_wrapper()); 70 new PaymentAppContextImpl(embedded_worker_helper_->context_wrapper());
71 71
72 bool called = false; 72 bool called = false;
73 embedded_worker_helper_->context()->RegisterServiceWorker( 73 embedded_worker_helper_->context()->RegisterServiceWorker(
74 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL, 74 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL,
75 base::Bind(&RegisterServiceWorkerCallback, &called, 75 base::Bind(&RegisterServiceWorkerCallback, &called,
76 &sw_registration_id_)); 76 &sw_registration_id_));
77 base::RunLoop().RunUntilIdle(); 77 base::RunLoop().RunUntilIdle();
78 EXPECT_TRUE(called); 78 EXPECT_TRUE(called);
79 79
80 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = 80 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request =
(...skipping 16 matching lines...) Expand all
97 manager_->SetManifest(scope, std::move(manifest), callback); 97 manager_->SetManifest(scope, std::move(manifest), callback);
98 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
99 } 99 }
100 100
101 void GetManifest(const std::string& scope, 101 void GetManifest(const std::string& scope,
102 const PaymentAppManager::GetManifestCallback& callback) { 102 const PaymentAppManager::GetManifestCallback& callback) {
103 manager_->GetManifest(scope, callback); 103 manager_->GetManifest(scope, callback);
104 base::RunLoop().RunUntilIdle(); 104 base::RunLoop().RunUntilIdle();
105 } 105 }
106 106
107 void GetAll() {
108 payment_app_context_->GetAllManifests(base::Bind(&DidGetAll));
109 base::RunLoop().RunUntilIdle();
110 }
111
112 static void DidGetAll(const std::vector<PaymentAppContext::PaymentAppManifestW ithID>& manifests) {
113 LOG(INFO) << "zino";
114 }
115
107 private: 116 private:
108 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; 117 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
109 std::unique_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_; 118 std::unique_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_;
110 std::unique_ptr<StoragePartitionImpl> storage_partition_impl_; 119 std::unique_ptr<StoragePartitionImpl> storage_partition_impl_;
111 int64_t sw_registration_id_; 120 int64_t sw_registration_id_;
112 scoped_refptr<PaymentAppContext> payment_app_context_; 121 scoped_refptr<PaymentAppContextImpl> payment_app_context_;
113 payments::mojom::PaymentAppManagerPtr service_; 122 payments::mojom::PaymentAppManagerPtr service_;
114 123
115 // Owned by payment_app_context_. 124 // Owned by payment_app_context_.
116 PaymentAppManager* manager_; 125 PaymentAppManager* manager_;
117 126
118 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); 127 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest);
119 }; 128 };
120 129
121 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { 130 TEST_F(PaymentAppManagerTest, SetAndGetManifest) {
122 payments::mojom::PaymentAppOptionPtr option = 131 payments::mojom::PaymentAppOptionPtr option =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { 166 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) {
158 payments::mojom::PaymentAppManifestPtr read_manifest; 167 payments::mojom::PaymentAppManifestPtr read_manifest;
159 payments::mojom::PaymentAppManifestError read_error; 168 payments::mojom::PaymentAppManifestError read_error;
160 GetManifest(kServiceWorkerPattern, 169 GetManifest(kServiceWorkerPattern,
161 base::Bind(&GetManifestCallback, &read_manifest, &read_error)); 170 base::Bind(&GetManifestCallback, &read_manifest, &read_error));
162 171
163 EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: 172 EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError::
164 MANIFEST_STORAGE_OPERATION_FAILED); 173 MANIFEST_STORAGE_OPERATION_FAILED);
165 } 174 }
166 175
176 TEST_F(PaymentAppManagerTest, Test) {
177 payments::mojom::PaymentAppOptionPtr option =
178 payments::mojom::PaymentAppOption::New();
179 option->label = "Visa ****";
180 option->id = "payment-app-id";
181 option->icon = std::string("payment-app-icon");
182 option->enabled_methods.push_back("visa");
183
184 payments::mojom::PaymentAppManifestPtr manifest =
185 payments::mojom::PaymentAppManifest::New();
186 manifest->icon = std::string("payment-app-icon");
187 manifest->label = "Payment App";
188 manifest->options.push_back(std::move(option));
189
190 payments::mojom::PaymentAppManifestError error;
191 SetManifest(kServiceWorkerPattern, std::move(manifest),
192 base::Bind(&SetManifestCallback, &error));
193
194 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE);
195
196 GetAll();
197 }
198
167 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_manager.cc ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698