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

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

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/payments/payment_app_content_unittest_base.h"
6
7 #include <set>
8 #include <utility>
9
10 #include "base/run_loop.h"
11 #include "content/browser/service_worker/embedded_worker_test_helper.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/browser/storage_partition_impl.h"
14 #include "content/public/test/test_browser_context.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
16
17 namespace content {
18
19 namespace {
20
21 void RegisterServiceWorkerCallback(bool* called,
22 ServiceWorkerStatusCode status,
23 const std::string& status_message,
24 int64_t registration_id) {
25 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
26 *called = true;
27 }
28
29 } // namespace
30
31 PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase()
32 : thread_bundle_(
33 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)),
34 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())),
35 storage_partition_impl_(
36 new StoragePartitionImpl(embedded_worker_helper_->browser_context(),
37 base::FilePath(), nullptr, nullptr, nullptr,
38 nullptr, nullptr, nullptr, nullptr, nullptr,
39 nullptr, nullptr, nullptr, nullptr, nullptr,
40 nullptr)) {
41 embedded_worker_helper_->context_wrapper()->set_storage_partition(
42 storage_partition_impl_.get());
43
44 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.
45 payment_app_context_->Init(embedded_worker_helper_->context_wrapper());
46 }
47
48 PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() {
49 payment_app_context_->Shutdown();
50 base::RunLoop().RunUntilIdle();
51 }
52
53 PaymentAppContextImpl* PaymentAppContentUnitTestBase::GetPaymentAppContext()
54 const {
55 return payment_app_context_.get();
56 }
57
58 PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager(
59 const GURL& scope_url,
60 const GURL& sw_script_url) {
61 // Register service worker for payment app manager.
62 bool called = false;
63 embedded_worker_helper_->context()->RegisterServiceWorker(
64 scope_url, sw_script_url, nullptr,
65 base::Bind(&RegisterServiceWorkerCallback, &called));
66 base::RunLoop().RunUntilIdle();
67 EXPECT_TRUE(called);
68
69 // This function should eventually return created payment app manager
70 // but there is no way to get last created payment app manager from
71 // payment_app_context_->services_ because its type is std::map and can not
72 // ensure its order. So, just make a set of existing payment app managers
73 // before creating a new manager and then check what is a new thing.
74 std::set<PaymentAppManager*> existing_managers;
75 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.
76 existing_managers.insert(manager.first);
77 }
78
79 // Create a new payment app manager.
80 payments::mojom::PaymentAppManagerPtr service;
81 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request =
82 mojo::GetProxy(&service);
83 services_.push_back(std::move(service));
84 payment_app_context_->CreateService(std::move(request));
85 base::RunLoop().RunUntilIdle();
86
87 // Find a last registered payment app manager.
88 for (auto& manager : payment_app_context_->services_) {
89 if (existing_managers.find(manager.first) != existing_managers.end())
90 return manager.first;
91 }
92
please use gerrit instead 2016/12/12 20:17:39 NOTREACHED(); return nullptr;
zino 2016/12/16 19:45:40 Done.
93 return payment_app_context_->services_.begin()->first;
94 }
95
96 void PaymentAppContentUnitTestBase::SetManifest(
97 PaymentAppManager* manager,
98 const std::string& scope,
99 payments::mojom::PaymentAppManifestPtr manifest,
100 const PaymentAppManager::SetManifestCallback& callback) {
101 ASSERT_TRUE(manager);
102 manager->SetManifest(scope, std::move(manifest), callback);
103 base::RunLoop().RunUntilIdle();
104 }
105
106 void PaymentAppContentUnitTestBase::GetManifest(
107 PaymentAppManager* manager,
108 const std::string& scope,
109 const PaymentAppManager::GetManifestCallback& callback) {
110 ASSERT_TRUE(manager);
111 manager->GetManifest(scope, callback);
112 base::RunLoop().RunUntilIdle();
113 }
114
115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698