1 // Copyright (c) 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.chrome.testshell;
7 import org.chromium.chrome.browser.EmptyTabObserver;
8 import org.chromium.chrome.browser.TabBase;
9 import org.chromium.content.browser.ContentViewClient;
10 import org.chromium.content.browser.test.util.CallbackHelper;
11 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
12 import org.chromium.content.browser.test.util.TestContentViewClient;
13 import org.chromium.content.browser.test.util.TestContentViewClientWrapper;
14 import org.chromium.content.browser.test.util.TestWebContentsObserver;
17 * A utility class that contains methods generic to all Tabs tests.
19 public class TabShellTabUtils {
20 private static TestContentViewClient createTestContentViewClientForTab(TestShellTab tab) {
21 ContentViewClient client = tab.getContentView().getContentViewClient();
22 if (client instanceof TestContentViewClient) return (TestContentViewClient) client;
24 TestContentViewClient testClient = new TestContentViewClientWrapper(client);
25 tab.getContentView().setContentViewClient(testClient);
29 public static class TestCallbackHelperContainerForTab extends TestCallbackHelperContainer {
30 private final OnCloseTabHelper mOnCloseTabHelper;
31 public TestCallbackHelperContainerForTab(TestShellTab tab) {
32 super(createTestContentViewClientForTab(tab),
33 new TestWebContentsObserver(tab.getContentView().getContentViewCore()));
34 mOnCloseTabHelper = new OnCloseTabHelper();
35 tab.addObserver(new EmptyTabObserver() {
37 public void onDestroyed(TabBase tab) {
38 mOnCloseTabHelper.notifyCalled();
43 public static class OnCloseTabHelper extends CallbackHelper {
46 public OnCloseTabHelper getOnCloseTabHelper() {
47 return mOnCloseTabHelper;
52 * Creates, binds and returns a TestCallbackHelperContainer for a given Tab.
54 public static TestCallbackHelperContainerForTab getTestCallbackHelperContainer(
55 final TestShellTab tab) {
56 return tab == null ? null : new TestCallbackHelperContainerForTab(tab);