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

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

Issue 2958753003: Revert "Create ServiceWorkerProviderHost before starting worker" (Closed)
Patch Set: Created 3 years, 5 months 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_content_unittest_base.h" 5 #include "content/browser/payments/payment_app_content_unittest_base.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 10 matching lines...) Expand all
21 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
23 #include "mojo/public/cpp/bindings/interface_request.h" 23 #include "mojo/public/cpp/bindings/interface_request.h"
24 #include "services/service_manager/public/cpp/bind_source_info.h" 24 #include "services/service_manager/public/cpp/bind_source_info.h"
25 25
26 namespace content { 26 namespace content {
27 27
28 namespace { 28 namespace {
29 29
30 void RegisterServiceWorkerCallback(bool* called, 30 void RegisterServiceWorkerCallback(bool* called,
31 int64_t* out_registration_id,
32 ServiceWorkerStatusCode status, 31 ServiceWorkerStatusCode status,
33 const std::string& status_message, 32 const std::string& status_message,
34 int64_t registration_id) { 33 int64_t registration_id) {
35 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); 34 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
36 *called = true; 35 *called = true;
37 *out_registration_id = registration_id;
38 } 36 }
39 37
40 void UnregisterServiceWorkerCallback(bool* called, 38 void UnregisterServiceWorkerCallback(bool* called,
41 ServiceWorkerStatusCode status) { 39 ServiceWorkerStatusCode status) {
42 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); 40 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
43 *called = true; 41 *called = true;
44 } 42 }
45 43
46 void StopWorkerCallback(bool* called, ServiceWorkerStatusCode status) {
47 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
48 *called = true;
49 }
50
51 } // namespace 44 } // namespace
52 45
53 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper 46 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper
54 : public EmbeddedWorkerTestHelper { 47 : public EmbeddedWorkerTestHelper {
55 public: 48 public:
56 PaymentAppForWorkerTestHelper() 49 PaymentAppForWorkerTestHelper()
57 : EmbeddedWorkerTestHelper(base::FilePath()), 50 : EmbeddedWorkerTestHelper(base::FilePath()),
58 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {} 51 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {}
59 ~PaymentAppForWorkerTestHelper() override {} 52 ~PaymentAppForWorkerTestHelper() override {}
60 53
61 void OnStartWorker( 54 void OnStartWorker(int embedded_worker_id,
62 int embedded_worker_id, 55 int64_t service_worker_version_id,
63 int64_t service_worker_version_id, 56 const GURL& scope,
64 const GURL& scope, 57 const GURL& script_url,
65 const GURL& script_url, 58 bool pause_after_download,
66 bool pause_after_download, 59 mojom::ServiceWorkerEventDispatcherRequest request,
67 mojom::ServiceWorkerEventDispatcherRequest request, 60 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo
68 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, 61 instance_host) override {
69 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
70 override {
71 ServiceWorkerVersion* version = 62 ServiceWorkerVersion* version =
72 context()->GetLiveVersion(service_worker_version_id); 63 context()->GetLiveVersion(service_worker_version_id);
73 last_sw_registration_id_ = version->registration_id(); 64 last_sw_registration_id_ = version->registration_id();
74 last_sw_scope_ = scope; 65 last_sw_scope_ = scope;
75 EmbeddedWorkerTestHelper::OnStartWorker( 66 EmbeddedWorkerTestHelper::OnStartWorker(
76 embedded_worker_id, service_worker_version_id, scope, script_url, 67 embedded_worker_id, service_worker_version_id, scope, script_url,
77 pause_after_download, std::move(request), std::move(instance_host), 68 pause_after_download, std::move(request), std::move(instance_host));
78 std::move(provider_info));
79 } 69 }
80 70
81 void OnPaymentRequestEvent( 71 void OnPaymentRequestEvent(
82 payments::mojom::PaymentRequestEventDataPtr event_data, 72 payments::mojom::PaymentRequestEventDataPtr event_data,
83 payments::mojom::PaymentAppResponseCallbackPtr response_callback, 73 payments::mojom::PaymentAppResponseCallbackPtr response_callback,
84 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback 74 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback
85 callback) override { 75 callback) override {
86 EmbeddedWorkerTestHelper::OnPaymentRequestEvent( 76 EmbeddedWorkerTestHelper::OnPaymentRequestEvent(
87 std::move(event_data), std::move(response_callback), 77 std::move(event_data), std::move(response_callback),
88 std::move(callback)); 78 std::move(callback));
(...skipping 25 matching lines...) Expand all
114 BrowserContext* PaymentAppContentUnitTestBase::browser_context() { 104 BrowserContext* PaymentAppContentUnitTestBase::browser_context() {
115 DCHECK(worker_helper_); 105 DCHECK(worker_helper_);
116 return worker_helper_->browser_context(); 106 return worker_helper_->browser_context();
117 } 107 }
118 108
119 PaymentManager* PaymentAppContentUnitTestBase::CreatePaymentManager( 109 PaymentManager* PaymentAppContentUnitTestBase::CreatePaymentManager(
120 const GURL& scope_url, 110 const GURL& scope_url,
121 const GURL& sw_script_url) { 111 const GURL& sw_script_url) {
122 // Register service worker for payment manager. 112 // Register service worker for payment manager.
123 bool called = false; 113 bool called = false;
124 int64_t registration_id;
125 worker_helper_->context()->RegisterServiceWorker( 114 worker_helper_->context()->RegisterServiceWorker(
126 scope_url, sw_script_url, nullptr, 115 scope_url, sw_script_url, nullptr,
127 base::Bind(&RegisterServiceWorkerCallback, &called, &registration_id)); 116 base::Bind(&RegisterServiceWorkerCallback, &called));
128 base::RunLoop().RunUntilIdle(); 117 base::RunLoop().RunUntilIdle();
129 EXPECT_TRUE(called); 118 EXPECT_TRUE(called);
130 119
131 // Ensure the worker used for installation has stopped.
132 called = false;
133 ServiceWorkerRegistration* registration =
134 worker_helper_->context()->GetLiveRegistration(registration_id);
135 EXPECT_TRUE(registration);
136 EXPECT_TRUE(registration->active_version());
137 EXPECT_FALSE(registration->waiting_version());
138 EXPECT_FALSE(registration->installing_version());
139 registration->active_version()->StopWorker(
140 base::Bind(&StopWorkerCallback, &called));
141 base::RunLoop().RunUntilIdle();
142 EXPECT_TRUE(called);
143
144 // This function should eventually return created payment manager 120 // This function should eventually return created payment manager
145 // but there is no way to get last created payment manager from 121 // but there is no way to get last created payment manager from
146 // payment_app_context()->payment_managers_ because its type is std::map 122 // payment_app_context()->payment_managers_ because its type is std::map
147 // and can not ensure its order. So, just make a set of existing payment app 123 // and can not ensure its order. So, just make a set of existing payment app
148 // managers before creating a new manager and then check what is a new thing. 124 // managers before creating a new manager and then check what is a new thing.
149 std::set<PaymentManager*> existing_managers; 125 std::set<PaymentManager*> existing_managers;
150 for (const auto& existing_manager : 126 for (const auto& existing_manager :
151 payment_app_context()->payment_managers_) { 127 payment_app_context()->payment_managers_) {
152 existing_managers.insert(existing_manager.first); 128 existing_managers.insert(existing_manager.first);
153 } 129 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { 172 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() {
197 return static_cast<StoragePartitionImpl*>( 173 return static_cast<StoragePartitionImpl*>(
198 BrowserContext::GetDefaultStoragePartition(browser_context())); 174 BrowserContext::GetDefaultStoragePartition(browser_context()));
199 } 175 }
200 176
201 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { 177 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() {
202 return storage_partition()->GetPaymentAppContext(); 178 return storage_partition()->GetPaymentAppContext();
203 } 179 }
204 180
205 } // namespace content 181 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698