Home | History | Annotate | Download | only in resources
      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
      3 // found in the LICENSE file.
      4 
      5 #include <algorithm>
      6 #include <vector>
      7 
      8 #include "cc/resources/managed_tile_state.h"
      9 #include "cc/resources/prioritized_tile_set.h"
     10 #include "cc/resources/tile.h"
     11 #include "cc/test/fake_output_surface.h"
     12 #include "cc/test/fake_output_surface_client.h"
     13 #include "cc/test/fake_picture_pile_impl.h"
     14 #include "cc/test/fake_tile_manager.h"
     15 #include "cc/test/fake_tile_manager_client.h"
     16 #include "cc/test/test_tile_priorities.h"
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 
     19 namespace cc {
     20 
     21 class BinComparator {
     22  public:
     23   bool operator()(const scoped_refptr<Tile>& a,
     24                   const scoped_refptr<Tile>& b) const {
     25     const ManagedTileState& ams = a->managed_state();
     26     const ManagedTileState& bms = b->managed_state();
     27 
     28     if (ams.required_for_activation != bms.required_for_activation)
     29       return ams.required_for_activation;
     30 
     31     if (ams.resolution != bms.resolution)
     32       return ams.resolution < bms.resolution;
     33 
     34     if (ams.time_to_needed_in_seconds !=  bms.time_to_needed_in_seconds)
     35       return ams.time_to_needed_in_seconds < bms.time_to_needed_in_seconds;
     36 
     37     if (ams.distance_to_visible_in_pixels !=
     38         bms.distance_to_visible_in_pixels) {
     39       return ams.distance_to_visible_in_pixels <
     40              bms.distance_to_visible_in_pixels;
     41     }
     42 
     43     gfx::Rect a_rect = a->content_rect();
     44     gfx::Rect b_rect = b->content_rect();
     45     if (a_rect.y() != b_rect.y())
     46       return a_rect.y() < b_rect.y();
     47     return a_rect.x() < b_rect.x();
     48   }
     49 };
     50 
     51 namespace {
     52 
     53 class PrioritizedTileSetTest : public testing::Test {
     54  public:
     55   PrioritizedTileSetTest() {
     56     output_surface_ = FakeOutputSurface::Create3d().Pass();
     57     CHECK(output_surface_->BindToClient(&output_surface_client_));
     58 
     59     resource_provider_ =
     60         ResourceProvider::Create(output_surface_.get(),
     61                                  NULL,
     62                                  0,
     63                                  false,
     64                                  1).Pass();
     65     tile_manager_.reset(
     66         new FakeTileManager(&tile_manager_client_, resource_provider_.get()));
     67     picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile();
     68   }
     69 
     70   scoped_refptr<Tile> CreateTile() {
     71     return tile_manager_->CreateTile(picture_pile_.get(),
     72                                      settings_.default_tile_size,
     73                                      gfx::Rect(),
     74                                      gfx::Rect(),
     75                                      1.0,
     76                                      0,
     77                                      0,
     78                                      Tile::USE_LCD_TEXT);
     79   }
     80 
     81  private:
     82   LayerTreeSettings settings_;
     83   FakeOutputSurfaceClient output_surface_client_;
     84   scoped_ptr<FakeOutputSurface> output_surface_;
     85   scoped_ptr<ResourceProvider> resource_provider_;
     86   FakeTileManagerClient tile_manager_client_;
     87   scoped_ptr<FakeTileManager> tile_manager_;
     88   scoped_refptr<FakePicturePileImpl> picture_pile_;
     89 };
     90 
     91 TEST_F(PrioritizedTileSetTest, EmptyIterator) {
     92   // Creating an iterator to an empty set should work (but create iterator that
     93   // isn't valid).
     94 
     95   PrioritizedTileSet set;
     96 
     97   PrioritizedTileSet::Iterator it(&set, true);
     98   EXPECT_FALSE(it);
     99 }
    100 
    101 TEST_F(PrioritizedTileSetTest, NonEmptyIterator) {
    102   PrioritizedTileSet set;
    103   scoped_refptr<Tile> tile = CreateTile();
    104   set.InsertTile(tile, NOW_BIN);
    105 
    106   PrioritizedTileSet::Iterator it(&set, true);
    107   EXPECT_TRUE(it);
    108   EXPECT_TRUE(*it == tile.get());
    109   ++it;
    110   EXPECT_FALSE(it);
    111 }
    112 
    113 TEST_F(PrioritizedTileSetTest, NowAndReadyToDrawBin) {
    114   // Ensure that tiles in NOW_AND_READY_TO_DRAW_BIN aren't sorted.
    115 
    116   PrioritizedTileSet set;
    117   TilePriority priorities[4] = {
    118       TilePriorityForEventualBin(),
    119       TilePriorityForNowBin(),
    120       TilePriority(),
    121       TilePriorityForSoonBin()};
    122 
    123   std::vector<scoped_refptr<Tile> > tiles;
    124   for (int priority = 0; priority < 4; ++priority) {
    125     for (int i = 0; i < 5; ++i) {
    126       scoped_refptr<Tile> tile = CreateTile();
    127       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    128       tile->SetPriority(PENDING_TREE, priorities[priority]);
    129       tiles.push_back(tile);
    130       set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN);
    131     }
    132   }
    133 
    134   // Tiles should appear in the same order as inserted.
    135   int i = 0;
    136   for (PrioritizedTileSet::Iterator it(&set, true);
    137        it;
    138        ++it) {
    139     EXPECT_TRUE(*it == tiles[i].get());
    140     ++i;
    141   }
    142   EXPECT_EQ(20, i);
    143 }
    144 
    145 TEST_F(PrioritizedTileSetTest, NowBin) {
    146   // Ensure that tiles in NOW_BIN are sorted according to BinComparator.
    147 
    148   PrioritizedTileSet set;
    149   TilePriority priorities[4] = {
    150       TilePriorityForEventualBin(),
    151       TilePriorityForNowBin(),
    152       TilePriority(),
    153       TilePriorityForSoonBin()};
    154 
    155   std::vector<scoped_refptr<Tile> > tiles;
    156   for (int priority = 0; priority < 4; ++priority) {
    157     for (int i = 0; i < 5; ++i) {
    158       scoped_refptr<Tile> tile = CreateTile();
    159       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    160       tile->SetPriority(PENDING_TREE, priorities[priority]);
    161       tiles.push_back(tile);
    162       set.InsertTile(tile, NOW_BIN);
    163     }
    164   }
    165 
    166   // Tiles should appear in BinComparator order.
    167   std::sort(tiles.begin(), tiles.end(), BinComparator());
    168 
    169   int i = 0;
    170   for (PrioritizedTileSet::Iterator it(&set, true);
    171        it;
    172        ++it) {
    173     EXPECT_TRUE(*it == tiles[i].get());
    174     ++i;
    175   }
    176   EXPECT_EQ(20, i);
    177 }
    178 
    179 TEST_F(PrioritizedTileSetTest, SoonBin) {
    180   // Ensure that tiles in SOON_BIN are sorted according to BinComparator.
    181 
    182   PrioritizedTileSet set;
    183   TilePriority priorities[4] = {
    184       TilePriorityForEventualBin(),
    185       TilePriorityForNowBin(),
    186       TilePriority(),
    187       TilePriorityForSoonBin()};
    188 
    189   std::vector<scoped_refptr<Tile> > tiles;
    190   for (int priority = 0; priority < 4; ++priority) {
    191     for (int i = 0; i < 5; ++i) {
    192       scoped_refptr<Tile> tile = CreateTile();
    193       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    194       tile->SetPriority(PENDING_TREE, priorities[priority]);
    195       tiles.push_back(tile);
    196       set.InsertTile(tile, SOON_BIN);
    197     }
    198   }
    199 
    200   // Tiles should appear in BinComparator order.
    201   std::sort(tiles.begin(), tiles.end(), BinComparator());
    202 
    203   int i = 0;
    204   for (PrioritizedTileSet::Iterator it(&set, true);
    205        it;
    206        ++it) {
    207     EXPECT_TRUE(*it == tiles[i].get());
    208     ++i;
    209   }
    210   EXPECT_EQ(20, i);
    211 }
    212 
    213 TEST_F(PrioritizedTileSetTest, SoonBinNoPriority) {
    214   // Ensure that when not using priority iterator, SOON_BIN tiles
    215   // are not sorted.
    216 
    217   PrioritizedTileSet set;
    218   TilePriority priorities[4] = {
    219       TilePriorityForEventualBin(),
    220       TilePriorityForNowBin(),
    221       TilePriority(),
    222       TilePriorityForSoonBin()};
    223 
    224   std::vector<scoped_refptr<Tile> > tiles;
    225   for (int priority = 0; priority < 4; ++priority) {
    226     for (int i = 0; i < 5; ++i) {
    227       scoped_refptr<Tile> tile = CreateTile();
    228       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    229       tile->SetPriority(PENDING_TREE, priorities[priority]);
    230       tiles.push_back(tile);
    231       set.InsertTile(tile, SOON_BIN);
    232     }
    233   }
    234 
    235   int i = 0;
    236   for (PrioritizedTileSet::Iterator it(&set, false);
    237        it;
    238        ++it) {
    239     EXPECT_TRUE(*it == tiles[i].get());
    240     ++i;
    241   }
    242   EXPECT_EQ(20, i);
    243 }
    244 
    245 TEST_F(PrioritizedTileSetTest, EventuallyAndActiveBin) {
    246   // Ensure that EVENTUALLY_AND_ACTIVE_BIN tiles are sorted.
    247 
    248   PrioritizedTileSet set;
    249   TilePriority priorities[4] = {
    250       TilePriorityForEventualBin(),
    251       TilePriorityForNowBin(),
    252       TilePriority(),
    253       TilePriorityForSoonBin()};
    254 
    255   std::vector<scoped_refptr<Tile> > tiles;
    256   for (int priority = 0; priority < 4; ++priority) {
    257     for (int i = 0; i < 5; ++i) {
    258       scoped_refptr<Tile> tile = CreateTile();
    259       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    260       tile->SetPriority(PENDING_TREE, priorities[priority]);
    261       tiles.push_back(tile);
    262       set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN);
    263     }
    264   }
    265 
    266   // Tiles should appear in BinComparator order.
    267   std::sort(tiles.begin(), tiles.end(), BinComparator());
    268 
    269   int i = 0;
    270   for (PrioritizedTileSet::Iterator it(&set, true);
    271        it;
    272        ++it) {
    273     EXPECT_TRUE(*it == tiles[i].get());
    274     ++i;
    275   }
    276   EXPECT_EQ(20, i);
    277 }
    278 
    279 TEST_F(PrioritizedTileSetTest, EventuallyBin) {
    280   // Ensure that EVENTUALLY_BIN tiles are sorted.
    281 
    282   PrioritizedTileSet set;
    283   TilePriority priorities[4] = {
    284       TilePriorityForEventualBin(),
    285       TilePriorityForNowBin(),
    286       TilePriority(),
    287       TilePriorityForSoonBin()};
    288 
    289   std::vector<scoped_refptr<Tile> > tiles;
    290   for (int priority = 0; priority < 4; ++priority) {
    291     for (int i = 0; i < 5; ++i) {
    292       scoped_refptr<Tile> tile = CreateTile();
    293       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    294       tile->SetPriority(PENDING_TREE, priorities[priority]);
    295       tiles.push_back(tile);
    296       set.InsertTile(tile, EVENTUALLY_BIN);
    297     }
    298   }
    299 
    300   // Tiles should appear in BinComparator order.
    301   std::sort(tiles.begin(), tiles.end(), BinComparator());
    302 
    303   int i = 0;
    304   for (PrioritizedTileSet::Iterator it(&set, true);
    305        it;
    306        ++it) {
    307     EXPECT_TRUE(*it == tiles[i].get());
    308     ++i;
    309   }
    310   EXPECT_EQ(20, i);
    311 }
    312 
    313 TEST_F(PrioritizedTileSetTest, AtLastAndActiveBin) {
    314   // Ensure that AT_LAST_AND_ACTIVE_BIN tiles are sorted.
    315 
    316   PrioritizedTileSet set;
    317   TilePriority priorities[4] = {
    318       TilePriorityForEventualBin(),
    319       TilePriorityForNowBin(),
    320       TilePriority(),
    321       TilePriorityForSoonBin()};
    322 
    323   std::vector<scoped_refptr<Tile> > tiles;
    324   for (int priority = 0; priority < 4; ++priority) {
    325     for (int i = 0; i < 5; ++i) {
    326       scoped_refptr<Tile> tile = CreateTile();
    327       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    328       tile->SetPriority(PENDING_TREE, priorities[priority]);
    329       tiles.push_back(tile);
    330       set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN);
    331     }
    332   }
    333 
    334   // Tiles should appear in BinComparator order.
    335   std::sort(tiles.begin(), tiles.end(), BinComparator());
    336 
    337   int i = 0;
    338   for (PrioritizedTileSet::Iterator it(&set, true);
    339        it;
    340        ++it) {
    341     EXPECT_TRUE(*it == tiles[i].get());
    342     ++i;
    343   }
    344   EXPECT_EQ(20, i);
    345 }
    346 
    347 TEST_F(PrioritizedTileSetTest, AtLastBin) {
    348   // Ensure that AT_LAST_BIN tiles are sorted.
    349 
    350   PrioritizedTileSet set;
    351   TilePriority priorities[4] = {
    352       TilePriorityForEventualBin(),
    353       TilePriorityForNowBin(),
    354       TilePriority(),
    355       TilePriorityForSoonBin()};
    356 
    357   std::vector<scoped_refptr<Tile> > tiles;
    358   for (int priority = 0; priority < 4; ++priority) {
    359     for (int i = 0; i < 5; ++i) {
    360       scoped_refptr<Tile> tile = CreateTile();
    361       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    362       tile->SetPriority(PENDING_TREE, priorities[priority]);
    363       tiles.push_back(tile);
    364       set.InsertTile(tile, AT_LAST_BIN);
    365     }
    366   }
    367 
    368   // Tiles should appear in BinComparator order.
    369   std::sort(tiles.begin(), tiles.end(), BinComparator());
    370 
    371   int i = 0;
    372   for (PrioritizedTileSet::Iterator it(&set, true);
    373        it;
    374        ++it) {
    375     EXPECT_TRUE(*it == tiles[i].get());
    376     ++i;
    377   }
    378   EXPECT_EQ(20, i);
    379 }
    380 
    381 TEST_F(PrioritizedTileSetTest, TilesForEachBin) {
    382   // Aggregate test with one tile for each of the bins, which
    383   // should appear in order of the bins.
    384 
    385   scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile();
    386   scoped_refptr<Tile> now_bin = CreateTile();
    387   scoped_refptr<Tile> soon_bin = CreateTile();
    388   scoped_refptr<Tile> eventually_and_active_bin = CreateTile();
    389   scoped_refptr<Tile> eventually_bin = CreateTile();
    390   scoped_refptr<Tile> at_last_bin = CreateTile();
    391   scoped_refptr<Tile> at_last_and_active_bin = CreateTile();
    392 
    393   PrioritizedTileSet set;
    394   set.InsertTile(soon_bin, SOON_BIN);
    395   set.InsertTile(at_last_and_active_bin, AT_LAST_AND_ACTIVE_BIN);
    396   set.InsertTile(eventually_bin, EVENTUALLY_BIN);
    397   set.InsertTile(now_bin, NOW_BIN);
    398   set.InsertTile(eventually_and_active_bin, EVENTUALLY_AND_ACTIVE_BIN);
    399   set.InsertTile(at_last_bin, AT_LAST_BIN);
    400   set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN);
    401 
    402   // Tiles should appear in order.
    403   PrioritizedTileSet::Iterator it(&set, true);
    404   EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get());
    405   ++it;
    406   EXPECT_TRUE(*it == now_bin.get());
    407   ++it;
    408   EXPECT_TRUE(*it == soon_bin.get());
    409   ++it;
    410   EXPECT_TRUE(*it == eventually_and_active_bin.get());
    411   ++it;
    412   EXPECT_TRUE(*it == eventually_bin.get());
    413   ++it;
    414   EXPECT_TRUE(*it == at_last_and_active_bin.get());
    415   ++it;
    416   EXPECT_TRUE(*it == at_last_bin.get());
    417   ++it;
    418   EXPECT_FALSE(it);
    419 }
    420 
    421 TEST_F(PrioritizedTileSetTest, ManyTilesForEachBin) {
    422   // Aggregate test with many tiles in each of the bins of various
    423   // priorities. Ensure that they are all returned in a sorted order.
    424 
    425   std::vector<scoped_refptr<Tile> > now_and_ready_to_draw_bins;
    426   std::vector<scoped_refptr<Tile> > now_bins;
    427   std::vector<scoped_refptr<Tile> > soon_bins;
    428   std::vector<scoped_refptr<Tile> > eventually_and_active_bins;
    429   std::vector<scoped_refptr<Tile> > eventually_bins;
    430   std::vector<scoped_refptr<Tile> > at_last_bins;
    431   std::vector<scoped_refptr<Tile> > at_last_and_active_bins;
    432 
    433   TilePriority priorities[4] = {
    434       TilePriorityForEventualBin(),
    435       TilePriorityForNowBin(),
    436       TilePriority(),
    437       TilePriorityForSoonBin()};
    438 
    439   PrioritizedTileSet set;
    440   for (int priority = 0; priority < 4; ++priority) {
    441     for (int i = 0; i < 5; ++i) {
    442       scoped_refptr<Tile> tile = CreateTile();
    443       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    444       tile->SetPriority(PENDING_TREE, priorities[priority]);
    445 
    446       now_and_ready_to_draw_bins.push_back(tile);
    447       now_bins.push_back(tile);
    448       soon_bins.push_back(tile);
    449       eventually_and_active_bins.push_back(tile);
    450       eventually_bins.push_back(tile);
    451       at_last_bins.push_back(tile);
    452       at_last_and_active_bins.push_back(tile);
    453 
    454       set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN);
    455       set.InsertTile(tile, NOW_BIN);
    456       set.InsertTile(tile, SOON_BIN);
    457       set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN);
    458       set.InsertTile(tile, EVENTUALLY_BIN);
    459       set.InsertTile(tile, AT_LAST_BIN);
    460       set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN);
    461     }
    462   }
    463 
    464   PrioritizedTileSet::Iterator it(&set, true);
    465   std::vector<scoped_refptr<Tile> >::iterator vector_it;
    466 
    467   // Now and ready are not sorted.
    468   for (vector_it = now_and_ready_to_draw_bins.begin();
    469        vector_it != now_and_ready_to_draw_bins.end();
    470        ++vector_it) {
    471     EXPECT_TRUE(*vector_it == *it);
    472     ++it;
    473   }
    474 
    475   // Now bins are sorted.
    476   std::sort(now_bins.begin(), now_bins.end(), BinComparator());
    477   for (vector_it = now_bins.begin(); vector_it != now_bins.end(); ++vector_it) {
    478     EXPECT_TRUE(*vector_it == *it);
    479     ++it;
    480   }
    481 
    482   // Soon bins are sorted.
    483   std::sort(soon_bins.begin(), soon_bins.end(), BinComparator());
    484   for (vector_it = soon_bins.begin(); vector_it != soon_bins.end();
    485        ++vector_it) {
    486     EXPECT_TRUE(*vector_it == *it);
    487     ++it;
    488   }
    489 
    490   // Eventually and active bins are sorted.
    491   std::sort(eventually_and_active_bins.begin(),
    492             eventually_and_active_bins.end(),
    493             BinComparator());
    494   for (vector_it = eventually_and_active_bins.begin();
    495        vector_it != eventually_and_active_bins.end();
    496        ++vector_it) {
    497     EXPECT_TRUE(*vector_it == *it);
    498     ++it;
    499   }
    500 
    501   // Eventually bins are sorted.
    502   std::sort(eventually_bins.begin(), eventually_bins.end(), BinComparator());
    503   for (vector_it = eventually_bins.begin(); vector_it != eventually_bins.end();
    504        ++vector_it) {
    505     EXPECT_TRUE(*vector_it == *it);
    506     ++it;
    507   }
    508 
    509   // At last and active bins are sorted.
    510   std::sort(at_last_and_active_bins.begin(),
    511             at_last_and_active_bins.end(),
    512             BinComparator());
    513   for (vector_it = at_last_and_active_bins.begin();
    514        vector_it != at_last_and_active_bins.end();
    515        ++vector_it) {
    516     EXPECT_TRUE(*vector_it == *it);
    517     ++it;
    518   }
    519 
    520   // At last bins are sorted.
    521   std::sort(at_last_bins.begin(), at_last_bins.end(), BinComparator());
    522   for (vector_it = at_last_bins.begin(); vector_it != at_last_bins.end();
    523        ++vector_it) {
    524     EXPECT_TRUE(*vector_it == *it);
    525     ++it;
    526   }
    527 
    528   EXPECT_FALSE(it);
    529 }
    530 
    531 TEST_F(PrioritizedTileSetTest, ManyTilesForEachBinDisablePriority) {
    532   // Aggregate test with many tiles for each of the bins. Tiles should
    533   // appear in order, until DisablePriorityOrdering is called. After that
    534   // tiles should appear in the order they were inserted.
    535 
    536   std::vector<scoped_refptr<Tile> > now_and_ready_to_draw_bins;
    537   std::vector<scoped_refptr<Tile> > now_bins;
    538   std::vector<scoped_refptr<Tile> > soon_bins;
    539   std::vector<scoped_refptr<Tile> > eventually_and_active_bins;
    540   std::vector<scoped_refptr<Tile> > eventually_bins;
    541   std::vector<scoped_refptr<Tile> > at_last_bins;
    542   std::vector<scoped_refptr<Tile> > at_last_and_active_bins;
    543 
    544   TilePriority priorities[4] = {
    545       TilePriorityForEventualBin(),
    546       TilePriorityForNowBin(),
    547       TilePriority(),
    548       TilePriorityForSoonBin()};
    549 
    550   PrioritizedTileSet set;
    551   for (int priority = 0; priority < 4; ++priority) {
    552     for (int i = 0; i < 5; ++i) {
    553       scoped_refptr<Tile> tile = CreateTile();
    554       tile->SetPriority(ACTIVE_TREE, priorities[priority]);
    555       tile->SetPriority(PENDING_TREE, priorities[priority]);
    556 
    557       now_and_ready_to_draw_bins.push_back(tile);
    558       now_bins.push_back(tile);
    559       soon_bins.push_back(tile);
    560       eventually_and_active_bins.push_back(tile);
    561       eventually_bins.push_back(tile);
    562       at_last_bins.push_back(tile);
    563       at_last_and_active_bins.push_back(tile);
    564 
    565       set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN);
    566       set.InsertTile(tile, NOW_BIN);
    567       set.InsertTile(tile, SOON_BIN);
    568       set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN);
    569       set.InsertTile(tile, EVENTUALLY_BIN);
    570       set.InsertTile(tile, AT_LAST_BIN);
    571       set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN);
    572     }
    573   }
    574 
    575   PrioritizedTileSet::Iterator it(&set, true);
    576   std::vector<scoped_refptr<Tile> >::iterator vector_it;
    577 
    578   // Now and ready are not sorted.
    579   for (vector_it = now_and_ready_to_draw_bins.begin();
    580        vector_it != now_and_ready_to_draw_bins.end();
    581        ++vector_it) {
    582     EXPECT_TRUE(*vector_it == *it);
    583     ++it;
    584   }
    585 
    586   // Now bins are sorted.
    587   std::sort(now_bins.begin(), now_bins.end(), BinComparator());
    588   for (vector_it = now_bins.begin(); vector_it != now_bins.end(); ++vector_it) {
    589     EXPECT_TRUE(*vector_it == *it);
    590     ++it;
    591   }
    592 
    593   // Soon bins are sorted.
    594   std::sort(soon_bins.begin(), soon_bins.end(), BinComparator());
    595   for (vector_it = soon_bins.begin(); vector_it != soon_bins.end();
    596        ++vector_it) {
    597     EXPECT_TRUE(*vector_it == *it);
    598     ++it;
    599   }
    600 
    601   // After we disable priority ordering, we already have sorted the next vector.
    602   it.DisablePriorityOrdering();
    603 
    604   // Eventually and active bins are sorted.
    605   std::sort(eventually_and_active_bins.begin(),
    606             eventually_and_active_bins.end(),
    607             BinComparator());
    608   for (vector_it = eventually_and_active_bins.begin();
    609        vector_it != eventually_and_active_bins.end();
    610        ++vector_it) {
    611     EXPECT_TRUE(*vector_it == *it);
    612     ++it;
    613   }
    614 
    615   // Eventually bins are not sorted.
    616   for (vector_it = eventually_bins.begin(); vector_it != eventually_bins.end();
    617        ++vector_it) {
    618     EXPECT_TRUE(*vector_it == *it);
    619     ++it;
    620   }
    621 
    622   // At last and active bins are not sorted.
    623   for (vector_it = at_last_and_active_bins.begin();
    624        vector_it != at_last_and_active_bins.end();
    625        ++vector_it) {
    626     EXPECT_TRUE(*vector_it == *it);
    627     ++it;
    628   }
    629 
    630   // At last bins are not sorted.
    631   for (vector_it = at_last_bins.begin(); vector_it != at_last_bins.end();
    632        ++vector_it) {
    633     EXPECT_TRUE(*vector_it == *it);
    634     ++it;
    635   }
    636 
    637   EXPECT_FALSE(it);
    638 }
    639 
    640 TEST_F(PrioritizedTileSetTest, TilesForFirstAndLastBins) {
    641   // Make sure that if we have empty lists between two non-empty lists,
    642   // we just get two tiles from the iterator.
    643 
    644   scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile();
    645   scoped_refptr<Tile> at_last_bin = CreateTile();
    646 
    647   PrioritizedTileSet set;
    648   set.InsertTile(at_last_bin, AT_LAST_BIN);
    649   set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN);
    650 
    651   // Only two tiles should appear and they should appear in order.
    652   PrioritizedTileSet::Iterator it(&set, true);
    653   EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get());
    654   ++it;
    655   EXPECT_TRUE(*it == at_last_bin.get());
    656   ++it;
    657   EXPECT_FALSE(it);
    658 }
    659 
    660 TEST_F(PrioritizedTileSetTest, MultipleIterators) {
    661   // Ensure that multiple iterators don't interfere with each other.
    662 
    663   scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile();
    664   scoped_refptr<Tile> now_bin = CreateTile();
    665   scoped_refptr<Tile> soon_bin = CreateTile();
    666   scoped_refptr<Tile> eventually_bin = CreateTile();
    667   scoped_refptr<Tile> at_last_bin = CreateTile();
    668 
    669   PrioritizedTileSet set;
    670   set.InsertTile(soon_bin, SOON_BIN);
    671   set.InsertTile(eventually_bin, EVENTUALLY_BIN);
    672   set.InsertTile(now_bin, NOW_BIN);
    673   set.InsertTile(at_last_bin, AT_LAST_BIN);
    674   set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN);
    675 
    676   // Tiles should appear in order.
    677   PrioritizedTileSet::Iterator it(&set, true);
    678   EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get());
    679   ++it;
    680   EXPECT_TRUE(*it == now_bin.get());
    681   ++it;
    682   EXPECT_TRUE(*it == soon_bin.get());
    683   ++it;
    684   EXPECT_TRUE(*it == eventually_bin.get());
    685   ++it;
    686   EXPECT_TRUE(*it == at_last_bin.get());
    687   ++it;
    688   EXPECT_FALSE(it);
    689 
    690   // Creating multiple iterators shouldn't affect old iterators.
    691   PrioritizedTileSet::Iterator second_it(&set, true);
    692   EXPECT_TRUE(second_it);
    693   EXPECT_FALSE(it);
    694 
    695   ++second_it;
    696   EXPECT_TRUE(second_it);
    697   ++second_it;
    698   EXPECT_TRUE(second_it);
    699   EXPECT_FALSE(it);
    700 
    701   PrioritizedTileSet::Iterator third_it(&set, true);
    702   EXPECT_TRUE(third_it);
    703   ++second_it;
    704   ++second_it;
    705   EXPECT_TRUE(second_it);
    706   EXPECT_TRUE(third_it);
    707   EXPECT_FALSE(it);
    708 
    709   ++third_it;
    710   ++third_it;
    711   EXPECT_TRUE(third_it);
    712   EXPECT_TRUE(*third_it == soon_bin.get());
    713   EXPECT_TRUE(second_it);
    714   EXPECT_TRUE(*second_it == at_last_bin.get());
    715   EXPECT_FALSE(it);
    716 
    717   ++second_it;
    718   EXPECT_TRUE(third_it);
    719   EXPECT_FALSE(second_it);
    720   EXPECT_FALSE(it);
    721 
    722   set.Clear();
    723 
    724   PrioritizedTileSet::Iterator empty_it(&set, true);
    725   EXPECT_FALSE(empty_it);
    726 }
    727 
    728 }  // namespace
    729 }  // namespace cc
    730 
    731