Commit 479d85b5 authored by David Jacobo's avatar David Jacobo Committed by Commit Bot

Fix nits in ArcExternalProtocolDialog

Fixing nits to improve readibility, also removing unnecessary TODO.

Bug: None
Tets: Build, tests still valid as funcionality remain the same.
Change-Id: Ia0be3efa9ba6e064a520b37ab27552e3af063a03
Reviewed-on: https://chromium-review.googlesource.com/1013287
Commit-Queue: David Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551486}
parent fd7f88c2
...@@ -86,7 +86,8 @@ mojom::IntentInfoPtr CreateIntentInfo(const GURL& url, bool ui_bypassed) { ...@@ -86,7 +86,8 @@ mojom::IntentInfoPtr CreateIntentInfo(const GURL& url, bool ui_bypassed) {
// Create an intent with action VIEW, the |url| we are redirecting the user to // Create an intent with action VIEW, the |url| we are redirecting the user to
// and a flag that tells whether or not the user interacted with the picker UI // and a flag that tells whether or not the user interacted with the picker UI
arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New(); arc::mojom::IntentInfoPtr intent = arc::mojom::IntentInfo::New();
intent->action = "org.chromium.arc.intent.action.VIEW"; constexpr char kArcIntentActionView[] = "org.chromium.arc.intent.action.VIEW";
intent->action = kArcIntentActionView;
intent->data = url.spec(); intent->data = url.spec();
intent->ui_bypassed = ui_bypassed; intent->ui_bypassed = ui_bypassed;
...@@ -96,8 +97,7 @@ mojom::IntentInfoPtr CreateIntentInfo(const GURL& url, bool ui_bypassed) { ...@@ -96,8 +97,7 @@ mojom::IntentInfoPtr CreateIntentInfo(const GURL& url, bool ui_bypassed) {
// Sends |url| to ARC. // Sends |url| to ARC.
void HandleUrlInArc(int render_process_host_id, void HandleUrlInArc(int render_process_host_id,
int routing_id, int routing_id,
const std::pair<GURL, ArcIntentHelperBridge::ActivityName>& const GurlAndActivityInfo& url_and_activity,
url_and_activity,
bool ui_bypassed) { bool ui_bypassed) {
auto* arc_service_manager = ArcServiceManager::Get(); auto* arc_service_manager = ArcServiceManager::Get();
if (!arc_service_manager) if (!arc_service_manager)
...@@ -124,11 +124,10 @@ void HandleUrlInArc(int render_process_host_id, ...@@ -124,11 +124,10 @@ void HandleUrlInArc(int render_process_host_id,
GetActionResult GetActionInternal( GetActionResult GetActionInternal(
const GURL& original_url, const GURL& original_url,
const mojom::IntentHandlerInfoPtr& handler, const mojom::IntentHandlerInfoPtr& handler,
std::pair<GURL, ArcIntentHelperBridge::ActivityName>* GurlAndActivityInfo* out_url_and_activity_name) {
out_url_and_activity_name) {
if (handler->fallback_url.has_value()) { if (handler->fallback_url.has_value()) {
*out_url_and_activity_name = *out_url_and_activity_name =
std::make_pair(GURL(*handler->fallback_url), GurlAndActivityInfo(GURL(*handler->fallback_url),
ArcIntentHelperBridge::ActivityName( ArcIntentHelperBridge::ActivityName(
handler->package_name, handler->activity_name)); handler->package_name, handler->activity_name));
if (ArcIntentHelperBridge::IsIntentHelperPackage(handler->package_name)) { if (ArcIntentHelperBridge::IsIntentHelperPackage(handler->package_name)) {
...@@ -147,7 +146,7 @@ GetActionResult GetActionInternal( ...@@ -147,7 +146,7 @@ GetActionResult GetActionInternal(
// Unlike |handler->fallback_url|, the |original_url| should always be handled // Unlike |handler->fallback_url|, the |original_url| should always be handled
// in ARC since it's external to Chrome. // in ARC since it's external to Chrome.
*out_url_and_activity_name = std::make_pair( *out_url_and_activity_name = GurlAndActivityInfo(
original_url, ArcIntentHelperBridge::ActivityName( original_url, ArcIntentHelperBridge::ActivityName(
handler->package_name, handler->activity_name)); handler->package_name, handler->activity_name));
return GetActionResult::HANDLE_URL_IN_ARC; return GetActionResult::HANDLE_URL_IN_ARC;
...@@ -169,8 +168,7 @@ GetActionResult GetAction( ...@@ -169,8 +168,7 @@ GetActionResult GetAction(
const GURL& original_url, const GURL& original_url,
const std::vector<mojom::IntentHandlerInfoPtr>& handlers, const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
size_t selected_app_index, size_t selected_app_index,
std::pair<GURL, ArcIntentHelperBridge::ActivityName>* GurlAndActivityInfo* out_url_and_activity_name,
out_url_and_activity_name,
bool* in_out_safe_to_bypass_ui) { bool* in_out_safe_to_bypass_ui) {
DCHECK(out_url_and_activity_name); DCHECK(out_url_and_activity_name);
if (!handlers.size()) { if (!handlers.size()) {
...@@ -254,7 +252,7 @@ bool HandleUrl(int render_process_host_id, ...@@ -254,7 +252,7 @@ bool HandleUrl(int render_process_host_id,
const std::vector<mojom::IntentHandlerInfoPtr>& handlers, const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
size_t selected_app_index, size_t selected_app_index,
GetActionResult* out_result) { GetActionResult* out_result) {
auto url_and_activity_name = std::make_pair( GurlAndActivityInfo url_and_activity_name(
GURL(), GURL(),
ArcIntentHelperBridge::ActivityName{"" /* package */, "" /* activity */}); ArcIntentHelperBridge::ActivityName{"" /* package */, "" /* activity */});
...@@ -297,9 +295,10 @@ GURL GetUrlToNavigateOnDeactivate( ...@@ -297,9 +295,10 @@ GURL GetUrlToNavigateOnDeactivate(
const std::vector<mojom::IntentHandlerInfoPtr>& handlers) { const std::vector<mojom::IntentHandlerInfoPtr>& handlers) {
const GURL empty_url; const GURL empty_url;
for (size_t i = 0; i < handlers.size(); ++i) { for (size_t i = 0; i < handlers.size(); ++i) {
auto url_and_package = GurlAndActivityInfo url_and_package(
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{ GURL(),
"" /* package */, "" /* activity */}); ArcIntentHelperBridge::ActivityName{/*package=*/std::string(),
/*activity=*/std::string()});
if (GetActionInternal(empty_url, handlers[i], &url_and_package) == if (GetActionInternal(empty_url, handlers[i], &url_and_package) ==
GetActionResult::OPEN_URL_IN_CHROME) { GetActionResult::OPEN_URL_IN_CHROME) {
DCHECK(url_and_package.first.SchemeIsHTTPOrHTTPS()); DCHECK(url_and_package.first.SchemeIsHTTPOrHTTPS());
...@@ -537,8 +536,7 @@ GetActionResult GetActionForTesting( ...@@ -537,8 +536,7 @@ GetActionResult GetActionForTesting(
const GURL& original_url, const GURL& original_url,
const std::vector<mojom::IntentHandlerInfoPtr>& handlers, const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
size_t selected_app_index, size_t selected_app_index,
std::pair<GURL, ArcIntentHelperBridge::ActivityName>* GurlAndActivityInfo* out_url_and_activity_name,
out_url_and_activity_name,
bool* safe_to_bypass_ui) { bool* safe_to_bypass_ui) {
return GetAction(original_url, handlers, selected_app_index, return GetAction(original_url, handlers, selected_app_index,
out_url_and_activity_name, safe_to_bypass_ui); out_url_and_activity_name, safe_to_bypass_ui);
......
...@@ -36,6 +36,9 @@ class ArcWebContentsData ...@@ -36,6 +36,9 @@ class ArcWebContentsData
DISALLOW_COPY_AND_ASSIGN(ArcWebContentsData); DISALLOW_COPY_AND_ASSIGN(ArcWebContentsData);
}; };
using GurlAndActivityInfo =
std::pair<GURL, ArcIntentHelperBridge::ActivityName>;
// An enum returned from GetAction function. This is visible for testing. // An enum returned from GetAction function. This is visible for testing.
enum class GetActionResult { enum class GetActionResult {
// ARC cannot handle the |original_url|, and the URL does not have a fallback // ARC cannot handle the |original_url|, and the URL does not have a fallback
...@@ -67,8 +70,7 @@ GetActionResult GetActionForTesting( ...@@ -67,8 +70,7 @@ GetActionResult GetActionForTesting(
const GURL& original_url, const GURL& original_url,
const std::vector<mojom::IntentHandlerInfoPtr>& handlers, const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
size_t selected_app_index, size_t selected_app_index,
std::pair<GURL, ArcIntentHelperBridge::ActivityName>* GurlAndActivityInfo* out_url_and_activity_name,
out_url_and_activity_name,
bool* safe_to_bypass_ui); bool* safe_to_bypass_ui);
GURL GetUrlToNavigateOnDeactivateForTesting( GURL GetUrlToNavigateOnDeactivateForTesting(
......
...@@ -46,6 +46,13 @@ class ArcExternalProtocolDialogTestUtils : public BrowserWithTestWindowTest { ...@@ -46,6 +46,13 @@ class ArcExternalProtocolDialogTestUtils : public BrowserWithTestWindowTest {
const char* kChromePackageName = const char* kChromePackageName =
ArcIntentHelperBridge::kArcIntentHelperPackageName; ArcIntentHelperBridge::kArcIntentHelperPackageName;
// Creates a dummy GurlAndActivityInfo object.
GurlAndActivityInfo CreateEmptyGurlAndActivityInfo() {
return std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName(
/*package_name=*/std::string(),
/*activity_name=*/std::string()));
}
// Creates and returns a new IntentHandlerInfo object. // Creates and returns a new IntentHandlerInfo object.
mojom::IntentHandlerInfoPtr Create(const std::string& name, mojom::IntentHandlerInfoPtr Create(const std::string& name,
const std::string& package_name, const std::string& package_name,
...@@ -62,26 +69,13 @@ mojom::IntentHandlerInfoPtr Create(const std::string& name, ...@@ -62,26 +69,13 @@ mojom::IntentHandlerInfoPtr Create(const std::string& name,
return ptr; return ptr;
} }
// Some tests don't need to specify an activity.
mojom::IntentHandlerInfoPtr Create(const std::string& name,
const std::string& package_name,
bool is_preferred,
const GURL& fallback_url) {
return Create(name, package_name, "" /* activity_name */, is_preferred,
fallback_url);
}
} // namespace } // namespace
// Tests that when no apps are returned from ARC, GetAction returns // Tests that when no apps are returned from ARC, GetAction returns
// SHOW_CHROME_OS_DIALOG. // SHOW_CHROME_OS_DIALOG.
TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) { TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
// TODO(djacobo): Rewrite this using the specific type and simplify the GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
// initialization.
auto url_and_activity_name =
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// Marking this as safe to bypass or not makes no difference since there are // Marking this as safe to bypass or not makes no difference since there are
// no handlers. // no handlers.
...@@ -106,14 +100,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) { ...@@ -106,14 +100,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithNoApp) {
TEST(ArcExternalProtocolDialogTest, TEST(ArcExternalProtocolDialogTest,
TestGetActionWithOneAppBypassesIntentPicker) { TestGetActionWithOneAppBypassesIntentPicker) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
// TODO(djacobo): Specify the name of the third parameter in all cases. handlers.push_back(Create("package", "com.google.package.name",
handlers.push_back( /*activity_name=*/std::string(),
Create("package", "com.google.package.name", false, GURL())); /*is_preferred=*/false, /*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -128,13 +120,12 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -128,13 +120,12 @@ TEST(ArcExternalProtocolDialogTest,
TEST(ArcExternalProtocolDialogTest, TEST(ArcExternalProtocolDialogTest,
TestGetActionWithOneAppDoesntBypassIntentPicker) { TestGetActionWithOneAppDoesntBypassIntentPicker) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("package", "com.google.package.name",
Create("package", "com.google.package.name", false, GURL())); /*activity_name=*/std::string(),
/*is_preferred=*/false, /*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::ASK_USER, GetActionResult::ASK_USER,
...@@ -149,15 +140,15 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -149,15 +140,15 @@ TEST(ArcExternalProtocolDialogTest,
TEST(ArcExternalProtocolDialogTest, TEST(ArcExternalProtocolDialogTest,
TestGetActionWithTwoAppWontBypassIntentPicker) { TestGetActionWithTwoAppWontBypassIntentPicker) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("package", "com.google.package.name",
Create("package", "com.google.package.name", false, GURL())); /*activity_name=*/std::string(),
handlers.push_back( /*is_preferred=*/false, /*fallback_url=*/GURL()));
Create("package2", "com.google.package.name2", false, GURL())); handlers.push_back(Create("package2", "com.google.package.name2",
/*activity_name=*/std::string(),
/*is_preferred=*/false, /*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::ASK_USER, GetActionResult::ASK_USER,
...@@ -182,13 +173,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredApp) { ...@@ -182,13 +173,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredApp) {
const std::string activity_name("com.google.activity"); const std::string activity_name("com.google.activity");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("package", package_name, activity_name,
Create("package", package_name, activity_name, true, GURL())); /*is_preferred=*/true,
/*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
...@@ -221,13 +211,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneAppSelected) { ...@@ -221,13 +211,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneAppSelected) {
const std::string activity_name("fake_activity_name"); const std::string activity_name("fake_activity_name");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("package", package_name, activity_name,
Create("package", package_name, activity_name, false, GURL())); /*is_preferred=*/false,
/*fallback_url=*/GURL()));
constexpr size_t kSelection = 0; constexpr size_t kSelection = 0;
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -254,18 +243,18 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -254,18 +243,18 @@ TEST(ArcExternalProtocolDialogTest,
TestGetActionWithOnePreferredAppAndOneOther) { TestGetActionWithOnePreferredAppAndOneOther) {
const GURL external_url("external-protocol:foo"); const GURL external_url("external-protocol:foo");
const std::string package_name("com.google.package2.name"); const std::string package_name("com.google.package2.name");
const std::string activity_name("fake_package_name2"); const std::string activity_name("fake_activity_name2");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("package", "com.google.package.name", handlers.push_back(Create("package", "com.google.package.name",
"fake_package_name_1", false, GURL())); "fake_activity_name",
handlers.push_back( /*is_preferred=*/false, /*fallback_url=*/GURL()));
Create("package2", package_name, activity_name, true, GURL())); handlers.push_back(Create("package2", package_name, activity_name,
/*is_preferred=*/true,
/*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// For cases with 2+ apps it doesn't matter whether it was marked as safe to // For cases with 2+ apps it doesn't matter whether it was marked as safe to
// bypass or not, it will only check for user's preferrences. // bypass or not, it will only check for user's preferrences.
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
...@@ -303,13 +292,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrl) { ...@@ -303,13 +292,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrl) {
const std::string activity_name("chrome_activity_name"); const std::string activity_name("chrome_activity_name");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("Chrome", kChromePackageName, activity_name,
Create("Chrome", kChromePackageName, activity_name, true, GURL())); /*is_preferred=*/true,
/*fallback_url=*/GURL()));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -333,13 +321,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneFallbackUrl) { ...@@ -333,13 +321,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneFallbackUrl) {
const std::string activity_name("fake_activity_name"); const std::string activity_name("fake_activity_name");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("Chrome", kChromePackageName, activity_name,
Create("Chrome", kChromePackageName, activity_name, false, fallback_url)); /*is_preferred=*/false, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// Since the navigation is intended to stay in Chrome the UI is bypassed. // Since the navigation is intended to stay in Chrome the UI is bypassed.
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
...@@ -372,13 +358,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredFallbackUrl) { ...@@ -372,13 +358,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOnePreferredFallbackUrl) {
const std::string activity_name("fake_activity_name"); const std::string activity_name("fake_activity_name");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("Chrome", kChromePackageName, activity_name,
Create("Chrome", kChromePackageName, activity_name, true, fallback_url)); /*is_preferred=*/true, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// Safe to bypass should be marked as true in the end, since the // Safe to bypass should be marked as true in the end, since the
// OPEN_URL_IN_CHROME actually bypasses the UI, regardless of the flag. // OPEN_URL_IN_CHROME actually bypasses the UI, regardless of the flag.
...@@ -414,17 +398,15 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoFallbackUrls) { ...@@ -414,17 +398,15 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoFallbackUrls) {
const GURL fallback_url("http://zxing.org"); const GURL fallback_url("http://zxing.org");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other browser", "com.other.browser", "activity_1", handlers.push_back(Create("Other browser", "com.other.browser",
false, fallback_url)); /*activity_name=*/std::string(),
handlers.push_back( /*is_preferred=*/false, fallback_url));
Create("Chrome", kChromePackageName, "activity_2", false, fallback_url)); handlers.push_back(Create("Chrome", kChromePackageName,
/*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// TODO(djacobo): 2+ apps outcome is not modified by safe_to_bypass_ui flag,
// reconsider to add some basic testing anyways.
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::ASK_USER, GetActionResult::ASK_USER,
...@@ -445,14 +427,13 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -445,14 +427,13 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other browser", "com.other.browser", handlers.push_back(Create("Other browser", "com.other.browser",
"fake_activity_1", false, fallback_url)); "fake_activity",
handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity, true, /*is_preferred=*/false, fallback_url));
fallback_url)); handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity,
/*is_preferred=*/true, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::OPEN_URL_IN_CHROME, GetActionResult::OPEN_URL_IN_CHROME,
...@@ -479,14 +460,12 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -479,14 +460,12 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other browser", package_name, other_activity_name, handlers.push_back(Create("Other browser", package_name, other_activity_name,
true, fallback_url)); /*is_preferred=*/true, fallback_url));
handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity_name, handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity_name,
false, fallback_url)); /*is_preferred=*/false, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -509,14 +488,13 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -509,14 +488,13 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other browser", "com.other.browser", handlers.push_back(Create("Other browser", "com.other.browser",
"fake_activity", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity_name, handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity_name,
false, fallback_url)); /*is_preferred=*/false, fallback_url));
constexpr size_t kSelection = 1; // Chrome constexpr size_t kSelection = 1; // Chrome
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::OPEN_URL_IN_CHROME, GetActionResult::OPEN_URL_IN_CHROME,
...@@ -540,14 +518,12 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -540,14 +518,12 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other browser", package_name, other_activity_name, handlers.push_back(Create("Other browser", package_name, other_activity_name,
false, fallback_url)); /*is_preferred=*/false, fallback_url));
handlers.push_back(Create("Chrome", kChromePackageName, handlers.push_back(Create("Chrome", kChromePackageName, "chrome_activity",
"chrome_activity_name", false, fallback_url)); /*is_preferred=*/false, fallback_url));
constexpr size_t kSelection = 0; // the other browser constexpr size_t kSelection = 0; // the other browser
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// Already selected app index, output should be corrected to false. // Already selected app index, output should be corrected to false.
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
...@@ -570,12 +546,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneMarketFallbackUrl) { ...@@ -570,12 +546,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithOneMarketFallbackUrl) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Play Store", "com.google.play.store", handlers.push_back(Create("Play Store", "com.google.play.store",
"play_store_activty", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = std::make_pair( GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
GURL(), ArcIntentHelperBridge::ActivityName{"" /* package_name */,
"" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -602,12 +577,11 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -602,12 +577,11 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Play Store", play_store_package_name, handlers.push_back(Create("Play Store", play_store_package_name,
play_store_activity, true, fallback_url)); play_store_activity,
/*is_preferred=*/true, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = std::make_pair( GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
GURL(), ArcIntentHelperBridge::ActivityName{"" /* package_name */,
"" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -640,12 +614,11 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -640,12 +614,11 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Play Store", play_store_package_name, handlers.push_back(Create("Play Store", play_store_package_name,
play_store_activity, false, fallback_url)); play_store_activity,
/*is_preferred=*/false, fallback_url));
constexpr size_t kSelection = 0; constexpr size_t kSelection = 0;
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// App already selected, it doesn't really makes sense to call GetAction with // App already selected, it doesn't really makes sense to call GetAction with
// |in_out_safe_to_bypass_ui| set to true here. // |in_out_safe_to_bypass_ui| set to true here.
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
...@@ -669,12 +642,11 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -669,12 +642,11 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Play Store", "com.google.play.store", handlers.push_back(Create("Play Store", "com.google.play.store",
"play_store_activity", false, fallback_url)); "play_store_activity", /*is_preferred=*/false,
fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = true; bool in_out_safe_to_bypass_ui = true;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -693,14 +665,14 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoMarketFallbackUrls) { ...@@ -693,14 +665,14 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithTwoMarketFallbackUrls) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Play Store", "com.google.play.store", handlers.push_back(Create("Play Store", "com.google.play.store",
"play.store.act1", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
handlers.push_back(Create("Other Store app", "com.other.play.store", handlers.push_back(Create("Other Store app", "com.other.play.store",
"otherplay.store.act2", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::ASK_USER, GetActionResult::ASK_USER,
...@@ -720,14 +692,14 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -720,14 +692,14 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other Store app", "com.other.play.store", handlers.push_back(Create("Other Store app", "com.other.play.store",
"fake.play.store.act", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
handlers.push_back(Create("Play Store", play_store_package_name, handlers.push_back(Create("Play Store", play_store_package_name,
play_store_activity, true, fallback_url)); play_store_activity,
/*is_preferred=*/true, fallback_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
GetActionResult::HANDLE_URL_IN_ARC, GetActionResult::HANDLE_URL_IN_ARC,
...@@ -750,14 +722,14 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -750,14 +722,14 @@ TEST(ArcExternalProtocolDialogTest,
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Other Store app", "com.other.play.store", handlers.push_back(Create("Other Store app", "com.other.play.store",
"other.play.store.act", false, fallback_url)); /*activity_name=*/std::string(),
/*is_preferred=*/false, fallback_url));
handlers.push_back(Create("Play Store", play_store_package_name, handlers.push_back(Create("Play Store", play_store_package_name,
play_store_activity, false, fallback_url)); play_store_activity,
/*is_preferred=*/false, fallback_url));
const size_t kSelection = 1; // Play Store const size_t kSelection = 1; // Play Store
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
// After selection doesn't really makes sense to check this value. // After selection doesn't really makes sense to check this value.
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
EXPECT_EQ( EXPECT_EQ(
...@@ -781,13 +753,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrlAsFallback) { ...@@ -781,13 +753,11 @@ TEST(ArcExternalProtocolDialogTest, TestGetActionWithGeoUrlAsFallback) {
const std::string chrome_activity("chrome.activity"); const std::string chrome_activity("chrome.activity");
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back( handlers.push_back(Create("Chrome", kChromePackageName, chrome_activity,
Create("Chrome", kChromePackageName, chrome_activity, true, geo_url)); /*is_preferred=*/true, geo_url));
const size_t no_selection = handlers.size(); const size_t no_selection = handlers.size();
auto url_and_activity_name = GurlAndActivityInfo url_and_activity_name = CreateEmptyGurlAndActivityInfo();
std::make_pair(GURL(), ArcIntentHelperBridge::ActivityName{
"" /* package_name*/, "" /* activity_name */});
bool in_out_safe_to_bypass_ui = false; bool in_out_safe_to_bypass_ui = false;
// GetAction shouldn't return OPEN_URL_IN_CHROME because Chrome doesn't // GetAction shouldn't return OPEN_URL_IN_CHROME because Chrome doesn't
// directly support geo:. // directly support geo:.
...@@ -814,8 +784,9 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppOnly) { ...@@ -814,8 +784,9 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppOnly) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
// On production, when |handlers| only contains app(s), the fallback field is // On production, when |handlers| only contains app(s), the fallback field is
// empty, but to make the test more reliable, use non-empty fallback URL. // empty, but to make the test more reliable, use non-empty fallback URL.
handlers.push_back( handlers.push_back(Create("App", "app.package",
Create("App", "app.package", "app.activity", false, GURL("http://www"))); /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("http://www")));
EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers)); EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers));
} }
...@@ -825,10 +796,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppsOnly) { ...@@ -825,10 +796,12 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppsOnly) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
// On production, when |handlers| only contains app(s), the fallback field is // On production, when |handlers| only contains app(s), the fallback field is
// empty, but to make the test more reliable, use non-empty fallback URL. // empty, but to make the test more reliable, use non-empty fallback URL.
handlers.push_back(Create("App1", "app1.package", "app1.activity", false, handlers.push_back(Create("App1", "app1.package",
GURL("http://www"))); /*activity_name=*/std::string(),
handlers.push_back(Create("App2", "app2.package", "app2.activity", false, /*is_preferred=*/false, GURL("http://www")));
GURL("http://www"))); handlers.push_back(Create("App2", "app2.package",
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("http://www")));
EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers)); EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers));
} }
...@@ -836,8 +809,9 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppsOnly) { ...@@ -836,8 +809,9 @@ TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateAppsOnly) {
// contains Chrome, but it's not for http(s). // contains Chrome, but it's not for http(s).
TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateGeoUrl) { TEST(ArcExternalProtocolDialogTest, TestGetUrlToNavigateOnDeactivateGeoUrl) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("Chrome", kChromePackageName, "chrome.act1", false, handlers.push_back(
GURL("geo:37.4220,-122.0840"))); Create("Chrome", kChromePackageName, /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("geo:37.4220,-122.0840")));
EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers)); EXPECT_EQ(GURL(), GetUrlToNavigateOnDeactivateForTesting(handlers));
} }
...@@ -849,12 +823,15 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -849,12 +823,15 @@ TEST(ArcExternalProtocolDialogTest,
// On production, all handlers have the same fallback URL, but to make sure // On production, all handlers have the same fallback URL, but to make sure
// that "Chrome" is actually selected by the function, use different URLs. // that "Chrome" is actually selected by the function, use different URLs.
handlers.push_back(Create("A browser app", "browser.app.package", handlers.push_back(Create("A browser app", "browser.app.package",
"browser.app.act", false, GURL("http://www1/"))); /*activity_name=*/std::string(),
handlers.push_back( /*is_preferred=*/false, GURL("http://www1/")));
Create("Chrome", kChromePackageName, false, GURL("http://www2/"))); handlers.push_back(Create("Chrome", kChromePackageName,
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("http://www2/")));
handlers.push_back(Create("Yet another browser app", handlers.push_back(Create("Yet another browser app",
"yet.another.browser.app.package", "yet.another.browser.app.package",
"other.browser.act", false, GURL("http://www3/"))); /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("http://www3/")));
EXPECT_EQ(GURL("http://www2/"), EXPECT_EQ(GURL("http://www2/"),
GetUrlToNavigateOnDeactivateForTesting(handlers)); GetUrlToNavigateOnDeactivateForTesting(handlers));
...@@ -865,12 +842,15 @@ TEST(ArcExternalProtocolDialogTest, ...@@ -865,12 +842,15 @@ TEST(ArcExternalProtocolDialogTest,
TestGetUrlToNavigateOnDeactivateChromeAndAppHttps) { TestGetUrlToNavigateOnDeactivateChromeAndAppHttps) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("A browser app", "browser.app.package", handlers.push_back(Create("A browser app", "browser.app.package",
"browser.act", false, GURL("https://www1/"))); /*activity_name=*/std::string(),
handlers.push_back( /*is_preferred=*/false, GURL("https://www1/")));
Create("Chrome", kChromePackageName, false, GURL("https://www2/"))); handlers.push_back(Create("Chrome", kChromePackageName,
handlers.push_back( /*activity_name=*/std::string(),
Create("Yet another browser app", "yet.another.browser.app.package", /*is_preferred=*/false, GURL("https://www2/")));
"another.browser.act", false, GURL("https://www3/"))); handlers.push_back(Create("Yet another browser app",
"yet.another.browser.app.package",
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www3/")));
EXPECT_EQ(GURL("https://www2/"), EXPECT_EQ(GURL("https://www2/"),
GetUrlToNavigateOnDeactivateForTesting(handlers)); GetUrlToNavigateOnDeactivateForTesting(handlers));
...@@ -895,40 +875,52 @@ TEST_F(ArcExternalProtocolDialogTestUtils, TestTabIsNotStartedFromArc) { ...@@ -895,40 +875,52 @@ TEST_F(ArcExternalProtocolDialogTestUtils, TestTabIsNotStartedFromArc) {
TEST(ArcExternalProtocolDialogTest, TestIsChromeAnAppCandidate) { TEST(ArcExternalProtocolDialogTest, TestIsChromeAnAppCandidate) {
// First 3 cases are valid, just switching the position of Chrome. // First 3 cases are valid, just switching the position of Chrome.
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
handlers.push_back(Create("fake app 1", "fake.app.package1", false,
GURL("https://www.fo.com")));
handlers.push_back(Create("fake app 2", "fake_app_pkg_2", false,
GURL("https://www.bar.com")));
handlers.push_back( handlers.push_back(
Create("Chrome", kChromePackageName, false, GURL("https://www/"))); Create("fake app 1", "fake.app.package", /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www.fo.com")));
handlers.push_back(
Create("fake app 2", "fake.app.package2", /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www.bar.com")));
handlers.push_back(Create("Chrome", kChromePackageName,
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www/")));
EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers)); EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers));
std::vector<mojom::IntentHandlerInfoPtr> handlers2; std::vector<mojom::IntentHandlerInfoPtr> handlers2;
handlers2.push_back(Create("fake app 1", "fake.app.package", false,
GURL("https://www.fo.com")));
handlers2.push_back( handlers2.push_back(
Create("Chrome", kChromePackageName, false, GURL("https://www/"))); Create("fake app 1", "fake.app.package", /*activity_name=*/std::string(),
handlers2.push_back(Create("fake app 2", "fake.app.package2", false, /*is_preferred=*/false, GURL("https://www.fo.com")));
GURL("https://www.bar.com"))); handlers2.push_back(Create("Chrome", kChromePackageName,
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www/")));
handlers2.push_back(
Create("fake app 2", "fake.app.package2", /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www.bar.com")));
EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers2)); EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers2));
std::vector<mojom::IntentHandlerInfoPtr> handlers3; std::vector<mojom::IntentHandlerInfoPtr> handlers3;
handlers3.push_back(Create("Chrome", kChromePackageName,
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www/")));
handlers3.push_back( handlers3.push_back(
Create("Chrome", kChromePackageName, false, GURL("https://www/"))); Create("fake app 1", "fake.app.package", /*activity_name=*/std::string(),
handlers3.push_back(Create("fake app 1", "fake.app.package", false, /*is_preferred=*/false, GURL("https://www.fo.com")));
GURL("https://www.fo.com"))); handlers3.push_back(
handlers3.push_back(Create("fake app 2", "fake.app.package2", false, Create("fake app 2", "fake.app.package2", /*activity_name=*/std::string(),
GURL("https://www.bar.com"))); /*is_preferred=*/false, GURL("https://www.bar.com")));
EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers3)); EXPECT_TRUE(IsChromeAnAppCandidateForTesting(handlers3));
// Only non-Chrome apps. // Only non-Chrome apps.
std::vector<mojom::IntentHandlerInfoPtr> handlers4; std::vector<mojom::IntentHandlerInfoPtr> handlers4;
handlers4.push_back(Create("fake app 1", "fake.app.package", false,
GURL("https://www.fo.com")));
handlers4.push_back(Create("fake app 2", "fake.app.package2", false,
GURL("https://www.bar.com")));
handlers4.push_back( handlers4.push_back(
Create("fake app 3", "fake.app.package3", false, GURL("https://www/"))); Create("fake app 1", "fake.app.package", /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www.fo.com")));
handlers4.push_back(
Create("fake app 2", "fake.app.package2", /*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www.bar.com")));
handlers4.push_back(Create("fake app 3", "fake.app.package3",
/*activity_name=*/std::string(),
/*is_preferred=*/false, GURL("https://www/")));
EXPECT_FALSE(IsChromeAnAppCandidateForTesting(handlers4)); EXPECT_FALSE(IsChromeAnAppCandidateForTesting(handlers4));
// Empty vector case. // Empty vector case.
......
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