| 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.infobar; | 5 package org.chromium.chrome.browser.infobar; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.support.test.filters.MediumTest; | 10 import android.support.test.filters.MediumTest; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 85 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 86 @Override | 86 @Override |
| 87 public boolean isSatisfied() { | 87 public boolean isSatisfied() { |
| 88 if (getActivity().getActivityTab() == null) return false; | 88 if (getActivity().getActivityTab() == null) return false; |
| 89 if (getActivity().getActivityTab().getInfoBarContainer() == null
) return false; | 89 if (getActivity().getActivityTab().getInfoBarContainer() == null
) return false; |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 }); | 92 }); |
| 93 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo
ntainer(); | 93 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo
ntainer(); |
| 94 mListener = new InfoBarTestAnimationListener(); | 94 mListener = new InfoBarTestAnimationListener(); |
| 95 container.setAnimationListener(mListener); | 95 container.addAnimationListener(mListener); |
| 96 | 96 |
| 97 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 97 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
| 98 | 98 |
| 99 // Using an AdvancedMockContext allows us to use a fresh in-memory Share
dPreference. | 99 // Using an AdvancedMockContext allows us to use a fresh in-memory Share
dPreference. |
| 100 Context context = new AdvancedMockContext( | 100 Context context = new AdvancedMockContext( |
| 101 getInstrumentation().getTargetContext().getApplicationContext())
; | 101 getInstrumentation().getTargetContext().getApplicationContext())
; |
| 102 ContextUtils.initApplicationContextForTests(context); | 102 ContextUtils.initApplicationContextForTests(context); |
| 103 } | 103 } |
| 104 | 104 |
| 105 @Override | 105 @Override |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 public void testInfoBarContainerSwapsWebContents() | 464 public void testInfoBarContainerSwapsWebContents() |
| 465 throws InterruptedException, TimeoutException { | 465 throws InterruptedException, TimeoutException { |
| 466 // Add an infobar. | 466 // Add an infobar. |
| 467 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); | 467 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); |
| 468 loadUrl(mTestServer.getURL(GEOLOCATION_PAGE)); | 468 loadUrl(mTestServer.getURL(GEOLOCATION_PAGE)); |
| 469 mListener.addInfoBarAnimationFinished("InfoBar not added"); | 469 mListener.addInfoBarAnimationFinished("InfoBar not added"); |
| 470 assertEquals("Wrong infobar count", 1, getInfoBars().size()); | 470 assertEquals("Wrong infobar count", 1, getInfoBars().size()); |
| 471 | 471 |
| 472 // Swap out the WebContents and send the user somewhere so that the Info
Bar gets removed. | 472 // Swap out the WebContents and send the user somewhere so that the Info
Bar gets removed. |
| 473 InfoBarTestAnimationListener removeListener = new InfoBarTestAnimationLi
stener(); | 473 InfoBarTestAnimationListener removeListener = new InfoBarTestAnimationLi
stener(); |
| 474 getActivity().getActivityTab().getInfoBarContainer().setAnimationListene
r(removeListener); | 474 getActivity().getActivityTab().getInfoBarContainer().addAnimationListene
r(removeListener); |
| 475 ThreadUtils.runOnUiThread(new Runnable() { | 475 ThreadUtils.runOnUiThread(new Runnable() { |
| 476 @Override | 476 @Override |
| 477 public void run() { | 477 public void run() { |
| 478 WebContents newContents = WebContentsFactory.createWebContents(f
alse, false); | 478 WebContents newContents = WebContentsFactory.createWebContents(f
alse, false); |
| 479 getActivity().getActivityTab().swapWebContents(newContents, fals
e, false); | 479 getActivity().getActivityTab().swapWebContents(newContents, fals
e, false); |
| 480 } | 480 } |
| 481 }); | 481 }); |
| 482 loadUrl(HELLO_WORLD_URL); | 482 loadUrl(HELLO_WORLD_URL); |
| 483 removeListener.removeInfoBarAnimationFinished("InfoBar not removed."); | 483 removeListener.removeInfoBarAnimationFinished("InfoBar not removed."); |
| 484 assertEquals("Wrong infobar count", 0, getInfoBars().size()); | 484 assertEquals("Wrong infobar count", 0, getInfoBars().size()); |
| 485 | 485 |
| 486 // Revisiting the original page should make the InfoBar reappear. | 486 // Revisiting the original page should make the InfoBar reappear. |
| 487 InfoBarTestAnimationListener addListener = new InfoBarTestAnimationListe
ner(); | 487 InfoBarTestAnimationListener addListener = new InfoBarTestAnimationListe
ner(); |
| 488 getActivity().getActivityTab().getInfoBarContainer().setAnimationListene
r(addListener); | 488 getActivity().getActivityTab().getInfoBarContainer().addAnimationListene
r(addListener); |
| 489 loadUrl(mTestServer.getURL(GEOLOCATION_PAGE)); | 489 loadUrl(mTestServer.getURL(GEOLOCATION_PAGE)); |
| 490 addListener.addInfoBarAnimationFinished("InfoBar not added"); | 490 addListener.addInfoBarAnimationFinished("InfoBar not added"); |
| 491 assertEquals("Wrong infobar count", 1, getInfoBars().size()); | 491 assertEquals("Wrong infobar count", 1, getInfoBars().size()); |
| 492 } | 492 } |
| 493 } | 493 } |
| OLD | NEW |