Commit 1bb44f99 authored by Palak Agarwal's avatar Palak Agarwal Committed by Commit Bot

Passing Origin instead of URL as the app_name for the picker params

Change-Id: I5b7ee18f7f497d787998bde8408d46987a45a6eb
Bug: 1136714
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463833
Commit-Queue: Palak Agarwal <agpalak@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819813}
parent 643ae974
......@@ -194,8 +194,8 @@ void DisplayMediaAccessHandler::ProcessQueuedAccessRequest(
gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow();
picker_params.context = parent_window;
picker_params.parent = parent_window;
picker_params.app_name = url_formatter::FormatUrlForSecurityDisplay(
web_contents->GetLastCommittedURL(),
picker_params.app_name = url_formatter::FormatOriginForSecurityDisplay(
url::Origin::Create(web_contents->GetLastCommittedURL()),
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
picker_params.target_name = picker_params.app_name;
picker_params.request_audio =
......
......@@ -19,6 +19,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
......@@ -88,6 +89,10 @@ class DisplayMediaAccessHandlerTest : public ChromeRenderViewHostTestHarness {
content::NotificationDetails());
}
DesktopMediaPicker::Params GetParams() {
return picker_factory_->picker()->GetParams();
}
const DisplayMediaAccessHandler::RequestsQueues& GetRequestQueues() {
return access_handler_->pending_requests_;
}
......@@ -193,6 +198,73 @@ TEST_F(DisplayMediaAccessHandlerTest, UpdateMediaRequestStateWithClosing) {
access_handler_.reset();
}
TEST_F(DisplayMediaAccessHandlerTest, CorrectHostAsksForPermissions) {
const int render_process_id = 0;
const int render_frame_id = 0;
const int page_request_id = 0;
const blink::mojom::MediaStreamType video_stream_type =
blink::mojom::MediaStreamType::DISPLAY_VIDEO_CAPTURE;
const blink::mojom::MediaStreamType audio_stream_type =
blink::mojom::MediaStreamType::DISPLAY_AUDIO_CAPTURE;
FakeDesktopMediaPickerFactory::TestFlags test_flags[] = {
{true /* expect_screens */, true /* expect_windows*/,
true /* expect_tabs */, true /* expect_audio */,
content::DesktopMediaID(), true /* cancelled */}};
picker_factory_->SetTestFlags(test_flags, base::size(test_flags));
content::MediaStreamRequest request(
render_process_id, render_frame_id, page_request_id,
GURL("http://origin/"), false, blink::MEDIA_GENERATE_STREAM,
std::string(), std::string(), audio_stream_type, video_stream_type,
/*disable_local_echo=*/false, /*request_pan_tilt_zoom_permission=*/false);
content::MediaResponseCallback callback;
content::WebContents* test_web_contents = web_contents();
std::unique_ptr<content::NavigationSimulator> navigation =
content::NavigationSimulator::CreateBrowserInitiated(
GURL("blob:http://127.0.0.1:8000/says: www.google.com"),
test_web_contents);
navigation->Commit();
access_handler_->HandleRequest(test_web_contents, request,
std::move(callback), nullptr /* extension */);
DesktopMediaPicker::Params params = GetParams();
access_handler_->UpdateMediaRequestState(
render_process_id, render_frame_id, page_request_id, video_stream_type,
content::MEDIA_REQUEST_STATE_CLOSING);
EXPECT_EQ(base::UTF8ToUTF16("http://127.0.0.1:8000"), params.app_name);
}
TEST_F(DisplayMediaAccessHandlerTest, CorrectHostAsksForPermissionsNormalURLs) {
const int render_process_id = 0;
const int render_frame_id = 0;
const int page_request_id = 0;
const blink::mojom::MediaStreamType video_stream_type =
blink::mojom::MediaStreamType::DISPLAY_VIDEO_CAPTURE;
const blink::mojom::MediaStreamType audio_stream_type =
blink::mojom::MediaStreamType::DISPLAY_AUDIO_CAPTURE;
FakeDesktopMediaPickerFactory::TestFlags test_flags[] = {
{true /* expect_screens */, true /* expect_windows*/,
true /* expect_tabs */, true /* expect_audio */,
content::DesktopMediaID(), true /* cancelled */}};
picker_factory_->SetTestFlags(test_flags, base::size(test_flags));
content::MediaStreamRequest request(
render_process_id, render_frame_id, page_request_id,
GURL("http://origin/"), false, blink::MEDIA_GENERATE_STREAM,
std::string(), std::string(), audio_stream_type, video_stream_type,
/*disable_local_echo=*/false, /*request_pan_tilt_zoom_permission=*/false);
content::MediaResponseCallback callback;
content::WebContents* test_web_contents = web_contents();
std::unique_ptr<content::NavigationSimulator> navigation =
content::NavigationSimulator::CreateBrowserInitiated(
GURL("https://www.google.com"), test_web_contents);
navigation->Commit();
access_handler_->HandleRequest(test_web_contents, request,
std::move(callback), nullptr /* extension */);
DesktopMediaPicker::Params params = GetParams();
access_handler_->UpdateMediaRequestState(
render_process_id, render_frame_id, page_request_id, video_stream_type,
content::MEDIA_REQUEST_STATE_CLOSING);
EXPECT_EQ(base::UTF8ToUTF16("www.google.com"), params.app_name);
}
TEST_F(DisplayMediaAccessHandlerTest, WebContentsDestroyed) {
FakeDesktopMediaPickerFactory::TestFlags test_flags[] = {
{true /* expect_screens */, true /* expect_windows*/,
......
......@@ -12,69 +12,66 @@
#include "chrome/browser/media/webrtc/fake_desktop_media_list.h"
#include "testing/gtest/include/gtest/gtest.h"
class FakeDesktopMediaPicker : public DesktopMediaPicker {
public:
explicit FakeDesktopMediaPicker(
FakeDesktopMediaPickerFactory::TestFlags* expectation)
: expectation_(expectation) {
expectation_->picker_created = true;
}
~FakeDesktopMediaPicker() override { expectation_->picker_deleted = true; }
// DesktopMediaPicker interface.
void Show(const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) override {
bool show_screens = false;
bool show_windows = false;
bool show_tabs = false;
for (auto& source_list : source_lists) {
switch (source_list->GetMediaListType()) {
case content::DesktopMediaID::TYPE_NONE:
break;
case content::DesktopMediaID::TYPE_SCREEN:
show_screens = true;
break;
case content::DesktopMediaID::TYPE_WINDOW:
show_windows = true;
break;
case content::DesktopMediaID::TYPE_WEB_CONTENTS:
show_tabs = true;
break;
}
}
EXPECT_EQ(expectation_->expect_screens, show_screens);
EXPECT_EQ(expectation_->expect_windows, show_windows);
EXPECT_EQ(expectation_->expect_tabs, show_tabs);
EXPECT_EQ(expectation_->expect_audio, params.request_audio);
EXPECT_EQ(params.modality, ui::ModalType::MODAL_TYPE_CHILD);
FakeDesktopMediaPicker::FakeDesktopMediaPicker(
FakeDesktopMediaPickerFactory::TestFlags* expectation)
: expectation_(expectation) {
expectation_->picker_created = true;
}
FakeDesktopMediaPicker::~FakeDesktopMediaPicker() {
expectation_->picker_deleted = true;
}
if (!expectation_->cancelled) {
// Post a task to call the callback asynchronously.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&FakeDesktopMediaPicker::CallCallback,
weak_factory_.GetWeakPtr(), std::move(done_callback)));
} else {
// If we expect the dialog to be cancelled then store the callback to
// retain reference to the callback handler.
done_callback_ = std::move(done_callback);
// DesktopMediaPicker interface.
void FakeDesktopMediaPicker::Show(
const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) {
bool show_screens = false;
bool show_windows = false;
bool show_tabs = false;
picker_params_ = params;
for (auto& source_list : source_lists) {
switch (source_list->GetMediaListType()) {
case content::DesktopMediaID::TYPE_NONE:
break;
case content::DesktopMediaID::TYPE_SCREEN:
show_screens = true;
break;
case content::DesktopMediaID::TYPE_WINDOW:
show_windows = true;
break;
case content::DesktopMediaID::TYPE_WEB_CONTENTS:
show_tabs = true;
break;
}
}
private:
void CallCallback(DoneCallback done_callback) {
std::move(done_callback).Run(expectation_->selected_source);
EXPECT_EQ(expectation_->expect_screens, show_screens);
EXPECT_EQ(expectation_->expect_windows, show_windows);
EXPECT_EQ(expectation_->expect_tabs, show_tabs);
EXPECT_EQ(expectation_->expect_audio, params.request_audio);
EXPECT_EQ(params.modality, ui::ModalType::MODAL_TYPE_CHILD);
if (!expectation_->cancelled) {
// Post a task to call the callback asynchronously.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&FakeDesktopMediaPicker::CallCallback,
weak_factory_.GetWeakPtr(), std::move(done_callback)));
} else {
// If we expect the dialog to be cancelled then store the callback to
// retain reference to the callback handler.
done_callback_ = std::move(done_callback);
}
}
FakeDesktopMediaPickerFactory::TestFlags* expectation_;
DoneCallback done_callback_;
base::WeakPtrFactory<FakeDesktopMediaPicker> weak_factory_{this};
DesktopMediaPicker::Params FakeDesktopMediaPicker::GetParams() {
return picker_params_;
}
DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPicker);
};
void FakeDesktopMediaPicker::CallCallback(DoneCallback done_callback) {
std::move(done_callback).Run(expectation_->selected_source);
}
FakeDesktopMediaPickerFactory::FakeDesktopMediaPickerFactory() = default;
......@@ -93,8 +90,8 @@ FakeDesktopMediaPickerFactory::CreatePicker() {
if (current_test_ >= tests_count_)
return std::unique_ptr<DesktopMediaPicker>();
++current_test_;
return std::unique_ptr<DesktopMediaPicker>(
new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1));
picker_ = new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1);
return std::unique_ptr<DesktopMediaPicker>(picker_);
}
std::vector<std::unique_ptr<DesktopMediaList>>
......
......@@ -14,6 +14,8 @@
#include "chrome/browser/media/webrtc/desktop_media_picker_factory.h"
#include "content/public/browser/desktop_media_id.h"
class FakeDesktopMediaPicker;
// Used in tests to supply fake picker.
class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
public:
......@@ -36,13 +38,14 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
// |test_flags| are expected to outlive the factory.
void SetTestFlags(TestFlags* test_flags, int tests_count);
FakeDesktopMediaPicker* picker() const { return picker_; }
// DesktopMediaPickerFactory implementation
std::unique_ptr<DesktopMediaPicker> CreatePicker() override;
std::vector<std::unique_ptr<DesktopMediaList>> CreateMediaList(
const std::vector<content::DesktopMediaID::Type>& types) override;
private:
FakeDesktopMediaPicker* picker_;
TestFlags* test_flags_;
int tests_count_;
int current_test_;
......@@ -50,4 +53,29 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPickerFactory);
};
class FakeDesktopMediaPicker : public DesktopMediaPicker {
public:
explicit FakeDesktopMediaPicker(
FakeDesktopMediaPickerFactory::TestFlags* expectation);
~FakeDesktopMediaPicker() override;
// DesktopMediaPicker interface.
void Show(const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) override;
DesktopMediaPicker::Params GetParams();
private:
void CallCallback(DoneCallback done_callback);
FakeDesktopMediaPickerFactory::TestFlags* expectation_;
DoneCallback done_callback_;
DesktopMediaPicker::Params picker_params_;
base::WeakPtrFactory<FakeDesktopMediaPicker> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPicker);
};
#endif // CHROME_BROWSER_MEDIA_WEBRTC_FAKE_DESKTOP_MEDIA_PICKER_FACTORY_H_
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