Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[usecase-embeddingapi] Add tests for setJavaScript related APIs (#3731)
Browse files Browse the repository at this point in the history
Impacted tests(approved): new 4, update 0, delete 0
Unit test platform: Crosswalk for Android 21.51.546.0
Unit test result summary: pass 4, fail 0, block 0

BUG=https://crosswalk-project.org/jira/browse/CTS-1818
  • Loading branch information
haoxli authored and Shao-Feng committed Jul 27, 2016
1 parent 69cdefe commit ef012ac
Show file tree
Hide file tree
Showing 25 changed files with 629 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,24 @@
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".setting.XWalkViewSettingJavaScriptEnabledAsync"
android:label="@string/title_activity_xwalk_view_setting_javascript_enabled_async"
android:parentActivityName=".XWalkEmbeddedAPISample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".setting.XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync"
android:label="@string/title_activity_xwalk_view_setting_javascript_open_windows_automatically_async"
android:parentActivityName=".XWalkEmbeddedAPISample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".misc.XWalkViewWithOnTouchListenerAsync"
android:label="@string/title_activity_xwalk_view_with_on_touch_listener_async"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<body>
JavaScript Enabled: <span id="result">False</span>
<script>
document.getElementById("result").innerHTML = "True";
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<body>
Windows Open Automatically: <span id="result">Disabled</span>
<script>
try {
window.open("window_open_automatically_enabled.html", "_blank", "")
}catch(e) {
logDiv.innerHTML = e;
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Windows Open Automatically: <span id="result">Enabled</span>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check if XWalkView can enable/disable DOM storage API."
android:text="Check that XWalkView can enable/disable DOM storage API. Click the button to enable/disable DOM storage."
android:id="@+id/textView" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.xwalk.embedded.api.sample.setting.XWalkViewSettingJavaScriptEnabledAsync">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check that XWalkView can enable/disable JavaScript execution. Click the button to enable/disable JavaScript."
android:id="@+id/textView" />


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/message_tv"
android:textColor="#00ff00"
android:layout_below="@+id/textView"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch_al"
android:layout_below="@+id/message_tv"
android:layout_alignParentStart="true" />

<org.xwalk.core.XWalkView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/xwalk_view"
android:layout_below="@+id/switch_al" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="org.xwalk.embedded.api.sample.setting.XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check that XWalkView can enable/disable JavaScript open windows automatically. Click the button to enable/disable JavaScriptCanOpenWindowsAutomatically."
android:id="@+id/textView" />


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/message_tv"
android:textColor="#00ff00"
android:layout_below="@+id/textView"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch_al"
android:layout_below="@+id/message_tv"
android:layout_alignParentStart="true" />

<org.xwalk.core.XWalkView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/xwalk_view"
android:layout_below="@+id/switch_al" />

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ found in the LICENSE file.
</string>
<string name="title_activity_xwalk_view_setting_dom_storage_enabled_async">XWalkViewSettingDomStorageEnabledAsync</string>
<string name="title_activity_xwalk_view_setting_save_form_data_async">XWalkViewSettingSaveFormDataAsync</string>
<string name="title_activity_xwalk_view_setting_javascript_enabled_async">XWalkViewSettingJavaScriptEnabledAsync</string>
<string name="title_activity_xwalk_view_setting_javascript_open_windows_automatically_async">XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync</string>
<string name="title_activity_xwalk_view_with_on_touch_listener_async">XWalkViewWithOnTouchListenerAsync</string>
<string name="title_activity_xwalk_view_with_on_js_alert_async">XWalkViewWithOnJsAlertAsync</string>
<string name="title_activity_xwalk_view_with_response_headers_async">XWalkViewWithOnReceivedResponseHeadersAsync</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,23 @@ This usecase covers following interface and methods:

* XWalkSettings interface: setSaveFormData, getSaveFormData


### 90. The [XWalkViewSettingJavaScriptEnabledAsync](setting/XWalkViewSettingJavaScriptEnabledAsync.java) sample check XWalkView can enable/disable JavaScript, include:

* XWalkView can enable JavaScript
* XWalkView can disable JavaScript

This usecase covers following interface and methods:

* XWalkSettings interface: setJavaScript, getJavaScript


### 91. The [XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync](setting/XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync.java) sample check XWalkView can enable/disable JavaScriptCanOpenWindowsAutomatically, include:

* XWalkView can enable JavaScriptCanOpenWindowsAutomatically
* XWalkView can disable JavaScriptCanOpenWindowsAutomatically

This usecase covers following interface and methods:

* XWalkSettings interface: setJavaScriptCanOpenWindowsAutomatically, getJavaScriptCanOpenWindowsAutomatically

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onXWalkInitStarted() {

@Override
public void onXWalkInitCompleted() {
setContentView(R.layout.activity_xwalk_view_setting_accept_language_async);
setContentView(R.layout.activity_xwalk_view_setting_dom_storage_enable_async);

StringBuffer mess = new StringBuffer();
mess.append("Test Purpose: \n\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.xwalk.embedded.api.asyncsample.setting;

import org.xwalk.core.XWalkInitializer;
import org.xwalk.core.XWalkSettings;
import org.xwalk.core.XWalkView;
import org.xwalk.embedded.api.asyncsample.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class XWalkViewSettingJavaScriptCanOpenWindowsAutomaticallyAsync extends Activity implements XWalkInitializer.XWalkInitListener {

private XWalkInitializer mXWalkInitializer;

public final static String ENABLE_BT = "Enable JavaScriptCanOpenWindowsAutomatically";
public final static String DISABLE_BT = "Disable JavaScriptCanOpenWindowsAutomatically";
public final static String MESSAGE_TITLE = "JavaScriptCanOpenWindowsAutomatically Enabled: ";

private XWalkView mXWalkView;
private TextView mMessage;
private Button mButton;
private XWalkSettings settings;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mXWalkInitializer = new XWalkInitializer(this, this);
mXWalkInitializer.initAsync();
}

@Override
public void onXWalkInitCancelled() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitFailed() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitStarted() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitCompleted() {
setContentView(R.layout.activity_xwalk_view_setting_javascript_open_windows_automatically_async);

StringBuffer mess = new StringBuffer();
mess.append("Test Purpose: \n\n")
.append("Check that XWalkView can enable/disable JavaScript open windows automatically.\n\n")
.append("Expected Result:\n\n")
.append("Test passes if XWalkView can enable/disable JavaScript open windows automatically during window.open().");
new AlertDialog.Builder(this)
.setTitle("Info")
.setMessage(mess.toString())
.setPositiveButton("confirm", null)
.show();

mXWalkView = (XWalkView) findViewById(R.id.xwalk_view);
mMessage = (TextView) findViewById(R.id.message_tv);
mButton = (Button) findViewById(R.id.switch_al);
settings = mXWalkView.getSettings();
boolean defaultValue = settings.getJavaScriptCanOpenWindowsAutomatically();
if (defaultValue) {
mButton.setText(DISABLE_BT);
}else{
mButton.setText(ENABLE_BT);
}
mMessage.setText(MESSAGE_TITLE + defaultValue + "(Default)");
mXWalkView.load("file:///android_asset/window_open_automatically.html", null);

mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ENABLE_BT.equals(mButton.getText())) {
settings.setJavaScriptCanOpenWindowsAutomatically(true);
mButton.setText(DISABLE_BT);
} else {
settings.setJavaScriptCanOpenWindowsAutomatically(false);
mButton.setText(ENABLE_BT);
}
mMessage.setText(MESSAGE_TITLE + settings.getJavaScriptCanOpenWindowsAutomatically());
mXWalkView.load("file:///android_asset/window_open_automatically.html", null);

}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.xwalk.embedded.api.asyncsample.setting;

import org.xwalk.core.XWalkInitializer;
import org.xwalk.core.XWalkSettings;
import org.xwalk.core.XWalkView;
import org.xwalk.embedded.api.asyncsample.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class XWalkViewSettingJavaScriptEnabledAsync extends Activity implements XWalkInitializer.XWalkInitListener {

private XWalkInitializer mXWalkInitializer;

public final static String ENABLE_BT = "Enable JavaScript";
public final static String DISABLE_BT = "Disable JavaScript";
public final static String MESSAGE_TITLE = "JavaScript Enabled: ";

private XWalkView mXWalkView;
private TextView mMessage;
private Button mButton;
private XWalkSettings settings;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mXWalkInitializer = new XWalkInitializer(this, this);
mXWalkInitializer.initAsync();
}

@Override
public void onXWalkInitCancelled() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitFailed() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitStarted() {
// TODO Auto-generated method stub
}

@Override
public void onXWalkInitCompleted() {
setContentView(R.layout.activity_xwalk_view_setting_javascript_enabled_async);

StringBuffer mess = new StringBuffer();
mess.append("Test Purpose: \n\n")
.append("Check that XWalkView can enable/disable JavaScript execution.\n\n")
.append("Expected Result:\n\n")
.append("Test passes if JavaScript can be enabled/disabled");
new AlertDialog.Builder(this)
.setTitle("Info")
.setMessage(mess.toString())
.setPositiveButton("confirm", null)
.show();

mXWalkView = (XWalkView) findViewById(R.id.xwalk_view);
mMessage = (TextView) findViewById(R.id.message_tv);
mButton = (Button) findViewById(R.id.switch_al);
settings = mXWalkView.getSettings();
boolean defaultValue = settings.getJavaScriptEnabled();
if (defaultValue) {
mButton.setText(DISABLE_BT);
}else{
mButton.setText(ENABLE_BT);
}
mMessage.setText(MESSAGE_TITLE + defaultValue + "(Default)");
mXWalkView.load("file:///android_asset/javascript_enabled.html", null);

mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ENABLE_BT.equals(mButton.getText())) {
settings.setJavaScriptEnabled(true);
mButton.setText(DISABLE_BT);
} else {
settings.setJavaScriptEnabled(false);
mButton.setText(ENABLE_BT);
}
mMessage.setText(MESSAGE_TITLE + settings.getJavaScriptEnabled());
mXWalkView.load("file:///android_asset/javascript_enabled.html", null);

}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,24 @@
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".setting.XWalkViewSettingJavaScriptEnabled"
android:label="@string/title_activity_xwalk_view_setting_javascript_enabled"
android:parentActivityName=".XWalkEmbeddedAPISample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".setting.XWalkViewSettingJavaScriptCanOpenWindowsAutomatically"
android:label="@string/title_activity_xwalk_view_setting_javascript_open_windows_automatically"
android:parentActivityName=".XWalkEmbeddedAPISample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="XWalkView.Setting" />
</intent-filter>
</activity>
<activity
android:name=".misc.XWalkViewWithOnTouchListener"
android:label="@string/title_activity_xwalk_view_with_on_touch_listener"
Expand Down
Loading

0 comments on commit ef012ac

Please sign in to comment.