当前位置: 首页>>代码示例>>Java>>正文


Java ShadowWebView类代码示例

本文整理汇总了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\""));
}
 
开发者ID:brarcher,项目名称:gift-card-guard,代码行数:24,代码来源:ReceiptViewActivityTest.java

示例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\""));
}
 
开发者ID:brarcher,项目名称:budget-watch,代码行数:17,代码来源:ReceiptViewActivityTest.java

示例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();
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:20,代码来源:OfflineWebActivityTest.java

示例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");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:40,代码来源:WebFragmentLocalTest.java

示例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");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:33,代码来源:WebFragmentLocalTest.java

示例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();
}
 
开发者ID:JSafaiyeh,项目名称:Fabric-Example-App-Android,代码行数:13,代码来源:BaseHtmlWebViewTest.java

示例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());
}
 
开发者ID:JSafaiyeh,项目名称:Fabric-Example-App-Android,代码行数:12,代码来源:BaseHtmlWebViewTest.java

示例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();
}
 
开发者ID:JSafaiyeh,项目名称:Fabric-Example-App-Android,代码行数:14,代码来源:VastWebViewTest.java

示例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();
}
 
开发者ID:JSafaiyeh,项目名称:Fabric-Example-App-Android,代码行数:13,代码来源:BaseWebViewTest.java

示例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);
    }
    */
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:38,代码来源:WebViewActivityTest.java

示例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");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:51,代码来源:WebFragmentLocalTest.java

示例13: shadowOf

import org.robolectric.shadows.ShadowWebView; //导入依赖的package包/类
public static ShadowWebView shadowOf(WebView instance) {
  return (ShadowWebView) shadowOf_(instance);
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:4,代码来源:Robolectric.java


注:本文中的org.robolectric.shadows.ShadowWebView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。