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( ...@@ -194,8 +194,8 @@ void DisplayMediaAccessHandler::ProcessQueuedAccessRequest(
gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow(); gfx::NativeWindow parent_window = web_contents->GetTopLevelNativeWindow();
picker_params.context = parent_window; picker_params.context = parent_window;
picker_params.parent = parent_window; picker_params.parent = parent_window;
picker_params.app_name = url_formatter::FormatUrlForSecurityDisplay( picker_params.app_name = url_formatter::FormatOriginForSecurityDisplay(
web_contents->GetLastCommittedURL(), url::Origin::Create(web_contents->GetLastCommittedURL()),
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
picker_params.target_name = picker_params.app_name; picker_params.target_name = picker_params.app_name;
picker_params.request_audio = picker_params.request_audio =
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h" #include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" #include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
...@@ -88,6 +89,10 @@ class DisplayMediaAccessHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -88,6 +89,10 @@ class DisplayMediaAccessHandlerTest : public ChromeRenderViewHostTestHarness {
content::NotificationDetails()); content::NotificationDetails());
} }
DesktopMediaPicker::Params GetParams() {
return picker_factory_->picker()->GetParams();
}
const DisplayMediaAccessHandler::RequestsQueues& GetRequestQueues() { const DisplayMediaAccessHandler::RequestsQueues& GetRequestQueues() {
return access_handler_->pending_requests_; return access_handler_->pending_requests_;
} }
...@@ -193,6 +198,73 @@ TEST_F(DisplayMediaAccessHandlerTest, UpdateMediaRequestStateWithClosing) { ...@@ -193,6 +198,73 @@ TEST_F(DisplayMediaAccessHandlerTest, UpdateMediaRequestStateWithClosing) {
access_handler_.reset(); 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) { TEST_F(DisplayMediaAccessHandlerTest, WebContentsDestroyed) {
FakeDesktopMediaPickerFactory::TestFlags test_flags[] = { FakeDesktopMediaPickerFactory::TestFlags test_flags[] = {
{true /* expect_screens */, true /* expect_windows*/, {true /* expect_screens */, true /* expect_windows*/,
......
...@@ -12,22 +12,24 @@ ...@@ -12,22 +12,24 @@
#include "chrome/browser/media/webrtc/fake_desktop_media_list.h" #include "chrome/browser/media/webrtc/fake_desktop_media_list.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class FakeDesktopMediaPicker : public DesktopMediaPicker { FakeDesktopMediaPicker::FakeDesktopMediaPicker(
public:
explicit FakeDesktopMediaPicker(
FakeDesktopMediaPickerFactory::TestFlags* expectation) FakeDesktopMediaPickerFactory::TestFlags* expectation)
: expectation_(expectation) { : expectation_(expectation) {
expectation_->picker_created = true; expectation_->picker_created = true;
} }
~FakeDesktopMediaPicker() override { expectation_->picker_deleted = true; } FakeDesktopMediaPicker::~FakeDesktopMediaPicker() {
expectation_->picker_deleted = true;
}
// DesktopMediaPicker interface. // DesktopMediaPicker interface.
void Show(const DesktopMediaPicker::Params& params, void FakeDesktopMediaPicker::Show(
const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists, std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) override { DoneCallback done_callback) {
bool show_screens = false; bool show_screens = false;
bool show_windows = false; bool show_windows = false;
bool show_tabs = false; bool show_tabs = false;
picker_params_ = params;
for (auto& source_list : source_lists) { for (auto& source_list : source_lists) {
switch (source_list->GetMediaListType()) { switch (source_list->GetMediaListType()) {
...@@ -61,20 +63,15 @@ class FakeDesktopMediaPicker : public DesktopMediaPicker { ...@@ -61,20 +63,15 @@ class FakeDesktopMediaPicker : public DesktopMediaPicker {
// retain reference to the callback handler. // retain reference to the callback handler.
done_callback_ = std::move(done_callback); done_callback_ = std::move(done_callback);
} }
} }
private:
void CallCallback(DoneCallback done_callback) {
std::move(done_callback).Run(expectation_->selected_source);
}
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; FakeDesktopMediaPickerFactory::FakeDesktopMediaPickerFactory() = default;
...@@ -93,8 +90,8 @@ FakeDesktopMediaPickerFactory::CreatePicker() { ...@@ -93,8 +90,8 @@ FakeDesktopMediaPickerFactory::CreatePicker() {
if (current_test_ >= tests_count_) if (current_test_ >= tests_count_)
return std::unique_ptr<DesktopMediaPicker>(); return std::unique_ptr<DesktopMediaPicker>();
++current_test_; ++current_test_;
return std::unique_ptr<DesktopMediaPicker>( picker_ = new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1);
new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1)); return std::unique_ptr<DesktopMediaPicker>(picker_);
} }
std::vector<std::unique_ptr<DesktopMediaList>> std::vector<std::unique_ptr<DesktopMediaList>>
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "chrome/browser/media/webrtc/desktop_media_picker_factory.h" #include "chrome/browser/media/webrtc/desktop_media_picker_factory.h"
#include "content/public/browser/desktop_media_id.h" #include "content/public/browser/desktop_media_id.h"
class FakeDesktopMediaPicker;
// Used in tests to supply fake picker. // Used in tests to supply fake picker.
class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory { class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
public: public:
...@@ -36,13 +38,14 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory { ...@@ -36,13 +38,14 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
// |test_flags| are expected to outlive the factory. // |test_flags| are expected to outlive the factory.
void SetTestFlags(TestFlags* test_flags, int tests_count); void SetTestFlags(TestFlags* test_flags, int tests_count);
FakeDesktopMediaPicker* picker() const { return picker_; }
// DesktopMediaPickerFactory implementation // DesktopMediaPickerFactory implementation
std::unique_ptr<DesktopMediaPicker> CreatePicker() override; std::unique_ptr<DesktopMediaPicker> CreatePicker() override;
std::vector<std::unique_ptr<DesktopMediaList>> CreateMediaList( std::vector<std::unique_ptr<DesktopMediaList>> CreateMediaList(
const std::vector<content::DesktopMediaID::Type>& types) override; const std::vector<content::DesktopMediaID::Type>& types) override;
private: private:
FakeDesktopMediaPicker* picker_;
TestFlags* test_flags_; TestFlags* test_flags_;
int tests_count_; int tests_count_;
int current_test_; int current_test_;
...@@ -50,4 +53,29 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory { ...@@ -50,4 +53,29 @@ class FakeDesktopMediaPickerFactory : public DesktopMediaPickerFactory {
DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPickerFactory); 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_ #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