1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013-2014 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.internal.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.internal.XWalkClient;
15 import org.xwalk.core.internal.XWalkViewInternal;
18 * Test case for XWalkViewInternal.setNetworkAvailable method
20 * Once setNetworkAvailable is called, the navigator.onLine property will be
21 * set, and window.ononline/onoffline event will be fired if the property is
24 public class SetNetworkAvailableTest extends XWalkViewInternalTestBase {
26 public void setUp() throws Exception {
30 @Feature({"SetNetworkAvailableTest"})
32 public void testSetNetworkAvailableTest() throws Throwable {
33 final String code = "navigator.onLine";
34 loadAssetFile("navigator.online.html");
35 String title = getTitleOnUiThread();
37 final XWalkViewInternal xwView = getXWalkView();
39 if ("true".equals(title)) {
40 getInstrumentation().runOnMainSync(new Runnable() {
43 // Forcing to trigger 'offline' event.
44 xwView.setNetworkAvailable(false);
50 * 1. navigator.onLine is false;
51 * 2. window.onoffline event is fired.
53 assertEquals("false", executeJavaScriptAndWaitForResult(code));
54 assertEquals("offline:false", getTitleOnUiThread());
56 getInstrumentation().runOnMainSync(new Runnable() {
59 // Forcing to trigger 'online' event.
60 xwView.setNetworkAvailable(true);
66 * 1. navigator.onLine is true;
67 * 2. window.ononline event is fired.
69 assertEquals("true", executeJavaScriptAndWaitForResult(code));
70 assertEquals("online:true", getTitleOnUiThread());
73 if ("false".equals(title)) {
74 getInstrumentation().runOnMainSync(new Runnable() {
77 // Forcing to trigger 'online' event.
78 xwView.setNetworkAvailable(true);
84 * 1. navigator.onLine is true;
85 * 2. window.ononline event is fired.
87 assertEquals("true", executeJavaScriptAndWaitForResult(code));
88 assertEquals("online:true", getTitleOnUiThread());
90 getInstrumentation().runOnMainSync(new Runnable() {
93 // Forcing to trigger 'offline' event.
94 xwView.setNetworkAvailable(false);
100 * 1. navigator.onLine is false;
101 * 2. window.onoffline event is fired.
103 assertEquals("false", executeJavaScriptAndWaitForResult(code));
104 assertEquals("offline:false", getTitleOnUiThread());