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

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

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

Powered by Google App Engine
This is Rietveld 408576698