OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import static org.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
8 import static org.junit.Assert.assertFalse; | 8 import static org.junit.Assert.assertFalse; |
9 import static org.junit.Assert.assertNotEquals; | 9 import static org.junit.Assert.assertNotEquals; |
10 import static org.junit.Assert.assertThat; | 10 import static org.junit.Assert.assertThat; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions)
; | 301 mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions)
; |
302 assertItemsFor(section(4)); | 302 assertItemsFor(section(4)); |
303 } | 303 } |
304 | 304 |
305 /** | 305 /** |
306 * Tests how the loading indicator reacts to status changes. | 306 * Tests how the loading indicator reacts to status changes. |
307 */ | 307 */ |
308 @Test | 308 @Test |
309 @Feature({"Ntp"}) | 309 @Feature({"Ntp"}) |
310 public void testProgressIndicatorDisplay() { | 310 public void testProgressIndicatorDisplay() { |
311 SuggestionsSection section = mAdapter.getSectionForTesting(KnownCategori
es.ARTICLES); | 311 SuggestionsSection section = |
| 312 mAdapter.getSectionListForTesting().getSectionForTesting(KnownCa
tegories.ARTICLES); |
312 ProgressItem progress = section.getProgressItemForTesting(); | 313 ProgressItem progress = section.getProgressItemForTesting(); |
313 | 314 |
314 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.IN
ITIALIZING); | 315 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.IN
ITIALIZING); |
315 assertTrue(progress.isVisible()); | 316 assertTrue(progress.isVisible()); |
316 | 317 |
317 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE); | 318 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE); |
318 assertFalse(progress.isVisible()); | 319 assertFalse(progress.isVisible()); |
319 | 320 |
320 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE_LOADING); | 321 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE_LOADING); |
321 assertTrue(progress.isVisible()); | 322 assertTrue(progress.isVisible()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 reloadNtp(); | 396 reloadNtp(); |
396 assertItemsFor(sectionWithStatusCard().withProgress()); | 397 assertItemsFor(sectionWithStatusCard().withProgress()); |
397 | 398 |
398 // 1.2 - With suggestions | 399 // 1.2 - With suggestions |
399 List<SnippetArticle> articles = Collections.unmodifiableList(createDummy
Suggestions(3)); | 400 List<SnippetArticle> articles = Collections.unmodifiableList(createDummy
Suggestions(3)); |
400 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); | 401 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); |
401 suggestionsSource.setSuggestionsForCategory(category, articles); | 402 suggestionsSource.setSuggestionsForCategory(category, articles); |
402 assertItemsFor(section(3)); | 403 assertItemsFor(section(3)); |
403 | 404 |
404 // 1.3 - When all suggestions are dismissed | 405 // 1.3 - When all suggestions are dismissed |
405 SuggestionsSection section42 = mAdapter.getSectionForTesting(category); | 406 SuggestionsSection section42 = |
| 407 mAdapter.getSectionListForTesting().getSectionForTesting(categor
y); |
406 assertSectionMatches(section(3), section42); | 408 assertSectionMatches(section(3), section42); |
407 section42.removeSuggestion(articles.get(0)); | 409 section42.removeSuggestion(articles.get(0)); |
408 section42.removeSuggestion(articles.get(1)); | 410 section42.removeSuggestion(articles.get(1)); |
409 section42.removeSuggestion(articles.get(2)); | 411 section42.removeSuggestion(articles.get(2)); |
410 assertItemsFor(sectionWithStatusCard()); | 412 assertItemsFor(sectionWithStatusCard()); |
411 | 413 |
412 // Part 2: VisibleIfEmpty = false | 414 // Part 2: VisibleIfEmpty = false |
413 suggestionsSource = new FakeSuggestionsSource(); | 415 suggestionsSource = new FakeSuggestionsSource(); |
414 suggestionsSource.setStatusForCategory(category, CategoryStatus.INITIALI
ZING); | 416 suggestionsSource.setStatusForCategory(category, CategoryStatus.INITIALI
ZING); |
415 suggestionsSource.setInfoForCategory(category, new CategoryInfoBuilder(c
ategory).build()); | 417 suggestionsSource.setInfoForCategory(category, new CategoryInfoBuilder(c
ategory).build()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 reloadNtp(); | 451 reloadNtp(); |
450 assertItemsFor(sectionWithStatusCard().withActionButton().withProgress()
); | 452 assertItemsFor(sectionWithStatusCard().withActionButton().withProgress()
); |
451 | 453 |
452 // 1.2 - With suggestions. | 454 // 1.2 - With suggestions. |
453 List<SnippetArticle> articles = Collections.unmodifiableList(createDummy
Suggestions(3)); | 455 List<SnippetArticle> articles = Collections.unmodifiableList(createDummy
Suggestions(3)); |
454 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); | 456 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); |
455 suggestionsSource.setSuggestionsForCategory(category, articles); | 457 suggestionsSource.setSuggestionsForCategory(category, articles); |
456 assertItemsFor(section(3).withActionButton()); | 458 assertItemsFor(section(3).withActionButton()); |
457 | 459 |
458 // 1.3 - When all suggestions are dismissed. | 460 // 1.3 - When all suggestions are dismissed. |
459 SuggestionsSection section42 = mAdapter.getSectionForTesting(category); | 461 SuggestionsSection section42 = |
| 462 mAdapter.getSectionListForTesting().getSectionForTesting(categor
y); |
460 assertSectionMatches(section(3).withActionButton(), section42); | 463 assertSectionMatches(section(3).withActionButton(), section42); |
461 section42.removeSuggestion(articles.get(0)); | 464 section42.removeSuggestion(articles.get(0)); |
462 section42.removeSuggestion(articles.get(1)); | 465 section42.removeSuggestion(articles.get(1)); |
463 section42.removeSuggestion(articles.get(2)); | 466 section42.removeSuggestion(articles.get(2)); |
464 assertItemsFor(sectionWithStatusCard().withActionButton()); | 467 assertItemsFor(sectionWithStatusCard().withActionButton()); |
465 | 468 |
466 // Part 1: Without "View All" action | 469 // Part 1: Without "View All" action |
467 suggestionsSource = new FakeSuggestionsSource(); | 470 suggestionsSource = new FakeSuggestionsSource(); |
468 suggestionsSource.setStatusForCategory(category, CategoryStatus.INITIALI
ZING); | 471 suggestionsSource.setStatusForCategory(category, CategoryStatus.INITIALI
ZING); |
469 suggestionsSource.setInfoForCategory(category, | 472 suggestionsSource.setInfoForCategory(category, |
470 new CategoryInfoBuilder(category).showIfEmpty().build()); | 473 new CategoryInfoBuilder(category).showIfEmpty().build()); |
471 | 474 |
472 // 2.1 - Initial state. | 475 // 2.1 - Initial state. |
473 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); | 476 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); |
474 reloadNtp(); | 477 reloadNtp(); |
475 assertItemsFor(sectionWithStatusCard().withProgress()); | 478 assertItemsFor(sectionWithStatusCard().withProgress()); |
476 | 479 |
477 // 2.2 - With suggestions. | 480 // 2.2 - With suggestions. |
478 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); | 481 suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABL
E); |
479 suggestionsSource.setSuggestionsForCategory(category, articles); | 482 suggestionsSource.setSuggestionsForCategory(category, articles); |
480 assertItemsFor(section(3)); | 483 assertItemsFor(section(3)); |
481 | 484 |
482 // 2.3 - When all suggestions are dismissed. | 485 // 2.3 - When all suggestions are dismissed. |
483 section42 = mAdapter.getSectionForTesting(category); | 486 section42 = mAdapter.getSectionListForTesting().getSectionForTesting(cat
egory); |
484 assertSectionMatches(section(3), section42); | 487 assertSectionMatches(section(3), section42); |
485 section42.removeSuggestion(articles.get(0)); | 488 section42.removeSuggestion(articles.get(0)); |
486 section42.removeSuggestion(articles.get(1)); | 489 section42.removeSuggestion(articles.get(1)); |
487 section42.removeSuggestion(articles.get(2)); | 490 section42.removeSuggestion(articles.get(2)); |
488 assertItemsFor(sectionWithStatusCard()); | 491 assertItemsFor(sectionWithStatusCard()); |
489 } | 492 } |
490 | 493 |
491 /** | 494 /** |
492 * Tests that invalidated suggestions are immediately removed. | 495 * Tests that invalidated suggestions are immediately removed. |
493 */ | 496 */ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 reloadNtp(); | 539 reloadNtp(); |
537 assertItemsFor(section(3), section(5).withActionButton(), section(11)); | 540 assertItemsFor(section(3), section(5).withActionButton(), section(11)); |
538 } | 541 } |
539 | 542 |
540 /** | 543 /** |
541 * Tests that the order of the categories is kept. | 544 * Tests that the order of the categories is kept. |
542 */ | 545 */ |
543 @Test | 546 @Test |
544 @Feature({"Ntp"}) | 547 @Feature({"Ntp"}) |
545 public void testCategoryOrder() { | 548 public void testCategoryOrder() { |
546 // Above-the-fold, sign in promo, all-dismissed, footer, spacer. | |
547 final int basicChildCount = 5; | |
548 FakeSuggestionsSource suggestionsSource = new FakeSuggestionsSource(); | 549 FakeSuggestionsSource suggestionsSource = new FakeSuggestionsSource(); |
549 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); | 550 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); |
550 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); | 551 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); |
551 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 0); | 552 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 0); |
552 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); | 553 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); |
553 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); | 554 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); |
554 reloadNtp(); | 555 reloadNtp(); |
555 | 556 |
556 List<TreeNode> children = mAdapter.getRootForTesting().getChildren(); | 557 List<TreeNode> children = mAdapter.getSectionListForTesting().getChildre
n(); |
557 assertEquals(basicChildCount + 4, children.size()); | 558 assertEquals(4, children.size()); |
558 assertEquals(AboveTheFoldItem.class, children.get(0).getClass()); | 559 assertEquals(SuggestionsSection.class, children.get(0).getClass()); |
| 560 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(0))); |
559 assertEquals(SuggestionsSection.class, children.get(1).getClass()); | 561 assertEquals(SuggestionsSection.class, children.get(1).getClass()); |
560 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(1))); | 562 assertEquals(KnownCategories.BOOKMARKS, getCategory(children.get(1))); |
561 assertEquals(SuggestionsSection.class, children.get(2).getClass()); | 563 assertEquals(SuggestionsSection.class, children.get(2).getClass()); |
562 assertEquals(KnownCategories.BOOKMARKS, getCategory(children.get(2))); | 564 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(2))); |
563 assertEquals(SuggestionsSection.class, children.get(3).getClass()); | 565 assertEquals(SuggestionsSection.class, children.get(3).getClass()); |
564 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(3))); | 566 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(3))); |
565 assertEquals(SuggestionsSection.class, children.get(4).getClass()); | |
566 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(4))); | |
567 | 567 |
568 // With a different order. | 568 // With a different order. |
569 suggestionsSource = new FakeSuggestionsSource(); | 569 suggestionsSource = new FakeSuggestionsSource(); |
570 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); | 570 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); |
571 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); | 571 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); |
572 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); | 572 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); |
573 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); | 573 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); |
574 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 0); | 574 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 0); |
575 reloadNtp(); | 575 reloadNtp(); |
576 | 576 |
577 children = mAdapter.getRootForTesting().getChildren(); | 577 children = mAdapter.getSectionListForTesting().getChildren(); |
578 assertEquals(basicChildCount + 4, children.size()); | 578 assertEquals(4, children.size()); |
579 assertEquals(AboveTheFoldItem.class, children.get(0).getClass()); | 579 assertEquals(SuggestionsSection.class, children.get(0).getClass()); |
| 580 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(0))); |
580 assertEquals(SuggestionsSection.class, children.get(1).getClass()); | 581 assertEquals(SuggestionsSection.class, children.get(1).getClass()); |
581 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(1))); | 582 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(1))); |
582 assertEquals(SuggestionsSection.class, children.get(2).getClass()); | 583 assertEquals(SuggestionsSection.class, children.get(2).getClass()); |
583 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(2))); | 584 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(2))); |
584 assertEquals(SuggestionsSection.class, children.get(3).getClass()); | 585 assertEquals(SuggestionsSection.class, children.get(3).getClass()); |
585 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(3))); | 586 assertEquals(KnownCategories.BOOKMARKS, getCategory(children.get(3))); |
586 assertEquals(SuggestionsSection.class, children.get(4).getClass()); | |
587 assertEquals(KnownCategories.BOOKMARKS, getCategory(children.get(4))); | |
588 | 587 |
589 // With unknown categories. | 588 // With unknown categories. |
590 suggestionsSource = new FakeSuggestionsSource(); | 589 suggestionsSource = new FakeSuggestionsSource(); |
591 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); | 590 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); |
592 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); | 591 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 0); |
593 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); | 592 registerCategory(suggestionsSource, KnownCategories.PHYSICAL_WEB_PAGES,
0); |
594 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); | 593 registerCategory(suggestionsSource, KnownCategories.DOWNLOADS, 0); |
595 reloadNtp(); | 594 reloadNtp(); |
596 | 595 |
597 // The adapter is already initialised, it will not accept new categories
anymore. | 596 // The adapter is already initialised, it will not accept new categories
anymore. |
598 registerCategory(suggestionsSource, 42, 1); | 597 registerCategory(suggestionsSource, 42, 1); |
599 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 1); | 598 registerCategory(suggestionsSource, KnownCategories.BOOKMARKS, 1); |
600 | 599 |
601 children = mAdapter.getRootForTesting().getChildren(); | 600 children = mAdapter.getSectionListForTesting().getChildren(); |
602 assertEquals(basicChildCount + 3, children.size()); | 601 assertEquals(3, children.size()); |
603 assertEquals(AboveTheFoldItem.class, children.get(0).getClass()); | 602 assertEquals(SuggestionsSection.class, children.get(0).getClass()); |
| 603 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(0))); |
604 assertEquals(SuggestionsSection.class, children.get(1).getClass()); | 604 assertEquals(SuggestionsSection.class, children.get(1).getClass()); |
605 assertEquals(KnownCategories.ARTICLES, getCategory(children.get(1))); | 605 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(1))); |
606 assertEquals(SuggestionsSection.class, children.get(2).getClass()); | 606 assertEquals(SuggestionsSection.class, children.get(2).getClass()); |
607 assertEquals(KnownCategories.PHYSICAL_WEB_PAGES, getCategory(children.ge
t(2))); | 607 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(2))); |
608 assertEquals(SuggestionsSection.class, children.get(3).getClass()); | |
609 assertEquals(KnownCategories.DOWNLOADS, getCategory(children.get(3))); | |
610 } | 608 } |
611 | 609 |
612 @Test | 610 @Test |
613 @Feature({"Ntp"}) | 611 @Feature({"Ntp"}) |
614 public void testChangeNotifications() { | 612 public void testChangeNotifications() { |
615 FakeSuggestionsSource suggestionsSource = spy(new FakeSuggestionsSource(
)); | 613 FakeSuggestionsSource suggestionsSource = spy(new FakeSuggestionsSource(
)); |
616 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 3); | 614 registerCategory(suggestionsSource, KnownCategories.ARTICLES, 3); |
617 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); | 615 when(mNewTabPageManager.getSuggestionsSource()).thenReturn(suggestionsSo
urce); |
618 | 616 |
619 reloadNtp(); | 617 reloadNtp(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // 2 | Status | 656 // 2 | Status |
659 // 3 | Action | 657 // 3 | Action |
660 // 4 | Progress Indicator | 658 // 4 | Progress Indicator |
661 // 5 | Footer | 659 // 5 | Footer |
662 // 6 | Spacer | 660 // 6 | Spacer |
663 | 661 |
664 final int newSuggestionCount = 7; | 662 final int newSuggestionCount = 7; |
665 reset(dataObserver); | 663 reset(dataObserver); |
666 suggestionsSource.setSuggestionsForCategory( | 664 suggestionsSource.setSuggestionsForCategory( |
667 KnownCategories.ARTICLES, createDummySuggestions(newSuggestionCo
unt)); | 665 KnownCategories.ARTICLES, createDummySuggestions(newSuggestionCo
unt)); |
668 mAdapter.onNewSuggestions(KnownCategories.ARTICLES); | 666 mAdapter.getSectionListForTesting().onNewSuggestions(KnownCategories.ART
ICLES); |
669 verify(dataObserver).onItemRangeInserted(2, newSuggestionCount); | 667 verify(dataObserver).onItemRangeInserted(2, newSuggestionCount); |
670 verify(dataObserver).onItemRangeChanged(5 + newSuggestionCount, 1, null)
; // Spacer refresh | 668 verify(dataObserver).onItemRangeChanged(5 + newSuggestionCount, 1, null)
; // Spacer refresh |
671 verify(dataObserver, times(2)).onItemRangeRemoved(2 + newSuggestionCount
, 1); | 669 verify(dataObserver, times(2)).onItemRangeRemoved(2 + newSuggestionCount
, 1); |
672 verify(dataObserver).onItemRangeChanged(4 + newSuggestionCount, 1, null)
; // Spacer refresh | 670 verify(dataObserver).onItemRangeChanged(4 + newSuggestionCount, 1, null)
; // Spacer refresh |
673 verify(dataObserver).onItemRangeChanged(3 + newSuggestionCount, 1, null)
; // Spacer refresh | 671 verify(dataObserver).onItemRangeChanged(3 + newSuggestionCount, 1, null)
; // Spacer refresh |
674 | 672 |
675 // Adapter content: | 673 // Adapter content: |
676 // Idx | Item | 674 // Idx | Item |
677 // ----|---------------- | 675 // ----|---------------- |
678 // 0 | Above-the-fold | 676 // 0 | Above-the-fold |
679 // 1 | Header | 677 // 1 | Header |
680 // 2-8 | Sugg*7 | 678 // 2-8 | Sugg*7 |
681 // 9 | Footer | 679 // 9 | Footer |
682 // 10 | Spacer | 680 // 10 | Spacer |
683 | 681 |
684 verifyNoMoreInteractions(dataObserver); | 682 verifyNoMoreInteractions(dataObserver); |
685 reset(dataObserver); | 683 reset(dataObserver); |
686 suggestionsSource.setSuggestionsForCategory( | 684 suggestionsSource.setSuggestionsForCategory( |
687 KnownCategories.ARTICLES, createDummySuggestions(0)); | 685 KnownCategories.ARTICLES, createDummySuggestions(0)); |
688 mAdapter.onCategoryStatusChanged(KnownCategories.ARTICLES, CategoryStatu
s.SIGNED_OUT); | 686 mAdapter.getSectionListForTesting().onCategoryStatusChanged( |
| 687 KnownCategories.ARTICLES, CategoryStatus.SIGNED_OUT); |
689 verify(dataObserver).onItemRangeRemoved(2, newSuggestionCount); | 688 verify(dataObserver).onItemRangeRemoved(2, newSuggestionCount); |
690 verify(dataObserver).onItemRangeChanged(3, 1, null); // Spacer refresh | 689 verify(dataObserver).onItemRangeChanged(3, 1, null); // Spacer refresh |
691 verify(dataObserver).onItemRangeInserted(2, 1); // Status card added | 690 verify(dataObserver).onItemRangeInserted(2, 1); // Status card added |
692 verify(dataObserver).onItemRangeChanged(4, 1, null); // Spacer refresh | 691 verify(dataObserver).onItemRangeChanged(4, 1, null); // Spacer refresh |
693 verify(dataObserver).onItemRangeInserted(3, 1); // Action item added | 692 verify(dataObserver).onItemRangeInserted(3, 1); // Action item added |
694 verify(dataObserver).onItemRangeChanged(5, 1, null); // Spacer refresh | 693 verify(dataObserver).onItemRangeChanged(5, 1, null); // Spacer refresh |
695 verifyNoMoreInteractions(dataObserver); | 694 verifyNoMoreInteractions(dataObserver); |
696 } | 695 } |
697 | 696 |
698 @Test | 697 @Test |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 // Prepare some suggestions. They should not load because the category i
s dismissed on | 842 // Prepare some suggestions. They should not load because the category i
s dismissed on |
844 // the current NTP. | 843 // the current NTP. |
845 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE); | 844 mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AV
AILABLE); |
846 mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, createDummyS
uggestions(1)); | 845 mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, createDummyS
uggestions(1)); |
847 mSource.setInfoForCategory(KnownCategories.ARTICLES, | 846 mSource.setInfoForCategory(KnownCategories.ARTICLES, |
848 new CategoryInfoBuilder(KnownCategories.ARTICLES).build()); | 847 new CategoryInfoBuilder(KnownCategories.ARTICLES).build()); |
849 assertEquals(4, mAdapter.getItemCount()); // TODO(dgn): rewrite with sec
tion descriptors. | 848 assertEquals(4, mAdapter.getItemCount()); // TODO(dgn): rewrite with sec
tion descriptors. |
850 | 849 |
851 // On Sign in, we should reset the sections, bring back suggestions inst
ead of the All | 850 // On Sign in, we should reset the sections, bring back suggestions inst
ead of the All |
852 // Dismissed item. | 851 // Dismissed item. |
853 mAdapter.onFullRefreshRequired(); | 852 mAdapter.getSectionListForTesting().onFullRefreshRequired(); |
854 when(mMockSigninManager.isSignInAllowed()).thenReturn(true); | 853 when(mMockSigninManager.isSignInAllowed()).thenReturn(true); |
855 signinObserver.onSignedIn(); | 854 signinObserver.onSignedIn(); |
856 // Adapter content: | 855 // Adapter content: |
857 // Idx | Item | 856 // Idx | Item |
858 // ----|-------------------- | 857 // ----|-------------------- |
859 // 0 | Above-the-fold | 858 // 0 | Above-the-fold |
860 // 1 | Header | 859 // 1 | Header |
861 // 2 | Suggestion | 860 // 2 | Suggestion |
862 // 4 | Footer | 861 // 4 | Footer |
863 // 5 | Spacer | 862 // 5 | Spacer |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 suggestionsSource.setInfoForCategory(category, | 944 suggestionsSource.setInfoForCategory(category, |
946 new CategoryInfoBuilder(category).withReloadAction().showIfEmpty
().build()); | 945 new CategoryInfoBuilder(category).withReloadAction().showIfEmpty
().build()); |
947 suggestionsSource.setSuggestionsForCategory( | 946 suggestionsSource.setSuggestionsForCategory( |
948 category, createDummySuggestions(suggestionCount)); | 947 category, createDummySuggestions(suggestionCount)); |
949 } | 948 } |
950 | 949 |
951 private int getCategory(TreeNode item) { | 950 private int getCategory(TreeNode item) { |
952 return ((SuggestionsSection) item).getCategory(); | 951 return ((SuggestionsSection) item).getCategory(); |
953 } | 952 } |
954 } | 953 } |
OLD | NEW |