| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.content.browser.test.util.Criteria; | 10 import org.chromium.content.browser.test.util.Criteria; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 private void showContentViewOnUiThread() { | 38 private void showContentViewOnUiThread() { |
| 39 getInstrumentation().runOnMainSync(new Runnable() { | 39 getInstrumentation().runOnMainSync(new Runnable() { |
| 40 @Override | 40 @Override |
| 41 public void run() { | 41 public void run() { |
| 42 getContentViewCore().onShow(); | 42 getContentViewCore().onShow(); |
| 43 } | 43 } |
| 44 }); | 44 }); |
| 45 } | 45 } |
| 46 | 46 |
| 47 private void pollForPositionCallback() throws Throwable { | 47 private void pollForPositionCallback() throws Throwable { |
| 48 mJavascriptHelper.evaluateJavaScript(getWebContents(), | 48 mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| 49 "positionCount = 0"); | 49 "positionCount = 0"); |
| 50 mJavascriptHelper.waitUntilHasValue(); | 50 mJavascriptHelper.waitUntilHasValue(); |
| 51 assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear
())); | 51 assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear
())); |
| 52 | 52 |
| 53 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 53 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 54 @Override | 54 @Override |
| 55 public boolean isSatisfied() { | 55 public boolean isSatisfied() { |
| 56 mJavascriptHelper.evaluateJavaScript(getWebContents(), "posi
tionCount"); | 56 mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(
), "positionCount"); |
| 57 try { | 57 try { |
| 58 mJavascriptHelper.waitUntilHasValue(); | 58 mJavascriptHelper.waitUntilHasValue(); |
| 59 } catch (Exception e) { | 59 } catch (Exception e) { |
| 60 fail(); | 60 fail(); |
| 61 } | 61 } |
| 62 return Integer.parseInt(mJavascriptHelper.getJsonResultAndCl
ear()) > 0; | 62 return Integer.parseInt(mJavascriptHelper.getJsonResultAndCl
ear()) > 0; |
| 63 } | 63 } |
| 64 })); | 64 })); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private void startGeolocationWatchPosition() throws Throwable { | 67 private void startGeolocationWatchPosition() throws Throwable { |
| 68 mJavascriptHelper.evaluateJavaScript(getWebContents(), | 68 mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| 69 "initiate_watchPosition();"); | 69 "initiate_watchPosition();"); |
| 70 mJavascriptHelper.waitUntilHasValue(); | 70 mJavascriptHelper.waitUntilHasValue(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 private void ensureGeolocationRunning(final boolean running) throws Exceptio
n { | 73 private void ensureGeolocationRunning(final boolean running) throws Exceptio
n { |
| 74 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 74 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 75 @Override | 75 @Override |
| 76 public boolean isSatisfied() { | 76 public boolean isSatisfied() { |
| 77 return mMockLocationProvider.isRunning() == running; | 77 return mMockLocationProvider.isRunning() == running; |
| 78 } | 78 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 109 public void testWatchHideShowStop() throws Throwable { | 109 public void testWatchHideShowStop() throws Throwable { |
| 110 | 110 |
| 111 startGeolocationWatchPosition(); | 111 startGeolocationWatchPosition(); |
| 112 pollForPositionCallback(); | 112 pollForPositionCallback(); |
| 113 ensureGeolocationRunning(true); | 113 ensureGeolocationRunning(true); |
| 114 | 114 |
| 115 // Now hide the ContentView and ensure that geolocation stops. | 115 // Now hide the ContentView and ensure that geolocation stops. |
| 116 hideContentViewOnUiThread(); | 116 hideContentViewOnUiThread(); |
| 117 ensureGeolocationRunning(false); | 117 ensureGeolocationRunning(false); |
| 118 | 118 |
| 119 mJavascriptHelper.evaluateJavaScript(getWebContents(), | 119 mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), |
| 120 "positionCount = 0"); | 120 "positionCount = 0"); |
| 121 mJavascriptHelper.waitUntilHasValue(); | 121 mJavascriptHelper.waitUntilHasValue(); |
| 122 | 122 |
| 123 // Show the ContentView again and ensure that geolocation starts again. | 123 // Show the ContentView again and ensure that geolocation starts again. |
| 124 showContentViewOnUiThread(); | 124 showContentViewOnUiThread(); |
| 125 pollForPositionCallback(); | 125 pollForPositionCallback(); |
| 126 ensureGeolocationRunning(true); | 126 ensureGeolocationRunning(true); |
| 127 | 127 |
| 128 // Navigate away and ensure that geolocation stops. | 128 // Navigate away and ensure that geolocation stops. |
| 129 loadUrl(getContentViewCore().getWebContents().getNavigationController(), | 129 loadUrl(getContentViewCore().getWebContents().getNavigationController(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 hideContentViewOnUiThread(); | 168 hideContentViewOnUiThread(); |
| 169 startGeolocationWatchPosition(); | 169 startGeolocationWatchPosition(); |
| 170 ensureGeolocationRunning(false); | 170 ensureGeolocationRunning(false); |
| 171 | 171 |
| 172 loadUrl(getContentViewCore().getWebContents().getNavigationController(), | 172 loadUrl(getContentViewCore().getWebContents().getNavigationController(), |
| 173 mTestCallbackHelperContainer, new LoadUrlParams("about:blank")); | 173 mTestCallbackHelperContainer, new LoadUrlParams("about:blank")); |
| 174 showContentViewOnUiThread(); | 174 showContentViewOnUiThread(); |
| 175 ensureGeolocationRunning(false); | 175 ensureGeolocationRunning(false); |
| 176 } | 176 } |
| 177 } | 177 } |
| OLD | NEW |