| // Copyright 2019 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 "chrome/browser/serial/serial_chooser_context.h" |
| #include "chrome/browser/serial/serial_chooser_context_factory.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "components/bubble/bubble_manager.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/test_navigation_observer.h" |
| #include "mojo/public/cpp/bindings/interface_request.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "services/device/public/cpp/test/fake_serial_port_manager.h" |
| #include "services/device/public/mojom/serial.mojom.h" |
| #include "url/gurl.h" |
| |
| namespace { |
| |
| class SerialTest : public InProcessBrowserTest { |
| public: |
| void SetUpCommandLine(base::CommandLine* command_line) override { |
| InProcessBrowserTest::SetUpCommandLine(command_line); |
| command_line->AppendSwitch( |
| switches::kEnableExperimentalWebPlatformFeatures); |
| } |
| |
| void SetUpOnMainThread() override { |
| embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); |
| ASSERT_TRUE(embedded_test_server()->Start()); |
| |
| device::mojom::SerialPortManagerPtr port_manager_ptr; |
| port_manager_.AddBinding(mojo::MakeRequest(&port_manager_ptr)); |
| SerialChooserContextFactory::GetForProfile(browser()->profile()) |
| ->SetPortManagerForTesting(std::move(port_manager_ptr)); |
| |
| GURL url = embedded_test_server()->GetURL("localhost", "/simple_page.html"); |
| ui_test_utils::NavigateToURL(browser(), url); |
| } |
| |
| private: |
| device::FakeSerialPortManager port_manager_; |
| }; |
| |
| IN_PROC_BROWSER_TEST_F(SerialTest, NavigateWithChooserCrossOrigin) { |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| |
| content::TestNavigationObserver observer( |
| web_contents, 1 /* number_of_navigations */, |
| content::MessageLoopRunner::QuitMode::DEFERRED); |
| |
| EXPECT_TRUE(content::ExecJs(web_contents, |
| R"(navigator.serial.requestPort({}); |
| document.location.href = "https://google.com";)")); |
| |
| observer.Wait(); |
| EXPECT_EQ(0u, browser()->GetBubbleManager()->GetBubbleCountForTesting()); |
| } |
| |
| } // namespace |