[M94 Dev] Remove *.pyc files from git repositories
[platform/framework/web/chromium-efl.git] / chrome / browser / capability_delegation_browsertest.cc
1 // Copyright 2021 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/feature_list.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "chrome/test/payments/payment_request_platform_browsertest_base.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/content_features.h"
13 #include "content/public/test/browser_test.h"
14 #include "net/dns/mock_host_resolver.h"
15 #include "url/gurl.h"
16
17 class CapabilityDelegationBrowserTest
18     : public payments::PaymentRequestPlatformBrowserTestBase {
19  public:
20   CapabilityDelegationBrowserTest() {
21     feature_list_.InitAndEnableFeature(
22         features::kCapabilityDelegationPaymentRequest);
23   }
24
25   ~CapabilityDelegationBrowserTest() override = default;
26
27   void SetUpOnMainThread() override {
28     host_resolver()->AddRule("*", "127.0.0.1");
29     ASSERT_TRUE(https_server()->InitializeAndListen());
30     content::SetupCrossSiteRedirector(https_server());
31     https_server()->ServeFilesFromSourceDirectory(
32         "chrome/test/data/capability_delegation");
33     https_server()->StartAcceptingConnections();
34   }
35
36  private:
37   base::test::ScopedFeatureList feature_list_;
38
39   DISALLOW_COPY_AND_ASSIGN(CapabilityDelegationBrowserTest);
40 };
41
42 IN_PROC_BROWSER_TEST_F(CapabilityDelegationBrowserTest, PaymentRequest) {
43   // Navigate the top frame.
44   GURL main_url(
45       https_server()->GetURL("a.com", "/payment_request_delegation.html"));
46   ui_test_utils::NavigateToURL(browser(), main_url);
47
48   // Navigate the sub-frame cross-site.
49   content::WebContents* active_web_contents =
50       browser()->tab_strip_model()->GetActiveWebContents();
51   GURL cross_site_url(
52       https_server()->GetURL("b.com", "/payment_request_delegation_sub.html"));
53   EXPECT_TRUE(
54       NavigateIframeToURL(active_web_contents, "iframe", cross_site_url));
55
56   // Confirm that the subframe is cross-process depending on the process
57   // model.
58   content::RenderFrameHost* frame_host =
59       ChildFrameAt(active_web_contents->GetMainFrame(), 0);
60   ASSERT_TRUE(frame_host);
61   EXPECT_EQ(cross_site_url, frame_host->GetLastCommittedURL());
62   auto* main_instance = active_web_contents->GetMainFrame()->GetSiteInstance();
63   auto* subframe_instance = frame_host->GetSiteInstance();
64   if (main_instance->RequiresDedicatedProcess()) {
65     // Subframe is cross process because it can't be place in the main frame's
66     // process.
67     EXPECT_TRUE(frame_host->IsCrossProcessSubframe());
68   } else {
69     // The main frame does not require a dedicated process so the subframe will
70     // be placed in the same process as the main frame.
71     EXPECT_FALSE(frame_host->IsCrossProcessSubframe());
72     EXPECT_FALSE(subframe_instance->RequiresDedicatedProcess());
73     EXPECT_EQ(content::AreDefaultSiteInstancesEnabled(),
74               main_instance == subframe_instance);
75   }
76
77   // Without either user activation or payment request token, PaymentRequest
78   // dialog is not allowed.
79   EXPECT_EQ("NotAllowedError",
80             content::EvalJs(active_web_contents, "sendRequestToSubframe(false)",
81                             content::EXECUTE_SCRIPT_NO_USER_GESTURE));
82
83   // Without user activation but with the delegation option, PaymentRequest
84   // dialog is not allowed.
85   EXPECT_EQ("NotAllowedError",
86             content::EvalJs(active_web_contents, "sendRequestToSubframe(true)",
87                             content::EXECUTE_SCRIPT_NO_USER_GESTURE));
88
89   // With user activation but without the delegation option, PaymentRequest
90   // dialog is not allowed.
91   EXPECT_EQ("NotAllowedError", content::EvalJs(active_web_contents,
92                                                "sendRequestToSubframe(false)"));
93
94   // With both user activation and the delegation option, PaymentRequest dialog
95   // is shown and then successfully aborted by the script.
96   EXPECT_EQ("AbortError", content::EvalJs(active_web_contents,
97                                           "sendRequestToSubframe(true)"));
98 }