本文整理汇总了Java中org.robolectric.shadows.ShadowWebView类的典型用法代码示例。如果您正苦于以下问题:Java ShadowWebView类的具体用法?Java ShadowWebView怎么用?Java ShadowWebView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShadowWebView类属于org.robolectric.shadows包,在下文中一共展示了ShadowWebView类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LoadReceipt
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void LoadReceipt()
{
Intent intent = new Intent();
final Bundle bundle = new Bundle();
bundle.putString("receipt", "receipt");
intent.putExtras(bundle);
ActivityController activityController = Robolectric.buildActivity(
ReceiptViewActivity.class).withIntent(intent).create();
activityController.start();
activityController.resume();
Activity activity = (Activity)activityController.get();
WebView receiptView = (WebView)activity.findViewById(R.id.imageView);
ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL();
assertEquals("", loadedData.baseUrl);
assertEquals("text/html", loadedData.mimeType);
assertEquals("utf-8", loadedData.encoding);
assertNull(loadedData.historyUrl);
assertTrue(loadedData.data.contains("src=\"file://receipt\""));
}
示例2: LoadReceipt
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void LoadReceipt()
{
activityController.start();
activityController.resume();
Activity activity = (Activity)activityController.get();
WebView receiptView = (WebView)activity.findViewById(R.id.imageView);
ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL();
assertEquals("", loadedData.baseUrl);
assertEquals("text/html", loadedData.mimeType);
assertEquals("utf-8", loadedData.encoding);
assertNull(loadedData.historyUrl);
assertTrue(loadedData.data.contains("src=\"file://receipt\""));
}
示例3: testLoadUrl
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void testLoadUrl() {
activity = controller.withIntent(new Intent()
.putExtra(OfflineWebActivity.EXTRA_URL, "http://example.com"))
.create()
.get();
assertThat(activity.getTitle()).contains("http://example.com");
WebView webView = (WebView) activity.findViewById(R.id.web_view);
View progress = activity.findViewById(R.id.progress);
ShadowWebView shadowWebView = shadowOf(webView);
assertThat(shadowWebView.getLastLoadedUrl())
.contains("http://example.com");
shadowWebView.getWebViewClient().onPageFinished(webView, "http://example.com");
assertThat(activity.getTitle()).isNullOrEmpty(); // web view title
shadowWebView.getWebChromeClient().onProgressChanged(webView, 50);
assertThat(progress).isVisible();
shadowWebView.getWebChromeClient().onProgressChanged(webView, 100);
assertThat(progress).isNotVisible();
}
示例4: testStory
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void testStory() {
TestWebItem item = new TestWebItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getDisplayedTitle() {
return "Ask HN";
}
};
Intent intent = new Intent();
intent.putExtra(WebActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume().visible();
verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestItem() {
@Override
public String getText() {
return "text";
}
});
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = shadowOf(webView);
shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text");
}
示例5: testComment
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void testComment() {
TestItem item = new TestItem() {
@NonNull
@Override
public String getType() {
return COMMENT_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getText() {
return "comment";
}
};
Intent intent = new Intent();
intent.putExtra(WebActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume().visible();
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = shadowOf(webView);
shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("comment");
}
示例6: loadHtmlResponse_shouldCallLoadDataWithBaseURL
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void loadHtmlResponse_shouldCallLoadDataWithBaseURL() throws Exception {
String htmlResponse = "some random html response";
subject.loadHtmlResponse(htmlResponse);
ShadowWebView.LoadDataWithBaseURL lastLoadData = shadowOf(subject).getLastLoadDataWithBaseURL();
assertThat(lastLoadData.baseUrl).isEqualTo("http://ads.mopub.com/");
assertThat(lastLoadData.data).isEqualTo(htmlResponse);
assertThat(lastLoadData.mimeType).isEqualTo("text/html");
assertThat(lastLoadData.encoding).isEqualTo("utf-8");
assertThat(lastLoadData.historyUrl).isNull();
}
示例7: destroy_shouldRemoveSelfFromParent
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void destroy_shouldRemoveSelfFromParent() throws Exception {
ViewGroup parentView = mock(ViewGroup.class);
ShadowWebView shadow = shadowOf(subject);
shadow.setMyParent(parentView);
subject.destroy();
verify(parentView).removeView(eq(subject));
assertThat(shadow.wasDestroyCalled());
}
示例8: loadData_shouldCallLoadDataWithBaseURL
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void loadData_shouldCallLoadDataWithBaseURL() throws Exception {
String data = "some random html response";
subject.loadData(data);
ShadowWebView.LoadDataWithBaseURL lastLoadData
= shadowOf(subject).getLastLoadDataWithBaseURL();
assertThat(lastLoadData.baseUrl).isEqualTo("http://ads.mopub.com/");
assertThat(lastLoadData.data).isEqualTo(data);
assertThat(lastLoadData.mimeType).isEqualTo("text/html");
assertThat(lastLoadData.encoding).isEqualTo("utf-8");
assertThat(lastLoadData.historyUrl).isNull();
}
示例9: destroy_shouldRemoveSelfFromParent_beforeCallingDestroy
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void destroy_shouldRemoveSelfFromParent_beforeCallingDestroy() throws Exception {
subject = new BaseWebView(context);
ViewGroup parent = mock(ViewGroup.class);
ShadowWebView shadow = shadowOf(subject);
shadow.setMyParent(parent);
subject.destroy();
verify(parent).removeView(eq(subject));
assertThat(shadow.wasDestroyCalled()).isTrue();
}
示例10: test_StartWebViewActivity_LoadsUrlAndShowsTitle
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
/**
* Generic method for testing proper display of WebViewDialogFragment
*
* @param url The url to load
* @param title The title to show, if any
*/
private void test_StartWebViewActivity_LoadsUrlAndShowsTitle(@NonNull String url,
@Nullable String title)
throws PackageManager.NameNotFoundException {
final WebViewActivity activity =
Robolectric.buildActivity(WebViewActivity.class)
.withIntent(WebViewActivity.newIntent(
RuntimeEnvironment.application, url, title)).setup().get();
final View contentView = Shadows.shadowOf(activity).getContentView();
assertNotNull(contentView);
final WebView webView = (WebView) contentView.findViewById(R.id.webView);
assertNotNull(webView);
final ShadowWebView shadowWebView = Shadows.shadowOf(webView);
assertEquals(shadowWebView.getLastLoadedUrl(), url);
final ActionBar actionBar = activity.getSupportActionBar();
assertNotNull(actionBar);
assertThat(actionBar).isShowing();
if (!TextUtils.isEmpty(title)) {
assertThat(actionBar).hasTitle(title);
}
/*
Robolectric is not providing the correct default title which is why this code has
been commented.
else {
final PackageManager pm = activity.getPackageManager();
final ActivityInfo aInfo = pm.getActivityInfo(activity.getComponentName(), 0);
final String defaultTitle = aInfo.loadLabel(pm).toString();
assertThat(actionBar).hasTitle(defaultTitle);
}
*/
}
示例11: assertThat
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void WebViewで読み込んだURLのテスト() {
Activity activity = Robolectric
.buildActivity(RobolectricSampleActivity.class).create().get();
WebView webView = (WebView) activity.findViewById(R.id.webview);
ShadowWebView shadowWebView = Robolectric.shadowOf((WebView) webView);
assertThat("http://robolectric.org/index.html",
is(shadowWebView.getLastLoadedUrl()));
}
开发者ID:android-opensource-library-56,项目名称:android-opensource-library-56,代码行数:12,代码来源:RobolectricSampleActivityTest.java
示例12: testMenu
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
@Test
public void testMenu() {
TestWebItem item = new TestWebItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getDisplayedTitle() {
return "Ask HN";
}
};
Intent intent = new Intent();
intent.putExtra(WebActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume().visible();
verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestItem() {
@Override
public String getText() {
return "text";
}
});
Fragment fragment = activity.getSupportFragmentManager()
.findFragmentByTag(WebFragment.class.getName());
assertTrue(fragment.hasOptionsMenu());
fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
assertNotNull(ShadowDialog.getLatestDialog());
PreferenceManager.getDefaultSharedPreferences(activity)
.edit()
.putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf")
.apply();
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = shadowOf(webView);
shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowWebView.getLastLoadDataWithBaseURL().data)
.contains("text")
.contains("DroidSans.ttf");
}
示例13: shadowOf
import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
public static ShadowWebView shadowOf(WebView instance) {
return (ShadowWebView) shadowOf_(instance);
}