| 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.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.support.test.InstrumentationRegistry; |
| 8 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
| 9 import android.test.InstrumentationTestCase; | 10 |
| 11 import org.junit.After; |
| 12 import org.junit.Assert; |
| 13 import org.junit.Before; |
| 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; |
| 10 | 16 |
| 11 import org.chromium.base.metrics.RecordHistogram; | 17 import org.chromium.base.metrics.RecordHistogram; |
| 12 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 13 | 20 |
| 14 /** | 21 /** |
| 15 * Tests for {@link WebappAuthenticator}. | 22 * Tests for {@link WebappAuthenticator}. |
| 16 */ | 23 */ |
| 17 public class WebappAuthenticatorTest extends InstrumentationTestCase { | 24 @RunWith(ChromeJUnit4ClassRunner.class) |
| 18 @Override | 25 public class WebappAuthenticatorTest { |
| 26 @Before |
| 19 public void setUp() throws Exception { | 27 public void setUp() throws Exception { |
| 20 super.setUp(); | |
| 21 RecordHistogram.setDisabledForTests(true); | 28 RecordHistogram.setDisabledForTests(true); |
| 22 } | 29 } |
| 23 | 30 |
| 24 @Override | 31 @After |
| 25 protected void tearDown() throws Exception { | 32 public void tearDown() throws Exception { |
| 26 super.tearDown(); | |
| 27 RecordHistogram.setDisabledForTests(false); | 33 RecordHistogram.setDisabledForTests(false); |
| 28 } | 34 } |
| 29 | 35 |
| 36 @Test |
| 30 @SmallTest | 37 @SmallTest |
| 31 @Feature({"Webapps"}) | 38 @Feature({"Webapps"}) |
| 32 public void testAuthentication() { | 39 public void testAuthentication() { |
| 33 Context context = getInstrumentation().getTargetContext(); | 40 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); |
| 34 String url = "http://www.example.org/hello.html"; | 41 String url = "http://www.example.org/hello.html"; |
| 35 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); | 42 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); |
| 36 assertNotNull(mac); | 43 Assert.assertNotNull(mac); |
| 37 assertTrue(WebappAuthenticator.isUrlValid(context, url, mac)); | 44 Assert.assertTrue(WebappAuthenticator.isUrlValid(context, url, mac)); |
| 38 assertFalse(WebappAuthenticator.isUrlValid(context, url + "?goats=true",
mac)); | 45 Assert.assertFalse(WebappAuthenticator.isUrlValid(context, url + "?goats
=true", mac)); |
| 39 mac[4] += (byte) 1; | 46 mac[4] += (byte) 1; |
| 40 assertFalse(WebappAuthenticator.isUrlValid(context, url, mac)); | 47 Assert.assertFalse(WebappAuthenticator.isUrlValid(context, url, mac)); |
| 41 } | 48 } |
| 42 } | 49 } |
| OLD | NEW |