Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
please use gerrit instead
2016/12/16 21:41:21
You don't use ServiceWorkerContextWrapper anywhere
zino
2016/12/17 17:11:54
Used it here:
embedded_worker_helper_->context_wra
please use gerrit instead
2016/12/19 14:48:05
Acknowledged.
| |
| 13 #include "content/browser/storage_partition_impl.h" | |
| 14 #include "content/public/test/test_browser_context.h" | |
|
please use gerrit instead
2016/12/16 21:41:21
You don't use TestBrowserContext anywhere here/.
zino
2016/12/17 17:11:54
Used it here:
new StoragePartitionImpl(embedded_wo
please use gerrit instead
2016/12/19 14:48:05
Calling browser_context() without dereferencing th
| |
| 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, | |
|
please use gerrit instead
2016/12/16 21:41:21
#include "content/common/service_worker/service_wo
zino
2016/12/17 17:11:53
Done.
| |
| 23 const std::string& status_message, | |
| 24 int64_t registration_id) { | |
|
please use gerrit instead
2016/12/16 21:41:21
#include <stdint.h>
zino
2016/12/17 17:11:53
Done.
| |
| 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())), | |
|
please use gerrit instead
2016/12/16 21:41:20
#include "base/files/file_path.h"
zino
2016/12/17 17:11:54
Done.
| |
| 35 storage_partition_impl_( | |
| 36 new StoragePartitionImpl(embedded_worker_helper_->browser_context(), | |
| 37 base::FilePath(), | |
| 38 nullptr)), | |
| 39 payment_app_context_(new PaymentAppContextImpl()) { | |
| 40 embedded_worker_helper_->context_wrapper()->set_storage_partition( | |
| 41 storage_partition_impl_.get()); | |
| 42 payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); | |
|
please use gerrit instead
2016/12/16 21:41:21
You should RunUntilIdle here, because Init() posts
zino
2016/12/17 17:11:53
Done.
| |
| 43 } | |
| 44 | |
| 45 PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() { | |
| 46 payment_app_context_->Shutdown(); | |
| 47 base::RunLoop().RunUntilIdle(); | |
| 48 } | |
| 49 | |
| 50 PaymentAppContextImpl* PaymentAppContentUnitTestBase::GetPaymentAppContext() | |
| 51 const { | |
| 52 return payment_app_context_.get(); | |
| 53 } | |
| 54 | |
| 55 PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( | |
| 56 const GURL& scope_url, | |
| 57 const GURL& sw_script_url) { | |
| 58 // Register service worker for payment app manager. | |
| 59 bool called = false; | |
| 60 embedded_worker_helper_->context()->RegisterServiceWorker( | |
| 61 scope_url, sw_script_url, nullptr, | |
| 62 base::Bind(&RegisterServiceWorkerCallback, &called)); | |
| 63 base::RunLoop().RunUntilIdle(); | |
| 64 EXPECT_TRUE(called); | |
| 65 | |
| 66 // This function should eventually return created payment app manager | |
| 67 // but there is no way to get last created payment app manager from | |
| 68 // payment_app_context_->payment_app_managers_ because its type is std::map | |
| 69 // and can not ensure its order. So, just make a set of existing payment app | |
| 70 // managers before creating a new manager and then check what is a new thing. | |
| 71 std::set<PaymentAppManager*> existing_managers; | |
| 72 for (const auto& manager : payment_app_context_->payment_app_managers_) { | |
| 73 existing_managers.insert(manager.first); | |
| 74 } | |
| 75 | |
| 76 // Create a new payment app manager. | |
| 77 payments::mojom::PaymentAppManagerPtr manager; | |
|
please use gerrit instead
2016/12/16 21:41:21
You're using the name "manager" for both for-loop
zino
2016/12/17 17:11:53
Done.
| |
| 78 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = | |
|
please use gerrit instead
2016/12/16 21:41:21
#include "mojo/public/cpp/bindings/interface_reque
zino
2016/12/17 17:11:53
Done.
| |
| 79 mojo::GetProxy(&manager); | |
|
please use gerrit instead
2016/12/16 21:41:20
#include "mojo/public/cpp/bindings/associated_inte
zino
2016/12/17 17:11:54
Done.
| |
| 80 payment_app_managers_.push_back(std::move(manager)); | |
| 81 payment_app_context_->CreatePaymentAppManager(std::move(request)); | |
| 82 base::RunLoop().RunUntilIdle(); | |
| 83 | |
| 84 // Find a last registered payment app manager. | |
| 85 for (const auto& manager : payment_app_context_->payment_app_managers_) { | |
| 86 if (existing_managers.size() == 0 || | |
| 87 existing_managers.find(manager.first) != existing_managers.end()) | |
|
please use gerrit instead
2016/12/16 21:41:20
Your comment and your code disagrees. Use this to
zino
2016/12/17 17:11:53
You're right..
I used base::ContainsKey() instead.
| |
| 88 return manager.first; | |
| 89 } | |
| 90 | |
| 91 NOTREACHED(); | |
| 92 return nullptr; | |
| 93 } | |
| 94 | |
| 95 void PaymentAppContentUnitTestBase::SetManifest( | |
| 96 PaymentAppManager* manager, | |
| 97 const std::string& scope, | |
| 98 payments::mojom::PaymentAppManifestPtr manifest, | |
| 99 const PaymentAppManager::SetManifestCallback& callback) { | |
| 100 ASSERT_TRUE(manager); | |
|
please use gerrit instead
2016/12/16 21:41:21
ASSERT_NE(nullptr, manager) is better, because |ma
zino
2016/12/17 17:11:53
Done.
| |
| 101 manager->SetManifest(scope, std::move(manifest), callback); | |
| 102 base::RunLoop().RunUntilIdle(); | |
| 103 } | |
| 104 | |
| 105 void PaymentAppContentUnitTestBase::GetManifest( | |
| 106 PaymentAppManager* manager, | |
| 107 const std::string& scope, | |
| 108 const PaymentAppManager::GetManifestCallback& callback) { | |
| 109 ASSERT_TRUE(manager); | |
| 110 manager->GetManifest(scope, callback); | |
| 111 base::RunLoop().RunUntilIdle(); | |
| 112 } | |
| 113 | |
| 114 } // namespace content | |
| OLD | NEW |