Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
please use gerrit instead
2017/01/09 14:50:13
2017
Mathieu
2017/01/09 16:54:19
Doh! I should be used to it around February
| |
| 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 <vector> | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 10 #include "chrome/test/base/in_process_browser_test.h" | |
| 11 #include "chrome/test/base/ui_test_utils.h" | |
| 12 #include "components/payments/payment_request_impl.h" | |
| 13 #include "components/payments/payment_request_web_contents_manager.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/common/content_switches.h" | |
| 16 #include "content/public/test/browser_test_utils.h" | |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace payments { | |
| 21 | |
| 22 class PaymentRequestWebContentsManagerBrowserTest | |
| 23 : public InProcessBrowserTest { | |
| 24 public: | |
| 25 PaymentRequestWebContentsManagerBrowserTest() {} | |
| 26 ~PaymentRequestWebContentsManagerBrowserTest() override {} | |
| 27 | |
| 28 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 29 InProcessBrowserTest::SetUpCommandLine(command_line); | |
| 30 command_line->AppendSwitch( | |
| 31 switches::kEnableExperimentalWebPlatformFeatures); | |
| 32 } | |
| 33 | |
| 34 void SetUpOnMainThread() override { | |
| 35 https_server_.reset( | |
| 36 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | |
| 37 ASSERT_TRUE(https_server_->InitializeAndListen()); | |
| 38 content::SetupCrossSiteRedirector(https_server_.get()); | |
|
please use gerrit instead
2017/01/09 14:50:13
No need for cross-site redirector when not testing
Mathieu
2017/01/09 16:54:19
Done.
| |
| 39 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); | |
| 40 https_server_->StartAcceptingConnections(); | |
| 41 } | |
| 42 | |
| 43 // Convenience method to get a list of PaymentRequestImpl associated with | |
| 44 // |web_contents|. | |
| 45 const std::vector<PaymentRequestImpl*> GetPaymentRequestImpls( | |
| 46 content::WebContents* web_contents) { | |
| 47 PaymentRequestWebContentsManager* manager = | |
| 48 PaymentRequestWebContentsManager::GetOrCreateForWebContents( | |
| 49 web_contents); | |
| 50 if (!manager) | |
| 51 return std::vector<PaymentRequestImpl*>(); | |
| 52 | |
| 53 std::vector<PaymentRequestImpl*> payment_requests_ptrs; | |
| 54 for (const auto& p : manager->payment_requests_) { | |
| 55 payment_requests_ptrs.push_back(p.first); | |
| 56 } | |
| 57 return payment_requests_ptrs; | |
| 58 } | |
| 59 | |
| 60 std::unique_ptr<net::EmbeddedTestServer> https_server_; | |
| 61 | |
| 62 private: | |
| 63 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManagerBrowserTest); | |
| 64 }; | |
| 65 | |
| 66 IN_PROC_BROWSER_TEST_F(PaymentRequestWebContentsManagerBrowserTest, | |
| 67 MultiplePaymentRequests) { | |
| 68 GURL url = https_server_->GetURL("127.0.0.1", | |
|
please use gerrit instead
2017/01/09 14:50:13
Hostnames are important only for cross-site iframe
Mathieu
2017/01/09 16:54:19
Done.
| |
| 69 "/payment_request_multiple_requests.html"); | |
| 70 ui_test_utils::NavigateToURL(browser(), url); | |
| 71 | |
| 72 const std::vector<PaymentRequestImpl*> payment_requests = | |
| 73 GetPaymentRequestImpls( | |
| 74 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 75 EXPECT_EQ(5U, payment_requests.size()); | |
| 76 } | |
| 77 | |
| 78 } // namespace payments | |
| OLD | NEW |