1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 package org.xwalk.core.xwview.test;
8 import android.graphics.Bitmap;
9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.util.Log;
11 import org.chromium.base.test.util.DisabledTest;
12 import org.chromium.base.test.util.Feature;
14 import org.xwalk.core.XWalkClient;
15 import org.xwalk.core.XWalkContent;
16 import org.xwalk.core.XWalkView;
19 * Test case for XWalkView.setNetworkAvailable method
21 * Once setNetworkAvailable is called, the navigator.onLine property will be
22 * set, and window.ononline/onoffline event will be fired if the property is
25 public class SetNetworkAvailableTest extends XWalkViewTestBase {
27 public void setUp() throws Exception {
30 setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
33 @Feature({"SetNetworkAvailableTest"})
35 public void testSetNetworkAvailableTest() throws Throwable {
36 final String code = "navigator.onLine";
37 loadAssetFile("navigator.online.html");
38 String title = getTitleOnUiThread();
40 final XWalkView xwView = getXWalkView();
42 if ("true".equals(title)) {
43 getInstrumentation().runOnMainSync(new Runnable() {
46 // Forcing to trigger 'offline' event.
47 xwView.setNetworkAvailable(false);
53 * 1. navigator.onLine is false;
54 * 2. window.onoffline event is fired.
56 assertEquals("false", executeJavaScriptAndWaitForResult(code));
57 assertEquals("offline:false", getTitleOnUiThread());
59 getInstrumentation().runOnMainSync(new Runnable() {
62 // Forcing to trigger 'online' event.
63 xwView.setNetworkAvailable(true);
69 * 1. navigator.onLine is true;
70 * 2. window.ononline event is fired.
72 assertEquals("true", executeJavaScriptAndWaitForResult(code));
73 assertEquals("online:true", getTitleOnUiThread());
76 if ("false".equals(title)) {
77 getInstrumentation().runOnMainSync(new Runnable() {
80 // Forcing to trigger 'online' event.
81 xwView.setNetworkAvailable(true);
87 * 1. navigator.onLine is true;
88 * 2. window.ononline event is fired.
90 assertEquals("true", executeJavaScriptAndWaitForResult(code));
91 assertEquals("online:true", getTitleOnUiThread());
93 getInstrumentation().runOnMainSync(new Runnable() {
96 // Forcing to trigger 'offline' event.
97 xwView.setNetworkAvailable(false);
103 * 1. navigator.onLine is false;
104 * 2. window.onoffline event is fired.
106 assertEquals("false", executeJavaScriptAndWaitForResult(code));
107 assertEquals("offline:false", getTitleOnUiThread());