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 @@ ...@@ -31,6 +31,7 @@
#include "chrome/common/media_router/media_source.h" #include "chrome/common/media_router/media_source.h"
#include "chrome/common/media_router/media_source_helper.h" #include "chrome/common/media_router/media_source_helper.h"
#include "chrome/common/media_router/route_request_result.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/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
...@@ -738,7 +739,8 @@ void MediaRouterUIBase::MaybeReportFileInformation( ...@@ -738,7 +739,8 @@ void MediaRouterUIBase::MaybeReportFileInformation(
content::WebContents* MediaRouterUIBase::OpenTabWithUrl(const GURL& url) { content::WebContents* MediaRouterUIBase::OpenTabWithUrl(const GURL& url) {
// Check if the current page is a new tab. If so open file in current page. // Check if the current page is a new tab. If so open file in current page.
// If not then open a new 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); content::NavigationController::LoadURLParams load_params(url);
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED; load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
initiator_->GetController().LoadURLWithParams(load_params); initiator_->GetController().LoadURLWithParams(load_params);
......
...@@ -126,12 +126,6 @@ class MediaRouterUIBase ...@@ -126,12 +126,6 @@ class MediaRouterUIBase
const std::vector<MediaRoute>& routes() const { return routes_; } const std::vector<MediaRoute>& routes() const { return routes_; }
content::WebContents* initiator() const { return initiator_; } 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: protected:
struct RouteRequest { struct RouteRequest {
public: public:
...@@ -222,9 +216,8 @@ class MediaRouterUIBase ...@@ -222,9 +216,8 @@ class MediaRouterUIBase
return start_presentation_context_.get(); return start_presentation_context_.get();
} }
void set_start_presentation_context_for_test( QueryResultManager* query_result_manager() const {
std::unique_ptr<StartPresentationContext> start_presentation_context) { return query_result_manager_.get();
start_presentation_context_ = std::move(start_presentation_context);
} }
void set_media_router_file_dialog_for_test( void set_media_router_file_dialog_for_test(
...@@ -232,15 +225,19 @@ class MediaRouterUIBase ...@@ -232,15 +225,19 @@ class MediaRouterUIBase
media_router_file_dialog_ = std::move(file_dialog); media_router_file_dialog_ = std::move(file_dialog);
} }
QueryResultManager* query_result_manager() const { void set_start_presentation_context_for_test(
return query_result_manager_.get(); std::unique_ptr<StartPresentationContext> start_presentation_context) {
start_presentation_context_ = std::move(start_presentation_context);
} }
private: private:
friend class MediaRouterUiForTest;
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UIMediaRoutesObserverAssignsCurrentCastModes); UIMediaRoutesObserverAssignsCurrentCastModes);
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UIMediaRoutesObserverSkipsUnavailableCastModes); UIMediaRoutesObserverSkipsUnavailableCastModes);
FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest,
UpdateSinksWhenDialogMovesToAnotherDisplay);
class WebContentsFullscreenOnLoadedObserver; class WebContentsFullscreenOnLoadedObserver;
......
...@@ -119,6 +119,7 @@ class CastDialogView : public views::BubbleDialogDelegateView, ...@@ -119,6 +119,7 @@ class CastDialogView : public views::BubbleDialogDelegateView,
private: private:
friend class CastDialogViewTest; friend class CastDialogViewTest;
friend class MediaRouterUiForTest;
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CancelLocalFileSelection); FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CancelLocalFileSelection);
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CastLocalFile); FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, CastLocalFile);
FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, DisableUnsupportedSinks); FRIEND_TEST_ALL_PREFIXES(CastDialogViewTest, DisableUnsupportedSinks);
......
...@@ -42,11 +42,14 @@ class MediaRouterDialogControllerViews ...@@ -42,11 +42,14 @@ class MediaRouterDialogControllerViews
private: private:
friend class content::WebContentsUserData<MediaRouterDialogControllerViews>; friend class content::WebContentsUserData<MediaRouterDialogControllerViews>;
friend class MediaRouterUiForTest;
// Use MediaRouterDialogController::GetOrCreateForWebContents() to create // Use MediaRouterDialogController::GetOrCreateForWebContents() to create
// an instance. // an instance.
explicit MediaRouterDialogControllerViews(content::WebContents* web_contents); explicit MediaRouterDialogControllerViews(content::WebContents* web_contents);
MediaRouterViewsUI* ui() { return ui_.get(); }
// Responsible for notifying the dialog view of dialog model updates and // Responsible for notifying the dialog view of dialog model updates and
// sending route requests to MediaRouter. Set to nullptr when the dialog is // sending route requests to MediaRouter. Set to nullptr when the dialog is
// closed. // closed.
......
...@@ -813,8 +813,7 @@ TEST_F(MediaRouterUITest, UpdateSinksWhenDialogMovesToAnotherDisplay) { ...@@ -813,8 +813,7 @@ TEST_F(MediaRouterUITest, UpdateSinksWhenDialogMovesToAnotherDisplay) {
std::make_unique<TestWebContentsDisplayObserver>(display1); std::make_unique<TestWebContentsDisplayObserver>(display1);
TestWebContentsDisplayObserver* display_observer = TestWebContentsDisplayObserver* display_observer =
display_observer_unique.get(); display_observer_unique.get();
media_router_ui_->set_display_observer_for_test( media_router_ui_->display_observer_ = std::move(display_observer_unique);
std::move(display_observer_unique));
std::vector<MediaSinkWithCastModes> sinks; std::vector<MediaSinkWithCastModes> sinks;
MediaSinkWithCastModes display_sink1( MediaSinkWithCastModes display_sink1(
......
...@@ -33,7 +33,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterE2EBrowserTest, ...@@ -33,7 +33,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterE2EBrowserTest,
test_ui_->WaitForSinkAvailable(receiver_); test_ui_->WaitForSinkAvailable(receiver_);
// Mock out file dialog operations, as those can't be simulated. // Mock out file dialog operations, as those can't be simulated.
FileDialogSelectsFile(file_url); test_ui_->SetLocalFile(file_url);
// Click on the desired mode. // Click on the desired mode.
test_ui_->ChooseSourceType(CastDialogView::kLocalFile); test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
test_ui_->WaitForSinkAvailable(receiver_); test_ui_->WaitForSinkAvailable(receiver_);
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test_utils.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 "content/public/test/test_utils.h"
#include "media/base/test_data_util.h" #include "media/base/test_data_util.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
...@@ -46,6 +45,7 @@ const char kReceiver[] = "receiver"; ...@@ -46,6 +45,7 @@ const char kReceiver[] = "receiver";
const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL(
"media_router/browser_test_resources/"); "media_router/browser_test_resources/");
const char kTestSinkName[] = "test-sink-1"; const char kTestSinkName[] = "test-sink-1";
const char kButterflyVideoFileName[] = "butterfly-853x480.webm";
// The javascript snippets. // The javascript snippets.
const char kCheckSessionScript[] = "checkSession();"; const char kCheckSessionScript[] = "checkSession();";
const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');"; const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');";
...@@ -78,38 +78,6 @@ std::string GetDefaultRequestSessionId(WebContents* web_contents) { ...@@ -78,38 +78,6 @@ std::string GetDefaultRequestSessionId(WebContents* web_contents) {
return session_id; 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 } // namespace
MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() { MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() {
...@@ -119,6 +87,7 @@ MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() { ...@@ -119,6 +87,7 @@ MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() {
} }
void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() { void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() {
test_ui_->TearDown();
MediaRouterBaseBrowserTest::TearDownOnMainThread(); MediaRouterBaseBrowserTest::TearDownOnMainThread();
test_navigation_observer_.reset(); test_navigation_observer_.reset();
} }
...@@ -202,30 +171,27 @@ void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFile( ...@@ -202,30 +171,27 @@ void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFile(
? SetTestData(FILE_PATH_LITERAL("local_media_sink.json")) ? SetTestData(FILE_PATH_LITERAL("local_media_sink.json"))
: SetTestData(FILE_PATH_LITERAL("local_media_sink_route_fail.json")); : SetTestData(FILE_PATH_LITERAL("local_media_sink_route_fail.json"));
GURL file_url = net::FilePathToFileURL( GURL file_url = net::FilePathToFileURL(
media::GetTestDataFilePath("butterfly-853x480.webm")); media::GetTestDataFilePath(kButterflyVideoFileName));
test_ui_->ShowDialog(); test_ui_->ShowDialog();
// Mock out file dialog operations, as those can't be simulated. // 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_->WaitForSink(receiver_);
test_ui_->ChooseSourceType(CastDialogView::kLocalFile); test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
// Wait for the sinks to load. ASSERT_EQ(CastDialogView::kLocalFile, test_ui_->GetChosenSourceType());
test_ui_->WaitForSinkAvailable(receiver_); test_ui_->WaitForSinkAvailable(receiver_);
// Click on sink.
test_ui_->StartCasting(receiver_); test_ui_->StartCasting(receiver_);
// Expect that the current tab has the file open in it.
ASSERT_EQ(file_url, GetActiveWebContents()->GetURL()); ASSERT_EQ(file_url, GetActiveWebContents()->GetURL());
} }
void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFileFails() { void MediaRouterIntegrationBrowserTest::OpenDialogAndCastFileFails() {
SetTestData(FILE_PATH_LITERAL("local_media_sink.json")); SetTestData(FILE_PATH_LITERAL("local_media_sink.json"));
GURL file_url = net::FilePathToFileURL( GURL file_url = net::FilePathToFileURL(
media::GetTestDataFilePath("butterfly-853x480.webm")); media::GetTestDataFilePath(kButterflyVideoFileName));
test_ui_->ShowDialog(); test_ui_->ShowDialog();
// Mock out file dialog opperations, as those can't be simulated. // Mock out file dialog opperations, as those can't be simulated.
FileDialogSelectFails(IssueInfo()); test_ui_->SetLocalFileSelectionIssue(IssueInfo());
// Click on the desired mode. test_ui_->WaitForSink(receiver_);
test_ui_->ChooseSourceType(CastDialogView::kLocalFile); test_ui_->ChooseSourceType(CastDialogView::kLocalFile);
// Wait for the issue to appear.
test_ui_->WaitForAnyIssue(); test_ui_->WaitForAnyIssue();
} }
...@@ -368,17 +334,6 @@ WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() { ...@@ -368,17 +334,6 @@ WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() {
return browser()->tab_strip_model()->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() { void MediaRouterIntegrationBrowserTest::RunBasicTest() {
WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
CheckSessionValidity(web_contents); CheckSessionValidity(web_contents);
...@@ -458,9 +413,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, Basic) { ...@@ -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. // 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, IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileInCurrentTab) { OpenLocalMediaFileInCurrentTab) {
// Start at a new tab, the file should open in the same tab. // Start at a new tab, the file should open in the same tab.
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
// Make sure there is 1 tab. // Make sure there is 1 tab.
...@@ -471,6 +425,9 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, ...@@ -471,6 +425,9 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
// Expect that no new tab has been opened. // Expect that no new tab has been opened.
ASSERT_EQ(1, browser()->tab_strip_model()->count()); 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(); test_ui_->ShowDialog();
// Wait for a route to be created. // Wait for a route to be created.
...@@ -478,9 +435,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, ...@@ -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. // 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, 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. // 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")); ui_test_utils::NavigateToURL(browser(), GURL("https://google.com"));
// Make sure there is 1 tab. // Make sure there is 1 tab.
...@@ -498,7 +454,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, ...@@ -498,7 +454,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
} }
// Tests that failing to create a route with a local file shows an issue. // 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, IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileFailsAndShowsIssue) { DISABLED_OpenLocalMediaFileFailsAndShowsIssue) {
OpenDialogAndCastFileFails(); OpenDialogAndCastFileFails();
...@@ -507,7 +463,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, ...@@ -507,7 +463,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
} }
// Tests that creating a route with a local file opens in fullscreen. // 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, IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileFullscreen) { DISABLED_OpenLocalMediaFileFullscreen) {
// Start at a new tab, the file should open in the same tab. // Start at a new tab, the file should open in the same tab.
...@@ -531,9 +488,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, ...@@ -531,9 +488,8 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
} }
// Tests that failed route creation of local file does not enter fullscreen. // 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, IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
DISABLED_OpenLocalMediaFileCastFailNoFullscreen) { OpenLocalMediaFileCastFailNoFullscreen) {
// Start at a new tab, the file should open in the same tab. // Start at a new tab, the file should open in the same tab.
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
// Make sure there is 1 tab. // Make sure there is 1 tab.
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
namespace media_router { namespace media_router {
struct IssueInfo;
class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest { class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest {
public: public:
MediaRouterIntegrationBrowserTest(); MediaRouterIntegrationBrowserTest();
...@@ -108,14 +106,6 @@ class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest { ...@@ -108,14 +106,6 @@ class MediaRouterIntegrationBrowserTest : public MediaRouterBaseBrowserTest {
// Returns the active WebContents for the current window. // Returns the active WebContents for the current window.
content::WebContents* GetActiveWebContents(); 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 // Runs a basic test in which a presentation is created through the
// MediaRouter dialog, then terminated. // MediaRouter dialog, then terminated.
void RunBasicTest(); void RunBasicTest();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/media/router/media_router_factory.h" #include "chrome/browser/media/router/media_router_factory.h"
#include "chrome/browser/media/router/media_routes_observer.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_sink_button.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_view.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" #include "chrome/browser/ui/views/media_router/media_router_dialog_controller_views.h"
...@@ -50,6 +51,41 @@ class NoRoutesObserver : public MediaRoutesObserver { ...@@ -50,6 +51,41 @@ class NoRoutesObserver : public MediaRoutesObserver {
base::OnceClosure callback_; 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 } // namespace
// static // static
...@@ -64,6 +100,11 @@ MediaRouterUiForTest::~MediaRouterUiForTest() { ...@@ -64,6 +100,11 @@ MediaRouterUiForTest::~MediaRouterUiForTest() {
CHECK(!watch_callback_); CHECK(!watch_callback_);
} }
void MediaRouterUiForTest::TearDown() {
if (IsDialogShown())
HideDialog();
}
void MediaRouterUiForTest::ShowDialog() { void MediaRouterUiForTest::ShowDialog() {
dialog_controller_->ShowMediaRouterDialog(); dialog_controller_->ShowMediaRouterDialog();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -100,8 +141,15 @@ void MediaRouterUiForTest::ChooseSourceType( ...@@ -100,8 +141,15 @@ void MediaRouterUiForTest::ChooseSourceType(
dialog_view->sources_menu_model_for_test()->ActivatedAt(source_index); 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) { void MediaRouterUiForTest::StartCasting(const std::string& sink_name) {
CastDialogSinkButton* sink_button = GetSinkButton(sink_name); CastDialogSinkButton* sink_button = GetSinkButton(sink_name);
CHECK(sink_button->enabled());
sink_button->OnMousePressed(CreateMousePressedEvent()); sink_button->OnMousePressed(CreateMousePressedEvent());
sink_button->OnMouseReleased(CreateMouseReleasedEvent()); sink_button->OnMouseReleased(CreateMouseReleasedEvent());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -159,6 +207,9 @@ void MediaRouterUiForTest::WaitForDialogShown() { ...@@ -159,6 +207,9 @@ void MediaRouterUiForTest::WaitForDialogShown() {
} }
void MediaRouterUiForTest::WaitForDialogHidden() { void MediaRouterUiForTest::WaitForDialogHidden() {
if (!IsDialogShown())
return;
ObserveDialog(WatchType::kDialogHidden); ObserveDialog(WatchType::kDialogHidden);
} }
...@@ -197,6 +248,18 @@ std::string MediaRouterUiForTest::GetIssueTextForSink( ...@@ -197,6 +248,18 @@ std::string MediaRouterUiForTest::GetIssueTextForSink(
return sink_button->sink().issue->info().title; 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) MediaRouterUiForTest::MediaRouterUiForTest(content::WebContents* web_contents)
: web_contents_(web_contents), : web_contents_(web_contents),
dialog_controller_( dialog_controller_(
...@@ -225,7 +288,8 @@ void MediaRouterUiForTest::OnDialogModelUpdated(CastDialogView* dialog_view) { ...@@ -225,7 +288,8 @@ void MediaRouterUiForTest::OnDialogModelUpdated(CastDialogView* dialog_view) {
return sink_button->sink().friendly_name == return sink_button->sink().friendly_name ==
base::UTF8ToUTF16(*watch_sink_name_) && base::UTF8ToUTF16(*watch_sink_name_) &&
sink_button->sink().state == sink_button->sink().state ==
UIMediaSinkState::AVAILABLE; UIMediaSinkState::AVAILABLE &&
sink_button->enabled();
case WatchType::kAnyIssue: case WatchType::kAnyIssue:
return sink_button->sink().issue.has_value(); return sink_button->sink().issue.has_value();
case WatchType::kAnyRoute: case WatchType::kAnyRoute:
......
...@@ -30,12 +30,16 @@ class MediaRouterUiForTest ...@@ -30,12 +30,16 @@ class MediaRouterUiForTest
~MediaRouterUiForTest() override; ~MediaRouterUiForTest() override;
// Cleans up after a test.
void TearDown();
void ShowDialog(); void ShowDialog();
void HideDialog(); void HideDialog();
bool IsDialogShown() const; bool IsDialogShown() const;
// Chooses the source type in the dialog. Requires that the dialog is shown. // Chooses the source type in the dialog. Requires that the dialog is shown.
void ChooseSourceType(CastDialogView::SourceType source_type); void ChooseSourceType(CastDialogView::SourceType source_type);
CastDialogView::SourceType GetChosenSourceType() const;
// These methods require that the dialog is shown and the specified sink is // These methods require that the dialog is shown and the specified sink is
// shown in the dialog. // shown in the dialog.
...@@ -60,6 +64,11 @@ class MediaRouterUiForTest ...@@ -60,6 +64,11 @@ class MediaRouterUiForTest
std::string GetStatusTextForSink(const std::string& sink_name) const; std::string GetStatusTextForSink(const std::string& sink_name) const;
std::string GetIssueTextForSink(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_; } content::WebContents* web_contents() const { return web_contents_; }
private: 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