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

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

Issue 2785523003: PaymentHandler: Rename PaymentAppManager to PaymentManager. (Closed)
Patch Set: PaymentHandler: Rename PaymentAppManager to PaymentManager. Created 3 years, 8 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
(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 <utility>
6
7 #include "base/macros.h"
8 #include "components/payments/content/payment_app.mojom.h"
9 #include "content/browser/payments/payment_app_content_unittest_base.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h"
12
13 using payments::mojom::PaymentAppManifestError;
14 using payments::mojom::PaymentAppManifestPtr;
15
16 namespace content {
17 namespace {
18
19 const char kServiceWorkerPattern[] = "https://example.com/a";
20 const char kServiceWorkerScript[] = "https://example.com/a/script.js";
21
22 void SetManifestCallback(bool* called,
23 PaymentAppManifestError* out_error,
24 PaymentAppManifestError error) {
25 *called = true;
26 *out_error = error;
27 }
28
29 void GetManifestCallback(bool* called,
30 PaymentAppManifestPtr* out_manifest,
31 PaymentAppManifestError* out_error,
32 PaymentAppManifestPtr manifest,
33 PaymentAppManifestError error) {
34 *called = true;
35 *out_manifest = std::move(manifest);
36 *out_error = error;
37 }
38
39 } // namespace
40
41 class PaymentAppManagerTest : public PaymentAppContentUnitTestBase {
42 public:
43 PaymentAppManagerTest() {
44 manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern),
45 GURL(kServiceWorkerScript));
46 EXPECT_NE(nullptr, manager_);
47 }
48
49 PaymentAppManager* payment_app_manager() const { return manager_; }
50
51 private:
52 // Owned by payment_app_context_.
53 PaymentAppManager* manager_;
54
55 DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest);
56 };
57
58 TEST_F(PaymentAppManagerTest, SetAndGetManifest) {
59 bool called = false;
60 PaymentAppManifestError error =
61 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
62 SetManifest(payment_app_manager(),
63 CreatePaymentAppManifestForTest(kServiceWorkerPattern),
64 base::Bind(&SetManifestCallback, &called, &error));
65 ASSERT_TRUE(called);
66
67 ASSERT_EQ(PaymentAppManifestError::NONE, error);
68
69 called = false;
70 PaymentAppManifestPtr read_manifest;
71 PaymentAppManifestError read_error =
72 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
73 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
74 &read_manifest, &read_error));
75 ASSERT_TRUE(called);
76
77 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error);
78 EXPECT_EQ("payment-app-icon", read_manifest->icon.value());
79 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name);
80 ASSERT_EQ(1U, read_manifest->options.size());
81 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value());
82 EXPECT_EQ("Visa ****", read_manifest->options[0]->name);
83 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id);
84 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size());
85 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]);
86 }
87
88 TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) {
89 bool called = false;
90 PaymentAppManifestError error = PaymentAppManifestError::NONE;
91 UnregisterServiceWorker(GURL(kServiceWorkerPattern));
92 SetManifest(payment_app_manager(),
93 CreatePaymentAppManifestForTest(kServiceWorkerPattern),
94 base::Bind(&SetManifestCallback, &called, &error));
95 ASSERT_TRUE(called);
96
97 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error);
98 }
99
100 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) {
101 bool called = false;
102 PaymentAppManifestPtr read_manifest;
103 PaymentAppManifestError read_error = PaymentAppManifestError::NONE;
104 UnregisterServiceWorker(GURL(kServiceWorkerPattern));
105 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
106 &read_manifest, &read_error));
107 ASSERT_TRUE(called);
108
109 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error);
110 }
111
112 TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) {
113 bool called = false;
114 PaymentAppManifestPtr read_manifest;
115 PaymentAppManifestError read_error = PaymentAppManifestError::NONE;
116 GetManifest(payment_app_manager(), base::Bind(&GetManifestCallback, &called,
117 &read_manifest, &read_error));
118 ASSERT_TRUE(called);
119
120 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED,
121 read_error);
122 }
123
124 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_manager.cc ('k') | content/browser/payments/payment_app_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698