OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 "base/command_line.h" | |
6 #include "base/macros.h" | |
7 #include "base/run_loop.h" | |
8 #include "components/payments/payment_app.mojom.h" | |
9 #include "content/public/browser/payment_app_provider.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "content/public/common/content_switches.h" | |
12 #include "content/public/test/browser_test_utils.h" | |
13 #include "content/public/test/content_browser_test.h" | |
14 #include "content/public/test/content_browser_test_utils.h" | |
15 #include "content/shell/browser/shell.h" | |
16 #include "net/test/embedded_test_server/embedded_test_server.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 namespace content { | |
20 namespace { | |
21 | |
22 void GetAllManifestsCallback(const base::Closure& done_callback, | |
23 PaymentAppProvider::Manifests* out_manifests, | |
24 PaymentAppProvider::Manifests manifests) { | |
25 *out_manifests = std::move(manifests); | |
26 done_callback.Run(); | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 class PaymentAppBrowserTest : public ContentBrowserTest { | |
32 public: | |
33 PaymentAppBrowserTest() {} | |
34 ~PaymentAppBrowserTest() override {} | |
35 | |
36 void SetUpCommandLine(base::CommandLine* command_line) override { | |
37 command_line->AppendSwitch( | |
38 switches::kEnableExperimentalWebPlatformFeatures); | |
39 } | |
40 | |
41 void SetUpOnMainThread() override { | |
42 https_server_.reset( | |
43 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | |
44 https_server_->ServeFilesFromSourceDirectory("content/test/data"); | |
45 ASSERT_TRUE(https_server_->Start()); | |
46 ASSERT_TRUE(NavigateToURL( | |
47 shell(), | |
48 https_server_->GetURL("/payments/payment_app_invocation.html"))); | |
49 ContentBrowserTest::SetUpOnMainThread(); | |
50 } | |
51 | |
52 bool RunScript(const std::string& script, std::string* result) { | |
53 return content::ExecuteScriptAndExtractString(shell()->web_contents(), | |
54 script, result); | |
55 } | |
56 | |
57 std::string PopConsoleString() { | |
58 std::string script_result; | |
59 EXPECT_TRUE(RunScript("resultQueue.pop()", &script_result)); | |
60 return script_result; | |
61 } | |
62 | |
63 void RegisterPaymentApp() { | |
64 std::string script_result; | |
65 ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result)); | |
66 ASSERT_EQ("registered", script_result); | |
67 } | |
68 | |
69 std::vector<int64_t> GetAllPaymentAppIDs() { | |
70 base::RunLoop run_loop; | |
71 PaymentAppProvider::Manifests manifests; | |
72 PaymentAppProvider::GetInstance()->GetAllManifests( | |
73 shell()->web_contents()->GetBrowserContext(), | |
74 base::Bind(&GetAllManifestsCallback, run_loop.QuitClosure(), | |
75 &manifests)); | |
76 run_loop.Run(); | |
77 | |
78 std::vector<int64_t> ids; | |
79 for (const auto& manifest : manifests) { | |
80 ids.push_back(manifest.first); | |
81 } | |
82 | |
83 return ids; | |
84 } | |
85 | |
86 void InvokePaymentApp(int64_t registration_id) { | |
87 payments::mojom::PaymentAppRequestPtr app_request = | |
88 payments::mojom::PaymentAppRequest::New(); | |
89 app_request->methodData.push_back( | |
90 payments::mojom::PaymentMethodData::New()); | |
91 app_request->total = payments::mojom::PaymentItem::New(); | |
92 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); | |
93 PaymentAppProvider::GetInstance()->InvokePaymentApp( | |
94 shell()->web_contents()->GetBrowserContext(), registration_id, | |
95 std::move(app_request)); | |
96 } | |
97 | |
98 private: | |
99 std::unique_ptr<net::EmbeddedTestServer> https_server_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); | |
102 }; | |
103 | |
104 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, SW) { | |
falken
2017/02/04 22:02:10
nit: Does "SW" just mean "ServiceWorker"? Can you
zino
2017/02/07 17:56:38
Done.
| |
105 RegisterPaymentApp(); | |
106 | |
107 std::vector<int64_t> ids = GetAllPaymentAppIDs(); | |
108 ASSERT_EQ(1U, ids.size()); | |
109 | |
110 InvokePaymentApp(ids[0]); | |
111 | |
112 ASSERT_EQ("payment_app_window_ready", PopConsoleString()); | |
113 ASSERT_EQ("payment_app_response", PopConsoleString()); | |
114 } | |
115 | |
116 } // namespace content | |
OLD | NEW |