public static void destroy() { if (sInstance == null) { throw new RuntimeException("No instance to destroy"); } Settings.get().saveData(); MainApplication app = (MainApplication) sInstance.mContext.getApplicationContext(); Bus bus = app.getBus(); bus.unregister(sInstance); if (Settings.get().isIncognitoMode()) { CookieManager cookieManager = CookieManager.getInstance(); if (cookieManager != null && cookieManager.hasCookies()) { cookieManager.removeAllCookie(); } } if (Constant.PROFILE_FPS) { sInstance.mWindowManager.removeView(sInstance.mTextView); } sInstance.mBubbleDraggable.destroy(); sInstance.mBubbleFlowDraggable.destroy(); sInstance.mCanvasView.destroy(); sInstance.mChoreographer.removeFrameCallback(sInstance); sInstance.endAppPolling(); sInstance = null; }
@TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, method = "hasCookies", args = {}), @TestTargetNew( level = TestLevel.COMPLETE, method = "removeAllCookie", args = {}) }) @ToBeFixed(explanation = "CookieManager.hasCookies() should also count cookies in RAM cache") public void testCookieManager() { // enable cookie mCookieManager.setAcceptCookie(true); assertTrue(mCookieManager.acceptCookie()); // first there should be no cookie stored assertFalse(mCookieManager.hasCookies()); String url = "http://www.example.com"; String cookie = "name=test"; mCookieManager.setCookie(url, cookie); assertEquals(cookie, mCookieManager.getCookie(url)); // sync cookie from RAM to FLASH, because hasCookies() only counts FLASH cookies CookieSyncManager.getInstance().sync(); new DelayedCheck(TEST_DELAY) { @Override protected boolean check() { return mCookieManager.hasCookies(); } }.run(); // clean up all cookies mCookieManager.removeAllCookie(); new DelayedCheck(TEST_DELAY) { @Override protected boolean check() { return !mCookieManager.hasCookies(); } }.run(); }
@TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, method = "setAcceptCookie", args = {boolean.class}), @TestTargetNew( level = TestLevel.COMPLETE, method = "acceptCookie", args = {}), @TestTargetNew( level = TestLevel.COMPLETE, method = "setCookie", args = {String.class, String.class}), @TestTargetNew( level = TestLevel.COMPLETE, method = "getCookie", args = {String.class}), @TestTargetNew( level = TestLevel.COMPLETE, method = "removeAllCookie", args = {}) }) public void testAcceptCookie() throws Exception { mCookieManager.removeAllCookie(); mCookieManager.setAcceptCookie(false); assertFalse(mCookieManager.acceptCookie()); assertFalse(mCookieManager.hasCookies()); CtsTestServer server = new CtsTestServer(getActivity(), false); String url = server.getCookieUrl("conquest.html"); loadUrl(url); assertEquals(null, mWebView.getTitle()); // no cookies passed Thread.sleep(TEST_DELAY); assertNull(mCookieManager.getCookie(url)); mCookieManager.setAcceptCookie(true); assertTrue(mCookieManager.acceptCookie()); url = server.getCookieUrl("war.html"); loadUrl(url); assertEquals(null, mWebView.getTitle()); // no cookies passed waitForCookie(url); String cookie = mCookieManager.getCookie(url); assertNotNull(cookie); // 'count' value of the returned cookie is 0 final Pattern pat = Pattern.compile("count=(\\d+)"); Matcher m = pat.matcher(cookie); assertTrue(m.matches()); assertEquals("0", m.group(1)); url = server.getCookieUrl("famine.html"); loadUrl(url); assertEquals("count=0", mWebView.getTitle()); // outgoing cookie waitForCookie(url); cookie = mCookieManager.getCookie(url); assertNotNull(cookie); m = pat.matcher(cookie); assertTrue(m.matches()); assertEquals("1", m.group(1)); // value got incremented url = server.getCookieUrl("death.html"); mCookieManager.setCookie(url, "count=41"); loadUrl(url); assertEquals("count=41", mWebView.getTitle()); // outgoing cookie waitForCookie(url); cookie = mCookieManager.getCookie(url); assertNotNull(cookie); m = pat.matcher(cookie); assertTrue(m.matches()); assertEquals("42", m.group(1)); // value got incremented // clean up all cookies mCookieManager.removeAllCookie(); }
@TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, method = "removeSessionCookie", args = {}), @TestTargetNew( level = TestLevel.COMPLETE, method = "removeExpiredCookie", args = {}) }) @SuppressWarnings("deprecation") public void testRemoveCookies() throws InterruptedException { // enable cookie mCookieManager.setAcceptCookie(true); assertTrue(mCookieManager.acceptCookie()); assertFalse(mCookieManager.hasCookies()); final String url = "http://www.example.com"; final String cookie1 = "cookie1=peter"; final String cookie2 = "cookie2=sue"; final String cookie3 = "cookie3=marc"; mCookieManager.setCookie(url, cookie1); // session cookie Date date = new Date(); date.setTime(date.getTime() + 1000 * 600); String value2 = cookie2 + "; expires=" + date.toGMTString(); mCookieManager.setCookie(url, value2); // expires in 10min long expiration = 3000; date = new Date(); date.setTime(date.getTime() + expiration); String value3 = cookie3 + "; expires=" + date.toGMTString(); mCookieManager.setCookie(url, value3); // expires in 3s String allCookies = mCookieManager.getCookie(url); assertTrue(allCookies.contains(cookie1)); assertTrue(allCookies.contains(cookie2)); assertTrue(allCookies.contains(cookie3)); mCookieManager.removeSessionCookie(); new DelayedCheck(TEST_DELAY) { protected boolean check() { String c = mCookieManager.getCookie(url); return !c.contains(cookie1) && c.contains(cookie2) && c.contains(cookie3); } }.run(); Thread.sleep(expiration + 1000); // wait for cookie to expire mCookieManager.removeExpiredCookie(); new DelayedCheck(TEST_DELAY) { protected boolean check() { String c = mCookieManager.getCookie(url); return !c.contains(cookie1) && c.contains(cookie2) && !c.contains(cookie3); } }.run(); mCookieManager.removeAllCookie(); new DelayedCheck(TEST_DELAY) { protected boolean check() { return mCookieManager.getCookie(url) == null; } }.run(); }