| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include "android_webview/browser/global_tile_manager.h" | 6 #include "android_webview/browser/global_tile_manager.h" |
| 7 #include "android_webview/browser/global_tile_manager_client.h" | 7 #include "android_webview/browser/global_tile_manager_client.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 EXPECT_LE(total_tiles, kNumTilesLimit); | 83 EXPECT_LE(total_tiles, kNumTilesLimit); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(GlobalTileManagerTest, RandomizedStressRequests) { | 86 TEST_F(GlobalTileManagerTest, RandomizedStressRequests) { |
| 87 MockGlobalTileManagerClient clients[100]; | 87 MockGlobalTileManagerClient clients[100]; |
| 88 size_t index[100]; | 88 size_t index[100]; |
| 89 for (size_t i = 0; i < 100; i++) { | 89 for (size_t i = 0; i < 100; i++) { |
| 90 index[i] = i; | 90 index[i] = i; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Fix the seed so that tests are reproducible. |
| 94 std::srand(1); |
| 93 // Simulate a random request order of clients. | 95 // Simulate a random request order of clients. |
| 94 std::random_shuffle(&index[0], &index[99]); | 96 std::random_shuffle(&index[0], &index[99]); |
| 95 | 97 |
| 96 for (size_t i = 0; i < 100; i++) { | 98 for (size_t i = 0; i < 100; i++) { |
| 97 size_t j = index[i]; | 99 size_t j = index[i]; |
| 98 manager()->RequestTiles(clients[j].GetTileRequest(), clients[j].GetKey()); | 100 manager()->RequestTiles(clients[j].GetTileRequest(), clients[j].GetKey()); |
| 99 manager()->DidUse(clients[j].GetKey()); | 101 manager()->DidUse(clients[j].GetKey()); |
| 100 } | 102 } |
| 101 | 103 |
| 102 size_t total_tiles = 0; | 104 size_t total_tiles = 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // Ensure that the total tiles are divided evenly among all clients. | 150 // Ensure that the total tiles are divided evenly among all clients. |
| 149 for (size_t i = 0; i < 10; i++) { | 151 for (size_t i = 0; i < 10; i++) { |
| 150 EXPECT_EQ(clients[i].GetNumTiles(), kNumTilesLimit / 10); | 152 EXPECT_EQ(clients[i].GetNumTiles(), kNumTilesLimit / 10); |
| 151 } | 153 } |
| 152 | 154 |
| 153 // Ensure that the inactive tiles are evicted. | 155 // Ensure that the inactive tiles are evicted. |
| 154 for (size_t i = 11; i < 20; i++) { | 156 for (size_t i = 11; i < 20; i++) { |
| 155 EXPECT_EQ(clients[i].GetNumTiles(), 0u); | 157 EXPECT_EQ(clients[i].GetNumTiles(), 0u); |
| 156 } | 158 } |
| 157 } | 159 } |
| OLD | NEW |