OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.graphics.Canvas; | 7 import android.graphics.Canvas; |
8 import android.test.UiThreadTest; | 8 import android.test.UiThreadTest; |
9 import android.test.suitebuilder.annotation.LargeTest; | 9 import android.test.suitebuilder.annotation.LargeTest; |
10 import android.test.suitebuilder.annotation.MediumTest; | 10 import android.test.suitebuilder.annotation.MediumTest; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 assertTrue(mTab.getNativePage() instanceof NewTabPage); | 107 assertTrue(mTab.getNativePage() instanceof NewTabPage); |
108 mNtp = (NewTabPage) mTab.getNativePage(); | 108 mNtp = (NewTabPage) mTab.getNativePage(); |
109 mFakebox = mNtp.getView().findViewById(R.id.search_box); | 109 mFakebox = mNtp.getView().findViewById(R.id.search_box); |
110 mMostVisitedLayout = (ViewGroup) mNtp.getView().findViewById(R.id.most_v
isited_layout); | 110 mMostVisitedLayout = (ViewGroup) mNtp.getView().findViewById(R.id.most_v
isited_layout); |
111 assertEquals(mFakeMostVisitedUrls.length, mMostVisitedLayout.getChildCou
nt()); | 111 assertEquals(mFakeMostVisitedUrls.length, mMostVisitedLayout.getChildCou
nt()); |
112 } | 112 } |
113 | 113 |
114 @MediumTest | 114 @MediumTest |
115 @Feature({"NewTabPage", "RenderTest"}) | 115 @Feature({"NewTabPage", "RenderTest"}) |
116 @CommandLineFlags.Add("enable-features=NTPSnippets") | 116 @CommandLineFlags.Add("enable-features=NTPSnippets") |
117 public void testRender() throws IOException, InterruptedException { | 117 public void testRender() throws IOException { |
118 ViewRenderer viewRenderer = new ViewRenderer(getActivity(), | 118 ViewRenderer viewRenderer = new ViewRenderer(getActivity(), |
119 "chrome/test/data/android/render_tests", "NewTabPageTest"); | 119 "chrome/test/data/android/render_tests", "NewTabPageTest"); |
120 viewRenderer.renderAndCompare(mMostVisitedLayout, "most_visited"); | 120 viewRenderer.renderAndCompare(mMostVisitedLayout, "most_visited"); |
121 viewRenderer.renderAndCompare(mFakebox, "fakebox"); | 121 viewRenderer.renderAndCompare(mFakebox, "fakebox"); |
122 viewRenderer.renderAndCompare(mNtp.getView().getRootView(), "new_tab_pag
e"); | 122 viewRenderer.renderAndCompare(mNtp.getView().getRootView(), "new_tab_pag
e"); |
123 | 123 |
124 // Scroll to search bar | 124 // Scroll to search bar |
125 final NewTabPageRecyclerView recyclerView = | 125 final NewTabPageRecyclerView recyclerView = |
126 (NewTabPageRecyclerView) mNtp.getNewTabPageView().getWrapperView
(); | 126 (NewTabPageRecyclerView) mNtp.getNewTabPageView().getWrapperView
(); |
127 | 127 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 397 |
398 private boolean getUrlFocusAnimatonsDisabled() { | 398 private boolean getUrlFocusAnimatonsDisabled() { |
399 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { | 399 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
400 @Override | 400 @Override |
401 public Boolean call() throws Exception { | 401 public Boolean call() throws Exception { |
402 return mNtp.getNewTabPageView().urlFocusAnimationsDisabled(); | 402 return mNtp.getNewTabPageView().urlFocusAnimationsDisabled(); |
403 } | 403 } |
404 }); | 404 }); |
405 } | 405 } |
406 | 406 |
407 private void waitForUrlFocusAnimationsDisabledState(boolean disabled) | 407 private void waitForUrlFocusAnimationsDisabledState(boolean disabled) { |
408 throws InterruptedException { | |
409 CriteriaHelper.pollInstrumentationThread(Criteria.equals(disabled, new C
allable<Boolean>() { | 408 CriteriaHelper.pollInstrumentationThread(Criteria.equals(disabled, new C
allable<Boolean>() { |
410 @Override | 409 @Override |
411 public Boolean call() { | 410 public Boolean call() { |
412 return getUrlFocusAnimatonsDisabled(); | 411 return getUrlFocusAnimatonsDisabled(); |
413 } | 412 } |
414 })); | 413 })); |
415 } | 414 } |
416 | 415 |
417 private void waitForTabLoading() throws InterruptedException { | 416 private void waitForTabLoading() { |
418 CriteriaHelper.pollUiThread(new Criteria() { | 417 CriteriaHelper.pollUiThread(new Criteria() { |
419 @Override | 418 @Override |
420 public boolean isSatisfied() { | 419 public boolean isSatisfied() { |
421 return mTab.isLoading(); | 420 return mTab.isLoading(); |
422 } | 421 } |
423 }); | 422 }); |
424 } | 423 } |
425 | 424 |
426 private void waitForFakeboxFocusAnimationComplete(NewTabPage ntp) throws Int
erruptedException { | 425 private void waitForFakeboxFocusAnimationComplete(NewTabPage ntp) throws Int
erruptedException { |
427 waitForUrlFocusPercent(ntp, 1f); | 426 waitForUrlFocusPercent(ntp, 1f); |
428 } | 427 } |
429 | 428 |
430 private void waitForUrlFocusPercent(final NewTabPage ntp, float percent) | 429 private void waitForUrlFocusPercent(final NewTabPage ntp, float percent) { |
431 throws InterruptedException { | |
432 CriteriaHelper.pollUiThread(Criteria.equals(percent, new Callable<Float>
() { | 430 CriteriaHelper.pollUiThread(Criteria.equals(percent, new Callable<Float>
() { |
433 @Override | 431 @Override |
434 public Float call() { | 432 public Float call() { |
435 return ntp.getNewTabPageView().getUrlFocusChangeAnimationPercent
(); | 433 return ntp.getNewTabPageView().getUrlFocusChangeAnimationPercent
(); |
436 } | 434 } |
437 })); | 435 })); |
438 } | 436 } |
439 | 437 |
440 private void clickFakebox() { | 438 private void clickFakebox() { |
441 View fakebox = mNtp.getView().findViewById(R.id.search_box); | 439 View fakebox = mNtp.getView().findViewById(R.id.search_box); |
(...skipping 11 matching lines...) Expand all Loading... |
453 int[] location = new int[2]; | 451 int[] location = new int[2]; |
454 fakebox.getLocationInWindow(location); | 452 fakebox.getLocationInWindow(location); |
455 return location[1]; | 453 return location[1]; |
456 } | 454 } |
457 }); | 455 }); |
458 } | 456 } |
459 | 457 |
460 /** | 458 /** |
461 * Waits until the top of the fakebox reaches the given position. | 459 * Waits until the top of the fakebox reaches the given position. |
462 */ | 460 */ |
463 private void waitForFakeboxTopPosition(final NewTabPage ntp, int position) | 461 private void waitForFakeboxTopPosition(final NewTabPage ntp, int position) { |
464 throws InterruptedException { | |
465 CriteriaHelper.pollUiThread(Criteria.equals(position, new Callable<Integ
er>() { | 462 CriteriaHelper.pollUiThread(Criteria.equals(position, new Callable<Integ
er>() { |
466 @Override | 463 @Override |
467 public Integer call() { | 464 public Integer call() { |
468 return getFakeboxTop(ntp); | 465 return getFakeboxTop(ntp); |
469 } | 466 } |
470 })); | 467 })); |
471 } | 468 } |
472 } | 469 } |
OLD | NEW |