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.XWalkView;
15 import org.xwalk.core.internal.XWalkClient;
18 * Test case for XWalkView.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 XWalkViewTestBase {
26 public void setUp() throws Exception {
29 setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
32 @Feature({"SetNetworkAvailableTest"})
34 public void testSetNetworkAvailableTest() throws Throwable {
35 final String code = "navigator.onLine";
36 loadAssetFile("navigator.online.html");
37 String title = getTitleOnUiThread();
39 final XWalkView xwView = getXWalkView();
41 if ("true".equals(title)) {
42 getInstrumentation().runOnMainSync(new Runnable() {
45 // Forcing to trigger 'offline' event.
46 xwView.setNetworkAvailable(false);
52 * 1. navigator.onLine is false;
53 * 2. window.onoffline event is fired.
55 assertEquals("false", executeJavaScriptAndWaitForResult(code));
56 assertEquals("offline:false", getTitleOnUiThread());
58 getInstrumentation().runOnMainSync(new Runnable() {
61 // Forcing to trigger 'online' event.
62 xwView.setNetworkAvailable(true);
68 * 1. navigator.onLine is true;
69 * 2. window.ononline event is fired.
71 assertEquals("true", executeJavaScriptAndWaitForResult(code));
72 assertEquals("online:true", getTitleOnUiThread());
75 if ("false".equals(title)) {
76 getInstrumentation().runOnMainSync(new Runnable() {
79 // Forcing to trigger 'online' event.
80 xwView.setNetworkAvailable(true);
86 * 1. navigator.onLine is true;
87 * 2. window.ononline event is fired.
89 assertEquals("true", executeJavaScriptAndWaitForResult(code));
90 assertEquals("online:true", getTitleOnUiThread());
92 getInstrumentation().runOnMainSync(new Runnable() {
95 // Forcing to trigger 'offline' event.
96 xwView.setNetworkAvailable(false);
102 * 1. navigator.onLine is false;
103 * 2. window.onoffline event is fired.
105 assertEquals("false", executeJavaScriptAndWaitForResult(code));
106 assertEquals("offline:false", getTitleOnUiThread());