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

Unified Diff: content/browser/payments/payment_app_browsertest.cc

Issue 2646313002: PaymentApp: Implement invokePaymentApp() in renderer side. (Closed)
Patch Set: address comments Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/common/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/payments/payment_app_browsertest.cc
diff --git a/content/browser/payments/payment_app_browsertest.cc b/content/browser/payments/payment_app_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..23ddafbb5590f6d42573da0d61dea6c8fc64b909
--- /dev/null
+++ b/content/browser/payments/payment_app_browsertest.cc
@@ -0,0 +1,116 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/run_loop.h"
+#include "components/payments/payment_app.mojom.h"
+#include "content/public/browser/payment_app_provider.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/content_browser_test.h"
+#include "content/public/test/content_browser_test_utils.h"
+#include "content/shell/browser/shell.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+namespace {
+
+void GetAllManifestsCallback(const base::Closure& done_callback,
+ PaymentAppProvider::Manifests* out_manifests,
+ PaymentAppProvider::Manifests manifests) {
+ *out_manifests = std::move(manifests);
+ done_callback.Run();
+}
+
+} // namespace
+
+class PaymentAppBrowserTest : public ContentBrowserTest {
+ public:
+ PaymentAppBrowserTest() {}
+ ~PaymentAppBrowserTest() override {}
+
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitch(
+ switches::kEnableExperimentalWebPlatformFeatures);
+ }
+
+ void SetUpOnMainThread() override {
+ https_server_.reset(
+ new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
+ https_server_->ServeFilesFromSourceDirectory("content/test/data");
+ ASSERT_TRUE(https_server_->Start());
+ ASSERT_TRUE(NavigateToURL(
+ shell(),
+ https_server_->GetURL("/payments/payment_app_invocation.html")));
+ ContentBrowserTest::SetUpOnMainThread();
+ }
+
+ bool RunScript(const std::string& script, std::string* result) {
+ return content::ExecuteScriptAndExtractString(shell()->web_contents(),
+ script, result);
+ }
+
+ std::string PopConsoleString() {
+ std::string script_result;
+ EXPECT_TRUE(RunScript("resultQueue.pop()", &script_result));
+ return script_result;
+ }
+
+ void RegisterPaymentApp() {
+ std::string script_result;
+ ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result));
+ ASSERT_EQ("registered", script_result);
+ }
+
+ std::vector<int64_t> GetAllPaymentAppIDs() {
+ base::RunLoop run_loop;
+ PaymentAppProvider::Manifests manifests;
+ PaymentAppProvider::GetInstance()->GetAllManifests(
+ shell()->web_contents()->GetBrowserContext(),
+ base::Bind(&GetAllManifestsCallback, run_loop.QuitClosure(),
+ &manifests));
+ run_loop.Run();
+
+ std::vector<int64_t> ids;
+ for (const auto& manifest : manifests) {
+ ids.push_back(manifest.first);
+ }
+
+ return ids;
+ }
+
+ void InvokePaymentApp(int64_t registration_id) {
+ payments::mojom::PaymentAppRequestPtr app_request =
+ payments::mojom::PaymentAppRequest::New();
+ app_request->methodData.push_back(
+ payments::mojom::PaymentMethodData::New());
+ app_request->total = payments::mojom::PaymentItem::New();
+ app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New();
+ PaymentAppProvider::GetInstance()->InvokePaymentApp(
+ shell()->web_contents()->GetBrowserContext(), registration_id,
+ std::move(app_request));
+ }
+
+ private:
+ std::unique_ptr<net::EmbeddedTestServer> https_server_;
+
+ DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
+ RegisterPaymentApp();
+
+ std::vector<int64_t> ids = GetAllPaymentAppIDs();
+ ASSERT_EQ(1U, ids.size());
+
+ InvokePaymentApp(ids[0]);
+
+ ASSERT_EQ("payment_app_window_ready", PopConsoleString());
+ ASSERT_EQ("payment_app_response", PopConsoleString());
+}
+
+} // namespace content
« no previous file with comments | « no previous file | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698