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 |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.base; |
6 | |
7 | import android.content.Context; |
8 | import android.test.AndroidTestCase; |
9 | import android.test.mock.MockContext; |
10 | import android.test.suitebuilder.annotation.SmallTest; |
11 | |
12 | import static org.chromium.base.ContextTypes.CONTEXT_TYPE_NORMAL; |
13 | import static org.chromium.base.ContextTypes.CONTEXT_TYPE_WEBAPP; |
14 | |
15 | public class ContextTypesTest extends AndroidTestCase { |
16 | |
17 | @SmallTest |
18 | public void testReturnsExpectedType() { |
19 | ContextTypes contextTypes = ContextTypes.getInstance(); |
20 | Context normal = new MockContext(); |
21 | Context webapp = new MockContext(); |
22 | contextTypes.put(normal, CONTEXT_TYPE_NORMAL); |
23 | contextTypes.put(webapp, CONTEXT_TYPE_WEBAPP); |
24 | assertEquals(CONTEXT_TYPE_NORMAL, contextTypes.getType(normal)); |
25 | assertEquals(CONTEXT_TYPE_WEBAPP, contextTypes.getType(webapp)); |
26 | } |
27 | |
28 | @SmallTest |
29 | public void testAbsentContextReturnsNormalType() { |
30 | assertEquals(CONTEXT_TYPE_NORMAL, ContextTypes.getInstance().getType(new MockContext())); |
31 | } |
32 | |
33 | @SmallTest |
34 | public void testPutInvalidTypeThrowsException() { |
35 | boolean exceptionThrown = false; |
36 | try { |
37 | ContextTypes.getInstance().put(new MockContext(), -1); |
38 | } catch (IllegalArgumentException e) { |
39 | exceptionThrown = true; |
40 | } |
41 | assertTrue(exceptionThrown); |
42 | } |
43 | } |