forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SH-Clank] Add basic Link to text feature
Add basic Link to text feature without link generation request. This CL also adds a new version of Sharing hub with a message. Success case: https://screenshot.googleplex.com/2KiLEciz0uS.png Failure case: https://screenshot.googleplex.com/jQgcyd6kpjg.png Bug: 1102382 Change-Id: I3508169170d657c0538bb6b450e7e33a93191fa0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309003 Commit-Queue: Gayane Petrosyan <gayane@chromium.org> Reviewed-by: Lijin Shen <lazzzis@google.com> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Kyle Milka <kmilka@chromium.org> Cr-Commit-Position: refs/heads/master@{#792875}
- Loading branch information
Gayane Petrosyan
authored and
Commit Bot
committed
Jul 29, 2020
1 parent
5deced7
commit 4562d5e
Showing
13 changed files
with
220 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ndroid/java/src/org/chromium/chrome/browser/share/link_to_text/LinkToTextCoordinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.share.link_to_text; | ||
|
||
import android.content.Context; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.share.ChromeShareExtras; | ||
import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback; | ||
import org.chromium.components.browser_ui.share.ShareParams; | ||
import org.chromium.ui.base.WindowAndroid; | ||
|
||
/** | ||
* Handles the Link To Text action in the Sharing Hub. | ||
*/ | ||
public class LinkToTextCoordinator { | ||
private static final String SHARE_TEXT_TEMPLATE = "\"%s\"\n%s"; | ||
private static final String URL_TEMPLATE = "%s:~:text=%s"; | ||
private final Context mContext; | ||
private final WindowAndroid mWindow; | ||
private final ChromeOptionShareCallback mChromeOptionShareCallback; | ||
private final String mVisibleUrl; | ||
private final String mSelectedText; | ||
|
||
public LinkToTextCoordinator(Context context, WindowAndroid window, | ||
ChromeOptionShareCallback chromeOptionShareCallback, String visibleUrl, | ||
String selectedText) { | ||
mContext = context; | ||
mWindow = window; | ||
mChromeOptionShareCallback = chromeOptionShareCallback; | ||
mVisibleUrl = visibleUrl; | ||
mSelectedText = selectedText; | ||
|
||
// TODO(1102382): Replace following line with a request to create text fragment selector and | ||
// pass |OnSelectorReady| as callback. | ||
onSelectorReady(""); | ||
} | ||
|
||
public void onSelectorReady(String selector) { | ||
String successMessage = | ||
mContext.getResources().getString(R.string.link_to_text_success_message); | ||
String failureMessage = | ||
mContext.getResources().getString(R.string.link_to_text_failure_message); | ||
|
||
// TODO(1102382): Consider creating SharedParams on sharesheet side. In that case there will | ||
// be no need to keep the WindowAndroid in this class. | ||
String textToShare = getTextToShare(selector); | ||
ShareParams params = new ShareParams.Builder(mWindow, /*title=*/"", /*url=*/"") | ||
.setText(textToShare) | ||
.build(); | ||
|
||
ChromeShareExtras chromeShareExtras = new ChromeShareExtras.Builder().build(); | ||
mChromeOptionShareCallback.showThirdPartyShareSheetWithMessage( | ||
!selector.isEmpty() ? successMessage : failureMessage, params, chromeShareExtras, | ||
System.currentTimeMillis()); | ||
} | ||
|
||
public String getTextToShare(String selector) { | ||
// TODO(1102382): visbileUrl might need a cleanup. For example, if already has text fragment | ||
// selector. | ||
String url = mVisibleUrl; | ||
if (!selector.isEmpty()) url = String.format(URL_TEMPLATE, mVisibleUrl, selector); | ||
|
||
return String.format(SHARE_TEXT_TEMPLATE, mSelectedText, url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...vatests/src/org/chromium/chrome/browser/share/link_to_text/LinkToTextCoordinatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.share.link_to_text; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import android.content.Context; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
import androidx.test.filters.SmallTest; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback; | ||
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | ||
import org.chromium.ui.base.WindowAndroid; | ||
import org.chromium.ui.test.util.DummyUiActivity; | ||
|
||
/** | ||
* Tests for {@link LinkToTextCoordinator}. | ||
*/ | ||
@RunWith(ChromeJUnit4ClassRunner.class) | ||
public class LinkToTextCoordinatorTest { | ||
@Rule | ||
public ActivityTestRule<DummyUiActivity> mActivityTestRule = | ||
new ActivityTestRule<>(DummyUiActivity.class); | ||
|
||
@Mock | ||
private ChromeOptionShareCallback mShareCallback; | ||
|
||
@Mock | ||
private WindowAndroid mWindow; | ||
|
||
private Context mContext; | ||
private static final String SELECTED_TEXT = "selection"; | ||
private static final String VISIBLE_URL = "www.example.com"; | ||
|
||
@Before | ||
public void setUp() { | ||
mContext = mActivityTestRule.getActivity(); | ||
|
||
MockitoAnnotations.initMocks(this); | ||
doNothing() | ||
.when(mShareCallback) | ||
.showThirdPartyShareSheetWithMessage(anyString(), any(), any(), anyLong()); | ||
} | ||
|
||
@Test | ||
@SmallTest | ||
public void getTextToShareTest() { | ||
String selector = "selector"; | ||
String expectedTextToShare = "\"selection\"\nwww.example.com:~:text=selector"; | ||
LinkToTextCoordinator coordinator = new LinkToTextCoordinator( | ||
mContext, mWindow, mShareCallback, VISIBLE_URL, SELECTED_TEXT); | ||
Assert.assertEquals(expectedTextToShare, coordinator.getTextToShare(selector)); | ||
} | ||
|
||
@Test | ||
@SmallTest | ||
public void getTextToShareTest_EmptySelector() { | ||
String selector = ""; | ||
String expectedTextToShare = "\"selection\"\nwww.example.com"; | ||
LinkToTextCoordinator coordinator = new LinkToTextCoordinator( | ||
mContext, mWindow, mShareCallback, VISIBLE_URL, SELECTED_TEXT); | ||
Assert.assertEquals(expectedTextToShare, coordinator.getTextToShare(selector)); | ||
} | ||
|
||
@Test | ||
@SmallTest | ||
public void onSelectorReadyTest() { | ||
LinkToTextCoordinator coordinator = new LinkToTextCoordinator( | ||
mContext, mWindow, mShareCallback, VISIBLE_URL, SELECTED_TEXT); | ||
// OnSelectorReady should call back the share sheet. | ||
verify(mShareCallback) | ||
.showThirdPartyShareSheetWithMessage(anyString(), any(), any(), anyLong()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...r/ui/android/strings/android_chrome_strings_grd/IDS_LINK_TO_TEXT_FAILURE_MESSAGE.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5b5898eac5894e51f40d95d28448f26400679b22 |
1 change: 1 addition & 0 deletions
1
...r/ui/android/strings/android_chrome_strings_grd/IDS_LINK_TO_TEXT_SUCCESS_MESSAGE.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bb68f939991be1e938f3fceafc7f127aadf23e07 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters