Index: content/browser/payments/payment_app_content_unittest_base.cc |
diff --git a/content/browser/payments/payment_app_content_unittest_base.cc b/content/browser/payments/payment_app_content_unittest_base.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..47901d7dc4581c7aa8eb379379222def36bb08be |
--- /dev/null |
+++ b/content/browser/payments/payment_app_content_unittest_base.cc |
@@ -0,0 +1,115 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/payments/payment_app_content_unittest_base.h" |
+ |
+#include <set> |
+#include <utility> |
+ |
+#include "base/run_loop.h" |
+#include "content/browser/service_worker/embedded_worker_test_helper.h" |
+#include "content/browser/service_worker/service_worker_context_wrapper.h" |
+#include "content/browser/storage_partition_impl.h" |
+#include "content/public/test/test_browser_context.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+void RegisterServiceWorkerCallback(bool* called, |
+ ServiceWorkerStatusCode status, |
+ const std::string& status_message, |
+ int64_t registration_id) { |
+ EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
+ *called = true; |
+} |
+ |
+} // namespace |
+ |
+PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() |
+ : thread_bundle_( |
+ new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
+ embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), |
+ storage_partition_impl_( |
+ new StoragePartitionImpl(embedded_worker_helper_->browser_context(), |
+ base::FilePath(), nullptr, nullptr, nullptr, |
+ nullptr, nullptr, nullptr, nullptr, nullptr, |
+ nullptr, nullptr, nullptr, nullptr, nullptr, |
+ nullptr)) { |
+ embedded_worker_helper_->context_wrapper()->set_storage_partition( |
+ storage_partition_impl_.get()); |
+ |
+ payment_app_context_ = new PaymentAppContextImpl(); |
please use gerrit instead
2016/12/12 20:17:39
Can you initialize payment_app_context_ in the mem
zino
2016/12/16 19:45:40
Done.
|
+ payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); |
+} |
+ |
+PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() { |
+ payment_app_context_->Shutdown(); |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
+PaymentAppContextImpl* PaymentAppContentUnitTestBase::GetPaymentAppContext() |
+ const { |
+ return payment_app_context_.get(); |
+} |
+ |
+PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( |
+ const GURL& scope_url, |
+ const GURL& sw_script_url) { |
+ // Register service worker for payment app manager. |
+ bool called = false; |
+ embedded_worker_helper_->context()->RegisterServiceWorker( |
+ scope_url, sw_script_url, nullptr, |
+ base::Bind(&RegisterServiceWorkerCallback, &called)); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_TRUE(called); |
+ |
+ // This function should eventually return created payment app manager |
+ // but there is no way to get last created payment app manager from |
+ // payment_app_context_->services_ because its type is std::map and can not |
+ // ensure its order. So, just make a set of existing payment app managers |
+ // before creating a new manager and then check what is a new thing. |
+ std::set<PaymentAppManager*> existing_managers; |
+ for (auto& manager : payment_app_context_->services_) { |
please use gerrit instead
2016/12/12 20:17:39
const auto&
zino
2016/12/16 19:45:40
Done.
|
+ existing_managers.insert(manager.first); |
+ } |
+ |
+ // Create a new payment app manager. |
+ payments::mojom::PaymentAppManagerPtr service; |
+ mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = |
+ mojo::GetProxy(&service); |
+ services_.push_back(std::move(service)); |
+ payment_app_context_->CreateService(std::move(request)); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // Find a last registered payment app manager. |
+ for (auto& manager : payment_app_context_->services_) { |
+ if (existing_managers.find(manager.first) != existing_managers.end()) |
+ return manager.first; |
+ } |
+ |
please use gerrit instead
2016/12/12 20:17:39
NOTREACHED();
return nullptr;
zino
2016/12/16 19:45:40
Done.
|
+ return payment_app_context_->services_.begin()->first; |
+} |
+ |
+void PaymentAppContentUnitTestBase::SetManifest( |
+ PaymentAppManager* manager, |
+ const std::string& scope, |
+ payments::mojom::PaymentAppManifestPtr manifest, |
+ const PaymentAppManager::SetManifestCallback& callback) { |
+ ASSERT_TRUE(manager); |
+ manager->SetManifest(scope, std::move(manifest), callback); |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
+void PaymentAppContentUnitTestBase::GetManifest( |
+ PaymentAppManager* manager, |
+ const std::string& scope, |
+ const PaymentAppManager::GetManifestCallback& callback) { |
+ ASSERT_TRUE(manager); |
+ manager->GetManifest(scope, callback); |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
+} // namespace content |