【问题标题】:Android programmatically manipulate Browser History for unittestsAndroid 以编程方式处理单元测试的浏览器历史记录
【发布时间】:2014-02-25 11:20:06
【问题描述】:

我想对我的课程进行单元测试,为此我首先调用:

Browser.clearHistory(getContext().getContentResolver());

但是我现在如何添加一些条目作为我的单元测试的测试数据?

【问题讨论】:

    标签: android browser-history


    【解决方案1】:

    我为此创建了一个函数,它在 chrome 中调用 url

    private void openUrlInChrome(String url) {
        Intent intent = new Intent("android.intent.action.MAIN");
    
        // force system to use chrome and not standard browser
        intent.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
    
        intent.addCategory("android.intent.category.LAUNCHER");
    
        // is needed because this test is not an activity
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
        intent.setData(Uri.parse(url));
        getContext().startActivity(intent);
        // wait until chrome has opened the pages
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-08
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      相关资源
      最近更新 更多