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 |
index 38ffa37a5d8351e742736eb6ec8778d809d583bb..e14456a5ca623d233444fe13ae9bb1f82241eafb 100644 |
--- a/content/browser/payments/payment_app_content_unittest_base.cc |
+++ b/content/browser/payments/payment_app_content_unittest_base.cc |
@@ -15,6 +15,7 @@ |
#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/common/service_worker/service_worker_event_dispatcher.mojom.h" |
#include "content/common/service_worker/service_worker_status_code.h" |
#include "content/public/test/test_browser_context.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
@@ -41,21 +42,60 @@ void UnregisterServiceWorkerCallback(bool* called, |
} // namespace |
+struct PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper |
zino
2017/01/11 20:06:43
@rouslan,
Should this struct be located to below
please use gerrit instead
2017/01/12 19:04:00
It feels strange to derive a struct from a class.
please use gerrit instead
2017/01/12 19:04:00
Good question. Let's follow the rule of thumb that
zino
2017/01/13 16:41:10
Done.
zino
2017/01/16 15:01:09
I tried it but I couldn't because it is used in Pa
|
+ : public EmbeddedWorkerTestHelper { |
+ PaymentAppForWorkerTestHelper() |
+ : EmbeddedWorkerTestHelper(base::FilePath()) {} |
please use gerrit instead
2017/01/12 19:04:00
Need to initialize was_dispatched and last_sw_regi
please use gerrit instead
2017/01/12 19:04:00
Need to override the parent destructor.
zino
2017/01/13 16:41:10
Done.
|
+ |
+ void OnStartWorker(int embedded_worker_id, |
+ int64_t service_worker_version_id, |
+ const GURL& scope, |
+ const GURL& script_url, |
+ bool pause_after_download) override { |
+ ServiceWorkerVersion* version = |
+ context()->GetLiveVersion(service_worker_version_id); |
+ version->SetMainScriptHttpResponseInfo( |
+ EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); |
+ last_sw_registration_id = version->registration_id(); |
+ last_sw_scope = scope; |
+ EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, |
+ service_worker_version_id, scope, |
+ script_url, pause_after_download); |
+ } |
+ |
+ void OnPaymentRequestEvent( |
+ payments::mojom::PaymentAppRequestDataPtr data, |
+ const mojom::ServiceWorkerEventDispatcher:: |
+ DispatchPaymentRequestEventCallback& callback) override { |
+ ASSERT_FALSE(was_dispatched); |
+ EmbeddedWorkerTestHelper::OnPaymentRequestEvent(std::move(data), callback); |
+ was_dispatched = true; |
+ } |
+ |
+ bool was_dispatched; |
+ int64_t last_sw_registration_id; |
+ GURL last_sw_scope; |
please use gerrit instead
2017/01/12 19:04:00
private:
DISALLOW_COPY_AND_ASSIGN(PaymentAppForWor
zino
2017/01/13 16:41:10
Done.
|
+}; |
+ |
PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() |
: thread_bundle_( |
new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
- embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())) { |
- embedded_worker_helper_->context_wrapper()->set_storage_partition( |
- storage_partition()); |
- payment_app_context()->Init(embedded_worker_helper_->context_wrapper()); |
+ worker_helper_(new PaymentAppForWorkerTestHelper()) { |
+ worker_helper_->context_wrapper()->set_storage_partition(storage_partition()); |
+ storage_partition()->service_worker_context_->Shutdown(); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ storage_partition()->service_worker_context_ = |
+ worker_helper_->context_wrapper(); |
+ payment_app_context()->Init(worker_helper_->context_wrapper()); |
base::RunLoop().RunUntilIdle(); |
} |
PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() {} |
BrowserContext* PaymentAppContentUnitTestBase::browser_context() { |
- DCHECK(embedded_worker_helper_); |
- return embedded_worker_helper_->browser_context(); |
+ DCHECK(worker_helper_); |
+ return worker_helper_->browser_context(); |
} |
PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( |
@@ -63,7 +103,7 @@ PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( |
const GURL& sw_script_url) { |
// Register service worker for payment app manager. |
bool called = false; |
- embedded_worker_helper_->context()->RegisterServiceWorker( |
+ worker_helper_->context()->RegisterServiceWorker( |
scope_url, sw_script_url, nullptr, |
base::Bind(&RegisterServiceWorkerCallback, &called)); |
base::RunLoop().RunUntilIdle(); |
@@ -142,12 +182,28 @@ void PaymentAppContentUnitTestBase::UnregisterServiceWorker( |
const GURL& scope_url) { |
// Unregister service worker. |
bool called = false; |
- embedded_worker_helper_->context()->UnregisterServiceWorker( |
+ worker_helper_->context()->UnregisterServiceWorker( |
scope_url, base::Bind(&UnregisterServiceWorkerCallback, &called)); |
base::RunLoop().RunUntilIdle(); |
EXPECT_TRUE(called); |
} |
+void PaymentAppContentUnitTestBase::init_payment_app_invoked() const { |
+ worker_helper_->was_dispatched = false; |
please use gerrit instead
2017/01/12 19:04:00
Initialization should happen in the constructor of
zino
2017/01/13 16:41:10
Done.
|
+} |
+ |
+bool PaymentAppContentUnitTestBase::payment_app_invoked() const { |
+ return worker_helper_->was_dispatched; |
+} |
+ |
+int64_t PaymentAppContentUnitTestBase::last_sw_registration_id() const { |
+ return worker_helper_->last_sw_registration_id; |
+} |
+ |
+const GURL& PaymentAppContentUnitTestBase::last_sw_scope_url() const { |
+ return worker_helper_->last_sw_scope; |
+} |
+ |
StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { |
return static_cast<StoragePartitionImpl*>( |
BrowserContext::GetDefaultStoragePartition(browser_context())); |