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.
5 package org.chromium.base;
7 import android.content.Context;
8 import android.test.AndroidTestCase;
9 import android.test.mock.MockContext;
10 import android.test.suitebuilder.annotation.SmallTest;
12 import static org.chromium.base.ContextTypes.CONTEXT_TYPE_NORMAL;
13 import static org.chromium.base.ContextTypes.CONTEXT_TYPE_WEBAPP;
15 public class ContextTypesTest extends AndroidTestCase {
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));
29 public void testAbsentContextReturnsNormalType() {
30 assertEquals(CONTEXT_TYPE_NORMAL, ContextTypes.getInstance().getType(new MockContext()));
34 public void testPutInvalidTypeThrowsException() {
35 boolean exceptionThrown = false;
37 ContextTypes.getInstance().put(new MockContext(), -1);
38 } catch (IllegalArgumentException e) {
39 exceptionThrown = true;
41 assertTrue(exceptionThrown);