Android以编程方式操纵unittests的浏览器历史记录
我想对我的类进行单元测试,为此我首先调用:Android以编程方式操纵unittests的浏览器历史记录,android,browser-history,Android,Browser History,我想对我的类进行单元测试,为此我首先调用: Browser.clearHistory(getContext().getContentResolver()); 但是我现在如何添加一些条目作为我的unittest的测试数据呢?我已经为此创建了一个函数,它在chrome中调用URL private void openUrlInChrome(String url) { Intent intent = new Intent("android.intent.action.MAIN");
Browser.clearHistory(getContext().getContentResolver());
但是我现在如何添加一些条目作为我的unittest的测试数据呢?我已经为此创建了一个函数,它在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();
}
}