| OLD | NEW |
| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "components/payments/content/payment_app.mojom.h" | 8 #include "components/payments/content/payment_app.mojom.h" |
| 9 #include "content/browser/payments/payment_app_content_unittest_base.h" | 9 #include "content/browser/payments/payment_app_content_unittest_base.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 PaymentAppManifestError* out_error, | 31 PaymentAppManifestError* out_error, |
| 32 PaymentAppManifestPtr manifest, | 32 PaymentAppManifestPtr manifest, |
| 33 PaymentAppManifestError error) { | 33 PaymentAppManifestError error) { |
| 34 *called = true; | 34 *called = true; |
| 35 *out_manifest = std::move(manifest); | 35 *out_manifest = std::move(manifest); |
| 36 *out_error = error; | 36 *out_error = error; |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 class PaymentAppManagerTest : public PaymentAppContentUnitTestBase { | 41 class PaymentManagerTest : public PaymentAppContentUnitTestBase { |
| 42 public: | 42 public: |
| 43 PaymentAppManagerTest() { | 43 PaymentManagerTest() { |
| 44 manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern), | 44 manager_ = CreatePaymentManager(GURL(kServiceWorkerPattern), |
| 45 GURL(kServiceWorkerScript)); | 45 GURL(kServiceWorkerScript)); |
| 46 EXPECT_NE(nullptr, manager_); | 46 EXPECT_NE(nullptr, manager_); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PaymentAppManager* payment_app_manager() const { return manager_; } | 49 PaymentManager* payment_manager() const { return manager_; } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // Owned by payment_app_context_. | 52 // Owned by payment_app_context_. |
| 53 PaymentAppManager* manager_; | 53 PaymentManager* manager_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); | 55 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { | 58 TEST_F(PaymentManagerTest, SetAndGetManifest) { |
| 59 bool called = false; | 59 bool called = false; |
| 60 PaymentAppManifestError error = | 60 PaymentAppManifestError error = |
| 61 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 61 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
| 62 SetManifest(payment_app_manager(), | 62 SetManifest(payment_manager(), |
| 63 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | 63 CreatePaymentAppManifestForTest(kServiceWorkerPattern), |
| 64 base::Bind(&SetManifestCallback, &called, &error)); | 64 base::Bind(&SetManifestCallback, &called, &error)); |
| 65 ASSERT_TRUE(called); | 65 ASSERT_TRUE(called); |
| 66 | 66 |
| 67 ASSERT_EQ(PaymentAppManifestError::NONE, error); | 67 ASSERT_EQ(PaymentAppManifestError::NONE, error); |
| 68 | 68 |
| 69 called = false; | 69 called = false; |
| 70 PaymentAppManifestPtr read_manifest; | 70 PaymentAppManifestPtr read_manifest; |
| 71 PaymentAppManifestError read_error = | 71 PaymentAppManifestError read_error = |
| 72 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 72 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
| 73 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, | 73 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, |
| 74 &read_manifest, &read_error)); | 74 &read_manifest, &read_error)); |
| 75 ASSERT_TRUE(called); | 75 ASSERT_TRUE(called); |
| 76 | 76 |
| 77 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); | 77 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); |
| 78 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); | 78 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); |
| 79 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name); | 79 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name); |
| 80 ASSERT_EQ(1U, read_manifest->options.size()); | 80 ASSERT_EQ(1U, read_manifest->options.size()); |
| 81 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); | 81 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); |
| 82 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); | 82 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); |
| 83 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); | 83 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); |
| 84 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); | 84 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); |
| 85 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); | 85 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { | 88 TEST_F(PaymentManagerTest, SetManifestWithoutAssociatedServiceWorker) { |
| 89 bool called = false; | 89 bool called = false; |
| 90 PaymentAppManifestError error = PaymentAppManifestError::NONE; | 90 PaymentAppManifestError error = PaymentAppManifestError::NONE; |
| 91 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); | 91 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); |
| 92 SetManifest(payment_app_manager(), | 92 SetManifest(payment_manager(), |
| 93 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | 93 CreatePaymentAppManifestForTest(kServiceWorkerPattern), |
| 94 base::Bind(&SetManifestCallback, &called, &error)); | 94 base::Bind(&SetManifestCallback, &called, &error)); |
| 95 ASSERT_TRUE(called); | 95 ASSERT_TRUE(called); |
| 96 | 96 |
| 97 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error); | 97 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { | 100 TEST_F(PaymentManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
| 101 bool called = false; | 101 bool called = false; |
| 102 PaymentAppManifestPtr read_manifest; | 102 PaymentAppManifestPtr read_manifest; |
| 103 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | 103 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; |
| 104 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); | 104 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); |
| 105 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, | 105 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, |
| 106 &read_manifest, &read_error)); | 106 &read_manifest, &read_error)); |
| 107 ASSERT_TRUE(called); | 107 ASSERT_TRUE(called); |
| 108 | 108 |
| 109 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error); | 109 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { | 112 TEST_F(PaymentManagerTest, GetManifestWithNoSavedManifest) { |
| 113 bool called = false; | 113 bool called = false; |
| 114 PaymentAppManifestPtr read_manifest; | 114 PaymentAppManifestPtr read_manifest; |
| 115 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | 115 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; |
| 116 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, | 116 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, |
| 117 &read_manifest, &read_error)); | 117 &read_manifest, &read_error)); |
| 118 ASSERT_TRUE(called); | 118 ASSERT_TRUE(called); |
| 119 | 119 |
| 120 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, | 120 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, |
| 121 read_error); | 121 read_error); |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace content | 124 } // namespace content |
| OLD | NEW |