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/payment_app.mojom.h" | 8 #include "components/payments/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" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
13 using payments::mojom::PaymentAppManifestError; | 13 using payments::mojom::PaymentAppManifestError; |
14 using payments::mojom::PaymentAppManifestPtr; | 14 using payments::mojom::PaymentAppManifestPtr; |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kServiceWorkerPattern[] = "https://example.com/a"; | 19 const char kServiceWorkerPattern[] = "https://example.com/a"; |
20 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; | 20 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
21 const char kUnregisteredServiceWorkerPattern[] = | |
22 "https://example.com/unregistered"; | |
23 | 21 |
24 void SetManifestCallback(bool* called, | 22 void SetManifestCallback(bool* called, |
25 PaymentAppManifestError* out_error, | 23 PaymentAppManifestError* out_error, |
26 PaymentAppManifestError error) { | 24 PaymentAppManifestError error) { |
27 *called = true; | 25 *called = true; |
28 *out_error = error; | 26 *out_error = error; |
29 } | 27 } |
30 | 28 |
31 void GetManifestCallback(bool* called, | 29 void GetManifestCallback(bool* called, |
32 PaymentAppManifestPtr* out_manifest, | 30 PaymentAppManifestPtr* out_manifest, |
(...skipping 21 matching lines...) Expand all Loading... |
54 // Owned by payment_app_context_. | 52 // Owned by payment_app_context_. |
55 PaymentAppManager* manager_; | 53 PaymentAppManager* manager_; |
56 | 54 |
57 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); | 55 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); |
58 }; | 56 }; |
59 | 57 |
60 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { | 58 TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
61 bool called = false; | 59 bool called = false; |
62 PaymentAppManifestError error = | 60 PaymentAppManifestError error = |
63 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 61 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
64 SetManifest(payment_app_manager(), kServiceWorkerPattern, | 62 SetManifest(payment_app_manager(), |
65 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | 63 CreatePaymentAppManifestForTest(kServiceWorkerPattern), |
66 base::Bind(&SetManifestCallback, &called, &error)); | 64 base::Bind(&SetManifestCallback, &called, &error)); |
67 ASSERT_TRUE(called); | 65 ASSERT_TRUE(called); |
68 | 66 |
69 ASSERT_EQ(PaymentAppManifestError::NONE, error); | 67 ASSERT_EQ(PaymentAppManifestError::NONE, error); |
70 | 68 |
71 called = false; | 69 called = false; |
72 PaymentAppManifestPtr read_manifest; | 70 PaymentAppManifestPtr read_manifest; |
73 PaymentAppManifestError read_error = | 71 PaymentAppManifestError read_error = |
74 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 72 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
75 GetManifest( | 73 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, |
76 payment_app_manager(), kServiceWorkerPattern, | 74 &read_manifest, &read_error)); |
77 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); | |
78 ASSERT_TRUE(called); | 75 ASSERT_TRUE(called); |
79 | 76 |
80 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); | 77 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); |
81 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); | 78 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); |
82 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name); | 79 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name); |
83 ASSERT_EQ(1U, read_manifest->options.size()); | 80 ASSERT_EQ(1U, read_manifest->options.size()); |
84 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); | 81 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); |
85 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); | 82 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); |
86 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); | 83 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); |
87 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); | 84 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); |
88 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); | 85 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); |
89 } | 86 } |
90 | 87 |
91 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { | 88 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { |
92 bool called = false; | 89 bool called = false; |
93 PaymentAppManifestError error = PaymentAppManifestError::NONE; | 90 PaymentAppManifestError error = PaymentAppManifestError::NONE; |
94 SetManifest(payment_app_manager(), kUnregisteredServiceWorkerPattern, | 91 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); |
| 92 SetManifest(payment_app_manager(), |
95 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | 93 CreatePaymentAppManifestForTest(kServiceWorkerPattern), |
96 base::Bind(&SetManifestCallback, &called, &error)); | 94 base::Bind(&SetManifestCallback, &called, &error)); |
97 ASSERT_TRUE(called); | 95 ASSERT_TRUE(called); |
98 | 96 |
99 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error); | 97 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error); |
100 } | 98 } |
101 | 99 |
102 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { | 100 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
103 bool called = false; | 101 bool called = false; |
104 PaymentAppManifestPtr read_manifest; | 102 PaymentAppManifestPtr read_manifest; |
105 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | 103 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; |
106 GetManifest( | 104 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); |
107 payment_app_manager(), kUnregisteredServiceWorkerPattern, | 105 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, |
108 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); | 106 &read_manifest, &read_error)); |
109 ASSERT_TRUE(called); | 107 ASSERT_TRUE(called); |
110 | 108 |
111 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error); | 109 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error); |
112 } | 110 } |
113 | 111 |
114 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { | 112 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { |
115 bool called = false; | 113 bool called = false; |
116 PaymentAppManifestPtr read_manifest; | 114 PaymentAppManifestPtr read_manifest; |
117 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | 115 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; |
118 GetManifest( | 116 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called, |
119 payment_app_manager(), kServiceWorkerPattern, | 117 &read_manifest, &read_error)); |
120 base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); | |
121 ASSERT_TRUE(called); | 118 ASSERT_TRUE(called); |
122 | 119 |
123 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, | 120 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, |
124 read_error); | 121 read_error); |
125 } | 122 } |
126 | 123 |
127 } // namespace content | 124 } // namespace content |
OLD | NEW |