Commit 45140752 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

[Media Router] Implement local file integration tests with test API

Re-enable the following tests using test UI API / Views Cast dialog:
MediaRouterIntegrationBrowserTest.OpenLocalMediaFileInCurrentTab
MediaRouterIntegrationBrowserTest.OpenLocalMediaFileInNewTab
MediaRouterIntegrationBrowserTest.OpenLocalMediaFileCastFailNoFullscreen

DISABLED_OpenLocalMediaFileFailsAndShowsIssue cannot be enabled yet
because the Views dialog doesn't support showing an issue not associated
with a sink.

DISABLED_OpenLocalMediaFileFullscreen cannot be enabled yet due to a
known flake in which the local media doesn't go fullscreen on its own.

Bug: 900248
Change-Id: I0e95df58d3e2f92394e5f4b3e25a942a2b514eb9
Reviewed-on: https://chromium-review.googlesource.com/c/1351896
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619692}
parent 0bc7090c
......@@ -31,6 +31,7 @@
#include "chrome/common/media_router/media_source.h"
#include "chrome/common/media_router/media_source_helper.h"
#include "chrome/common/media_router/route_request_result.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/url_formatter/elide_url.h"
......@@ -738,7 +739,8 @@ void MediaRouterUIBase::MaybeReportFileInformation(
content::WebContents* MediaRouterUIBase::OpenTabWithUrl(const GURL& url) {
// Check if the current page is a new tab. If so open file in current page.
// If not then open a new page.
if (initiator_->GetVisibleURL() == chrome::kChromeUINewTabURL) {
if (initiator_->GetVisibleURL() == chrome::kChromeUINewTabURL ||
initiator_->GetVisibleURL() == chrome::kChromeSearchLocalNtpUrl) {
content::NavigationController::LoadURLParams load_params(url);
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
initiator_->GetController().LoadURLWithParams(load_params);
......
......@@ -126,12 +126,6 @@ class MediaRouterUIBase
const std::vector<MediaRoute>& routes() const { return routes_; }
content::WebContents* initiator() const { return initiator_; }
// Used in tests for wired display presentations.
void set_display_observer_for_test(
std::unique_ptr<WebContentsDisplayObserver> display_observer) {
display_observer_ = std::move(display_observer);
}
protected:
struct RouteRequest {
public:
......@@ -222,9 +216,8 @@ class MediaRouterUIBase
return start_presentation_context_.get();
}
void set_start_presentation_context_for_test(
std::unique_ptr<StartPresentationContext> start_presentation_context) {
start_presentation_context_ = std::move(start_presentation_context);
QueryResultManager* query_result_manager() const {
return query_result_manager_.get();
}
void set_media_router_file_dialog_for_test(
......@@ -232,15 +225,19 @@ class MediaRouterUIBase
media_router_file_dialog_ = std::move(file_dialog);
}
QueryResultManager* query_result_manager() const {
return query_result_manager_.get();
void set_start_presentation_context_for_test(
std::unique_ptr<StartPresentationContext> start_presentation_context) {
start_presentation_context_ = std::move(start_presentation_context);
}
private:
friend class MediaRouterUiForTest;
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UIMediaRoutesObserverAssignsCurrentCastModes);
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UIMediaRoutesObserverSkipsUnavailableCastModes);
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UpdateSinksWhenDialogMovesToAnotherDisplay);
class WebContentsFullscreenOnLoadedObserver;
......
......@@ -119,6 +119,7 @@ class CastDialogView : public views::BubbleDialogDelegateView,
private:
friend class CastDialogViewTest;
friend class MediaRouterUiForTest;
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CancelLocalFileSelection);
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CastLocalFile);
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, DisableUnsupportedSinks);
......
......@@ -42,11 +42,14 @@ class MediaRouterDialogControllerViews
private:
friend class content::WebContentsUserData<MediaRouterDialogControllerViews>;
friend class MediaRouterUiForTest;
// Use MediaRouterDialogController::GetOrCreateForWebContents() to create
// an instance.
explicit MediaRouterDialogControllerViews(content::WebContents* web_contents);
MediaRouterViewsUI* ui() { return ui_.get(); }
// Responsible for notifying the dialog view of dialog model updates and
// sending route requests to MediaRouter. Set to nullptr when the dialog is
// closed.
......
......@@ -813,8 +813,7 @@ TEST_F(MediaRouterUITest, UpdateSinksWhenDialogMovesToAnotherDisplay) {
std::make_unique<TestWebContentsDisplayObserver>(display1);
TestWebContentsDisplayObserver* display_observer =
display_observer_unique.get();
media_router_ui_->set_display_observer_for_test(
std::move(display_observer_unique));
media_router_ui_->display_observer_ = std::move(display_observer_unique);
std::vector<MediaSinkWithCastModes> sinks;
MediaSinkWithCastModes display_sink1(
......
......@@ -33,7 +33,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterE2EBrowserTest,
test_ui_->WaitForSinkAvailable(receiver_);
// Mock out file dialog operations, as those can't be simulated.
FileDialogSelectsFile(file_url);
test_ui_->SetLocalFile(file_url);
// Click on the desired mode.
test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
test_ui_->WaitForSinkAvailable(receiver_);
......
......@@ -28,7 +28,6 @@
#include "components/policy/policy_constants.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "media/base/test_data_util.h"
#include "net/base/filename_util.h"
......@@ -46,6 +45,7 @@ const char kReceiver[] = "receiver";
const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL(
"media_router/browser_test_resources/");
const char kTestSinkName[] = "test-sink-1";
const char kButterflyVideoFileName[] = "butterfly-853x480.webm";
// The javascript snippets.
const char kCheckSessionScript[] = "checkSession();";
const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');";
......@@ -78,38 +78,6 @@ std::string GetDefaultRequestSessionId(WebContents* web_contents) {
return session_id;
}
// File Dialog which fails on open.
class TestFailMediaRouterFileDialog : public MediaRouterFileDialog {
public:
TestFailMediaRouterFileDialog(MediaRouterFileDialogDelegate* delegate,
const IssueInfo& issue)
: MediaRouterFileDialog(nullptr), delegate_(delegate), issue_(issue) {}
~TestFailMediaRouterFileDialog() override {}
MediaRouterFileDialogDelegate* delegate_;
const IssueInfo issue_;
void OpenFileDialog(Browser* browser) override {
delegate_->FileDialogSelectionFailed(issue_);
}
};
// File Dialog with a preset file URL.
class TestMediaRouterFileDialog : public MediaRouterFileDialog {
public:
TestMediaRouterFileDialog(MediaRouterFileDialogDelegate* delegate, GURL url)
: MediaRouterFileDialog(nullptr), delegate_(delegate), file_url_(url) {}
~TestMediaRouterFileDialog() override {}
MediaRouterFileDialogDelegate* delegate_;
GURL file_url_;
GURL GetLastSelectedFileUrl() override { return file_url_; }
void OpenFileDialog(Browser* browser) override {
delegate_->FileDialogFileSelected(ui::SelectedFileInfo());
}
};
} // namespace
MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() {
......@@ -119,6 +87,7 @@ MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() {
}
void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() {
test_ui_->TearDown();
MediaRouterBaseBrowserTest::TearDownOnMainThread();
test_navigation_observer_.reset();
}
......@@ -202,30 +171,27 @@ void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFile(
? SetTestData(FILE_PATH_LITERAL("local_media_sink.json"))
: SetTestData(FILE_PATH_LITERAL("local_media_sink_route_fail.json"));
GURL file_url = net::FilePathToFileURL(
media::GetTestDataFilePath("butterfly-853x480.webm"));
media::GetTestDataFilePath(kButterflyVideoFileName));
test_ui_->ShowDialog();
// Mock out file dialog operations, as those can't be simulated.
FileDialogSelectsFile(file_url);
// Click on the desired mode.
test_ui_->SetLocalFile(file_url);
test_ui_->WaitForSink(receiver_);
test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
// Wait for the sinks to load.
ASSERT_EQ(CastDialogView::kLocalFile, test_ui_->GetChosenSourceType());
test_ui_->WaitForSinkAvailable(receiver_);
// Click on sink.
test_ui_->StartCasting(receiver_);
// Expect that the current tab has the file open in it.
ASSERT_EQ(file_url, GetActiveWebContents()->GetURL());
}
void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFileFails() {
SetTestData(FILE_PATH_LITERAL("local_media_sink.json"));
GURL file_url = net::FilePathToFileURL(
media::GetTestDataFilePath("butterfly-853x480.webm"));
media::GetTestDataFilePath(kButterflyVideoFileName));
test_ui_->ShowDialog();
// Mock out file dialog opperations, as those can't be simulated.
FileDialogSelectFails(IssueInfo());
// Click on the desired mode.
test_ui_->SetLocalFileSelectionIssue(IssueInfo());
test_ui_->WaitForSink(receiver_);
test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
// Wait for the issue to appear.
test_ui_->WaitForAnyIssue();
}
......@@ -368,17 +334,6 @@ WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
void MediaRouterIntegrationBrowserTest::FileDialogSelectsFile(GURL file_url) {
// TODO(https://crbug.com/900248): Implement this.
NOTIMPLEMENTED();
}
void MediaRouterIntegrationBrowserTest::FileDialogSelectFails(
const IssueInfo& issue) {
// TODO(https://crbug.com/900248): Implement this.
NOTIMPLEMENTED();
}
void MediaRouterIntegrationBrowserTest::RunBasicTest() {
WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
CheckSessionValidity(web_contents);
......@@ -458,9 +413,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, Basic) {
}
// Tests that creating a route with a local file opens the file in a new tab.
// TODO(https://crbug.com/900248): Make this test pass with the Views dialog.
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileInCurrentTab) {
OpenLocalMediaFileInCurrentTab) {
// Start at a new tab, the file should open in the same tab.
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
// Make sure there is 1 tab.
......@@ -471,6 +425,9 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
// Expect that no new tab has been opened.
ASSERT_EQ(1, browser()->tab_strip_model()->count());
// The dialog will close from navigating to the local file within the tab, so
// open it again after it closes.
test_ui_->WaitForDialogHidden();
test_ui_->ShowDialog();
// Wait for a route to be created.
......@@ -478,9 +435,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
}
// Tests that creating a route with a local file opens the file in a new tab.
// TODO(https://crbug.com/900248): Make this test pass with the Views dialog.
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileInNewTab) {
OpenLocalMediaFileInNewTab) {
// Start at a tab with content in it, the file will open in a new tab.
ui_test_utils::NavigateToURL(browser(), GURL("https://google.com"));
// Make sure there is 1 tab.
......@@ -498,7 +454,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
}
// Tests that failing to create a route with a local file shows an issue.
// TODO(https://crbug.com/900248): Make this test pass with the Views dialog.
// TODO(https://crbug.com/907539): Make the Views dialog show the issue.
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileFailsAndShowsIssue) {
OpenDialogAndCastFileFails();
......@@ -507,7 +463,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
}
// Tests that creating a route with a local file opens in fullscreen.
// TODO(https://crbug.com/900248): Make this test pass with the Views dialog.
// TODO(https://crbug.com/903016) Disabled due to flakiness in entering
// fullscreen.
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileFullscreen) {
// Start at a new tab, the file should open in the same tab.
......@@ -531,9 +488,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
}
// Tests that failed route creation of local file does not enter fullscreen.
// TODO(https://crbug.com/900248): Make this test pass with the Views dialog.
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileCastFailNoFullscreen) {
OpenLocalMediaFileCastFailNoFullscreen) {
// Start at a new tab, the file should open in the same tab.
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
// Make sure there is 1 tab.
......
......@@ -21,8 +21,6 @@
namespace media_router {
struct IssueInfo;
class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest {
public:
MediaRouterIntegrationBrowserTest();
......@@ -108,14 +106,6 @@ class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest {
// Returns the active WebContents for the current window.
content::WebContents* GetActiveWebContents();
// Sets the MediaRouterFileDialog to act like a valid file was selected on
// opening the dialog.
void FileDialogSelectsFile(GURL file_url);
// Sets the MediaRouterFileDialog to act like a bad file was selected on
// opening the dialog.
void FileDialogSelectFails(const IssueInfo& issue);
// Runs a basic test in which a presentation is created through the
// MediaRouter dialog, then terminated.
void RunBasicTest();
......
......@@ -7,6 +7,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/media/router/media_router_factory.h"
#include "chrome/browser/media/router/media_routes_observer.h"
#include "chrome/browser/ui/media_router/media_router_file_dialog.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_sink_button.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_view.h"
#include "chrome/browser/ui/views/media_router/media_router_dialog_controller_views.h"
......@@ -50,6 +51,41 @@ class NoRoutesObserver : public MediaRoutesObserver {
base::OnceClosure callback_;
};
// File dialog with a preset file URL.
class TestMediaRouterFileDialog : public MediaRouterFileDialog {
public:
TestMediaRouterFileDialog(MediaRouterFileDialogDelegate* delegate, GURL url)
: MediaRouterFileDialog(nullptr), delegate_(delegate), file_url_(url) {}
~TestMediaRouterFileDialog() override {}
GURL GetLastSelectedFileUrl() override { return file_url_; }
void OpenFileDialog(Browser* browser) override {
delegate_->FileDialogFileSelected(ui::SelectedFileInfo());
}
private:
MediaRouterFileDialogDelegate* delegate_;
GURL file_url_;
};
// File dialog which fails on open.
class TestFailMediaRouterFileDialog : public MediaRouterFileDialog {
public:
TestFailMediaRouterFileDialog(MediaRouterFileDialogDelegate* delegate,
const IssueInfo& issue)
: MediaRouterFileDialog(nullptr), delegate_(delegate), issue_(issue) {}
~TestFailMediaRouterFileDialog() override {}
void OpenFileDialog(Browser* browser) override {
delegate_->FileDialogSelectionFailed(issue_);
}
private:
MediaRouterFileDialogDelegate* delegate_;
const IssueInfo issue_;
};
} // namespace
// static
......@@ -64,6 +100,11 @@ MediaRouterUiForTest::~MediaRouterUiForTest() {
CHECK(!watch_callback_);
}
void MediaRouterUiForTest::TearDown() {
if (IsDialogShown())
HideDialog();
}
void MediaRouterUiForTest::ShowDialog() {
dialog_controller_->ShowMediaRouterDialog();
base::RunLoop().RunUntilIdle();
......@@ -100,8 +141,15 @@ void MediaRouterUiForTest::ChooseSourceType(
dialog_view->sources_menu_model_for_test()->ActivatedAt(source_index);
}
CastDialogView::SourceType MediaRouterUiForTest::GetChosenSourceType() const {
CastDialogView* dialog_view = CastDialogView::GetInstance();
CHECK(dialog_view);
return dialog_view->selected_source_;
}
void MediaRouterUiForTest::StartCasting(const std::string& sink_name) {
CastDialogSinkButton* sink_button = GetSinkButton(sink_name);
CHECK(sink_button->enabled());
sink_button->OnMousePressed(CreateMousePressedEvent());
sink_button->OnMouseReleased(CreateMouseReleasedEvent());
base::RunLoop().RunUntilIdle();
......@@ -159,6 +207,9 @@ void MediaRouterUiForTest::WaitForDialogShown() {
}
void MediaRouterUiForTest::WaitForDialogHidden() {
if (!IsDialogShown())
return;
ObserveDialog(WatchType::kDialogHidden);
}
......@@ -197,6 +248,18 @@ std::string MediaRouterUiForTest::GetIssueTextForSink(
return sink_button->sink().issue->info().title;
}
void MediaRouterUiForTest::SetLocalFile(const GURL& file_url) {
dialog_controller_->ui()->set_media_router_file_dialog_for_test(
std::make_unique<TestMediaRouterFileDialog>(dialog_controller_->ui(),
file_url));
}
void MediaRouterUiForTest::SetLocalFileSelectionIssue(const IssueInfo& issue) {
dialog_controller_->ui()->set_media_router_file_dialog_for_test(
std::make_unique<TestFailMediaRouterFileDialog>(dialog_controller_->ui(),
issue));
}
MediaRouterUiForTest::MediaRouterUiForTest(content::WebContents* web_contents)
: web_contents_(web_contents),
dialog_controller_(
......@@ -225,7 +288,8 @@ void MediaRouterUiForTest::OnDialogModelUpdated(CastDialogView* dialog_view) {
return sink_button->sink().friendly_name ==
base::UTF8ToUTF16(*watch_sink_name_) &&
sink_button->sink().state ==
UIMediaSinkState::AVAILABLE;
UIMediaSinkState::AVAILABLE &&
sink_button->enabled();
case WatchType::kAnyIssue:
return sink_button->sink().issue.has_value();
case WatchType::kAnyRoute:
......
......@@ -30,12 +30,16 @@ class MediaRouterUiForTest
~MediaRouterUiForTest() override;
// Cleans up after a test.
void TearDown();
void ShowDialog();
void HideDialog();
bool IsDialogShown() const;
// Chooses the source type in the dialog. Requires that the dialog is shown.
void ChooseSourceType(CastDialogView::SourceType source_type);
CastDialogView::SourceType GetChosenSourceType() const;
// These methods require that the dialog is shown and the specified sink is
// shown in the dialog.
......@@ -60,6 +64,11 @@ class MediaRouterUiForTest
std::string GetStatusTextForSink(const std::string& sink_name) const;
std::string GetIssueTextForSink(const std::string& sink_name) const;
// Sets up a mock file picker that returns |file_url| as the selected file.
void SetLocalFile(const GURL& file_url);
// Sets up a mock file picker that fails with |issue|.
void SetLocalFileSelectionIssue(const IssueInfo& issue);
content::WebContents* web_contents() const { return web_contents_; }
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment