// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.partnercustomizations;

import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;
import android.test.AndroidTestCase;

import org.chromium.chrome.test.partnercustomizations.TestPartnerBrowserCustomizationsDelayedProvider;
import org.chromium.chrome.test.partnercustomizations.TestPartnerBrowserCustomizationsProvider;

import java.util.concurrent.Semaphore;

/**
 * Basic shared functionality for partner customization unit tests.
 */
public class BasePartnerBrowserCustomizationUnitTest extends AndroidTestCase {
    protected static final String PARTNER_BROWSER_CUSTOMIZATIONS_PROVIDER =
            TestPartnerBrowserCustomizationsProvider.class.getName();
    protected static final String PARTNER_BROWSER_CUSTOMIZATIONS_NO_PROVIDER =
            TestPartnerBrowserCustomizationsProvider.class.getName() + "INVALID";
    protected static final String PARTNER_BROWSER_CUSTOMIZATIONS_DELAYED_PROVIDER =
            TestPartnerBrowserCustomizationsDelayedProvider.class.getName();
    protected static final long DEFAULT_TIMEOUT_MS = 500;

    protected final Runnable mCallback = new Runnable() {
        @Override
        public void run() {
            mCallbackLock.release();
        }
    };
    protected final Semaphore mCallbackLock = new Semaphore(0);

    /**
     * Specifies the URI path that should be delayed when querying the delayed provider.
     * <p>
     * This will override the provider authority in the PartnerBrowserCustomizations, so be
     * sure to reset it if you are not using the delayed provider.
     *
     * @param uriPath The path to be delayed.
     */
    public void setDelayProviderUriPathForDelay(String uriPath) {
        PartnerBrowserCustomizations.setProviderAuthorityForTests(
                PARTNER_BROWSER_CUSTOMIZATIONS_DELAYED_PROVIDER);
        Uri uri = PartnerBrowserCustomizations.buildQueryUri(uriPath);
        getContext().getContentResolver().call(uri, "setUriPathToDelay", uriPath, null);
    }

    @Override
    public Context getContext() {
        ContextWrapper context = new ContextWrapper(super.getContext()) {
            @Override
            public Context getApplicationContext() {
                return getBaseContext();
            }
        };
        return context;
    }
}

@@ -352,16 +352,54 @@
 tCase;%0A%0A
+import org.chromium.base.CommandLine;%0A
 import o
@@ -2229,16 +2229,138 @@
 %0A    %7D%0A%0A
+    @Override%0A    protected void setUp() throws Exception %7B%0A        super.setUp();%0A        CommandLine.init(null);%0A    %7D%0A%0A
     @Ove

Fix partner customizations unit tests.