Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/visitedlink/test/visitedlink_unittest.cc

Issue 1549993003: Switch to standard integer types in components/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h>
6 #include <stdint.h>
7
5 #include <cstdio> 8 #include <cstdio>
6 #include <string> 9 #include <string>
7 #include <vector> 10 #include <vector>
8 11
9 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
10 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h"
11 #include "base/memory/shared_memory.h" 15 #include "base/memory/shared_memory.h"
12 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
13 #include "base/run_loop.h" 17 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
16 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
17 #include "base/time/time.h" 21 #include "base/time/time.h"
18 #include "components/visitedlink/browser/visitedlink_delegate.h" 22 #include "components/visitedlink/browser/visitedlink_delegate.h"
19 #include "components/visitedlink/browser/visitedlink_event_listener.h" 23 #include "components/visitedlink/browser/visitedlink_event_listener.h"
20 #include "components/visitedlink/browser/visitedlink_master.h" 24 #include "components/visitedlink/browser/visitedlink_master.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 257
254 for (int i = 0; i < g_test_count; i++) 258 for (int i = 0; i < g_test_count; i++)
255 master_->AddURL(TestURL(i)); 259 master_->AddURL(TestURL(i));
256 260
257 // Test that the database was written properly 261 // Test that the database was written properly
258 Reload(); 262 Reload();
259 } 263 }
260 264
261 // Checks that we can delete things properly when there are collisions. 265 // Checks that we can delete things properly when there are collisions.
262 TEST_F(VisitedLinkTest, Delete) { 266 TEST_F(VisitedLinkTest, Delete) {
263 static const int32 kInitialSize = 17; 267 static const int32_t kInitialSize = 17;
264 ASSERT_TRUE(InitVisited(kInitialSize, true, true)); 268 ASSERT_TRUE(InitVisited(kInitialSize, true, true));
265 269
266 // Add a cluster from 14-17 wrapping around to 0. These will all hash to the 270 // Add a cluster from 14-17 wrapping around to 0. These will all hash to the
267 // same value. 271 // same value.
268 const VisitedLinkCommon::Fingerprint kFingerprint0 = kInitialSize * 0 + 14; 272 const VisitedLinkCommon::Fingerprint kFingerprint0 = kInitialSize * 0 + 14;
269 const VisitedLinkCommon::Fingerprint kFingerprint1 = kInitialSize * 1 + 14; 273 const VisitedLinkCommon::Fingerprint kFingerprint1 = kInitialSize * 1 + 14;
270 const VisitedLinkCommon::Fingerprint kFingerprint2 = kInitialSize * 2 + 14; 274 const VisitedLinkCommon::Fingerprint kFingerprint2 = kInitialSize * 2 + 14;
271 const VisitedLinkCommon::Fingerprint kFingerprint3 = kInitialSize * 3 + 14; 275 const VisitedLinkCommon::Fingerprint kFingerprint3 = kInitialSize * 3 + 14;
272 const VisitedLinkCommon::Fingerprint kFingerprint4 = kInitialSize * 4 + 14; 276 const VisitedLinkCommon::Fingerprint kFingerprint4 = kInitialSize * 4 + 14;
273 master_->AddFingerprint(kFingerprint0, false); // @14 277 master_->AddFingerprint(kFingerprint0, false); // @14
(...skipping 22 matching lines...) Expand all
296 "Hash table has values in it."; 300 "Hash table has values in it.";
297 } 301 }
298 302
299 // When we delete more than kBigDeleteThreshold we trigger different behavior 303 // When we delete more than kBigDeleteThreshold we trigger different behavior
300 // where the entire file is rewritten. 304 // where the entire file is rewritten.
301 TEST_F(VisitedLinkTest, BigDelete) { 305 TEST_F(VisitedLinkTest, BigDelete) {
302 ASSERT_TRUE(InitVisited(16381, true, true)); 306 ASSERT_TRUE(InitVisited(16381, true, true));
303 307
304 // Add the base set of URLs that won't be deleted. 308 // Add the base set of URLs that won't be deleted.
305 // Reload() will test for these. 309 // Reload() will test for these.
306 for (int32 i = 0; i < g_test_count; i++) 310 for (int32_t i = 0; i < g_test_count; i++)
307 master_->AddURL(TestURL(i)); 311 master_->AddURL(TestURL(i));
308 312
309 // Add more URLs than necessary to trigger this case. 313 // Add more URLs than necessary to trigger this case.
310 const int kTestDeleteCount = VisitedLinkMaster::kBigDeleteThreshold + 2; 314 const int kTestDeleteCount = VisitedLinkMaster::kBigDeleteThreshold + 2;
311 URLs urls_to_delete; 315 URLs urls_to_delete;
312 for (int32 i = g_test_count; i < g_test_count + kTestDeleteCount; i++) { 316 for (int32_t i = g_test_count; i < g_test_count + kTestDeleteCount; i++) {
313 GURL url(TestURL(i)); 317 GURL url(TestURL(i));
314 master_->AddURL(url); 318 master_->AddURL(url);
315 urls_to_delete.push_back(url); 319 urls_to_delete.push_back(url);
316 } 320 }
317 321
318 TestURLIterator iterator(urls_to_delete); 322 TestURLIterator iterator(urls_to_delete);
319 master_->DeleteURLs(&iterator); 323 master_->DeleteURLs(&iterator);
320 master_->DebugValidate(); 324 master_->DebugValidate();
321 325
322 Reload(); 326 Reload();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 master_->DebugValidate(); 366 master_->DebugValidate();
363 EXPECT_EQ(0, master_->GetUsedCount()); 367 EXPECT_EQ(0, master_->GetUsedCount());
364 for (int i = 0; i < g_test_count; i++) 368 for (int i = 0; i < g_test_count; i++)
365 EXPECT_FALSE(master_->IsVisited(TestURL(i))); 369 EXPECT_FALSE(master_->IsVisited(TestURL(i)));
366 } 370 }
367 371
368 // This tests that the master correctly resizes its tables when it gets too 372 // This tests that the master correctly resizes its tables when it gets too
369 // full, notifies its slaves of the change, and updates the disk. 373 // full, notifies its slaves of the change, and updates the disk.
370 TEST_F(VisitedLinkTest, Resizing) { 374 TEST_F(VisitedLinkTest, Resizing) {
371 // Create a very small database. 375 // Create a very small database.
372 const int32 initial_size = 17; 376 const int32_t initial_size = 17;
373 ASSERT_TRUE(InitVisited(initial_size, true, true)); 377 ASSERT_TRUE(InitVisited(initial_size, true, true));
374 378
375 // ...and a slave 379 // ...and a slave
376 VisitedLinkSlave slave; 380 VisitedLinkSlave slave;
377 base::SharedMemoryHandle new_handle = base::SharedMemory::NULLHandle(); 381 base::SharedMemoryHandle new_handle = base::SharedMemory::NULLHandle();
378 master_->shared_memory()->ShareToProcess( 382 master_->shared_memory()->ShareToProcess(
379 base::GetCurrentProcessHandle(), &new_handle); 383 base::GetCurrentProcessHandle(), &new_handle);
380 slave.OnUpdateVisitedLinks(new_handle); 384 slave.OnUpdateVisitedLinks(new_handle);
381 g_slaves.push_back(&slave); 385 g_slaves.push_back(&slave);
382 386
383 int32 used_count = master_->GetUsedCount(); 387 int32_t used_count = master_->GetUsedCount();
384 ASSERT_EQ(used_count, 0); 388 ASSERT_EQ(used_count, 0);
385 389
386 for (int i = 0; i < g_test_count; i++) { 390 for (int i = 0; i < g_test_count; i++) {
387 master_->AddURL(TestURL(i)); 391 master_->AddURL(TestURL(i));
388 used_count = master_->GetUsedCount(); 392 used_count = master_->GetUsedCount();
389 ASSERT_EQ(i + 1, used_count); 393 ASSERT_EQ(i + 1, used_count);
390 } 394 }
391 395
392 // Verify that the table got resized sufficiently. 396 // Verify that the table got resized sufficiently.
393 int32 table_size; 397 int32_t table_size;
394 VisitedLinkCommon::Fingerprint* table; 398 VisitedLinkCommon::Fingerprint* table;
395 master_->GetUsageStatistics(&table_size, &table); 399 master_->GetUsageStatistics(&table_size, &table);
396 used_count = master_->GetUsedCount(); 400 used_count = master_->GetUsedCount();
397 ASSERT_GT(table_size, used_count); 401 ASSERT_GT(table_size, used_count);
398 ASSERT_EQ(used_count, g_test_count) << 402 ASSERT_EQ(used_count, g_test_count) <<
399 "table count doesn't match the # of things we added"; 403 "table count doesn't match the # of things we added";
400 404
401 // Verify that the slave got the resize message and has the same 405 // Verify that the slave got the resize message and has the same
402 // table information. 406 // table information.
403 int32 child_table_size; 407 int32_t child_table_size;
404 VisitedLinkCommon::Fingerprint* child_table; 408 VisitedLinkCommon::Fingerprint* child_table;
405 slave.GetUsageStatistics(&child_table_size, &child_table); 409 slave.GetUsageStatistics(&child_table_size, &child_table);
406 ASSERT_EQ(table_size, child_table_size); 410 ASSERT_EQ(table_size, child_table_size);
407 for (int32 i = 0; i < table_size; i++) { 411 for (int32_t i = 0; i < table_size; i++) {
408 ASSERT_EQ(table[i], child_table[i]); 412 ASSERT_EQ(table[i], child_table[i]);
409 } 413 }
410 414
411 master_->DebugValidate(); 415 master_->DebugValidate();
412 g_slaves.clear(); 416 g_slaves.clear();
413 417
414 // This tests that the file is written correctly by reading it in using 418 // This tests that the file is written correctly by reading it in using
415 // a new database. 419 // a new database.
416 Reload(); 420 Reload();
417 } 421 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 void WidgetHidden() override { widgets_--; } 590 void WidgetHidden() override { widgets_--; }
587 int VisibleWidgetCount() const override { return widgets_; } 591 int VisibleWidgetCount() const override { return widgets_; }
588 592
589 bool Send(IPC::Message* msg) override { 593 bool Send(IPC::Message* msg) override {
590 VisitCountingContext* counting_context = 594 VisitCountingContext* counting_context =
591 static_cast<VisitCountingContext*>( 595 static_cast<VisitCountingContext*>(
592 GetBrowserContext()); 596 GetBrowserContext());
593 597
594 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) { 598 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) {
595 base::PickleIterator iter(*msg); 599 base::PickleIterator iter(*msg);
596 std::vector<uint64> fingerprints; 600 std::vector<uint64_t> fingerprints;
597 CHECK(IPC::ReadParam(msg, &iter, &fingerprints)); 601 CHECK(IPC::ReadParam(msg, &iter, &fingerprints));
598 counting_context->CountAddEvent(fingerprints.size()); 602 counting_context->CountAddEvent(fingerprints.size());
599 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) { 603 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) {
600 base::PickleIterator iter(*msg); 604 base::PickleIterator iter(*msg);
601 bool invalidate_hashes; 605 bool invalidate_hashes;
602 CHECK(IPC::ReadParam(msg, &iter, &invalidate_hashes)); 606 CHECK(IPC::ReadParam(msg, &iter, &invalidate_hashes));
603 if (invalidate_hashes) 607 if (invalidate_hashes)
604 counting_context->CountCompletelyResetEvent(); 608 counting_context->CountCompletelyResetEvent();
605 else 609 else
606 counting_context->CountResetEvent(); 610 counting_context->CountResetEvent();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 // Waiting complete loading the table. 881 // Waiting complete loading the table.
878 content::RunAllBlockingPoolTasksUntilIdle(); 882 content::RunAllBlockingPoolTasksUntilIdle();
879 883
880 WaitForCoalescence(); 884 WaitForCoalescence();
881 885
882 // After load table expect completely reset event. 886 // After load table expect completely reset event.
883 EXPECT_EQ(1, context()->completely_reset_event_count()); 887 EXPECT_EQ(1, context()->completely_reset_event_count());
884 } 888 }
885 889
886 } // namespace visitedlink 890 } // namespace visitedlink
OLDNEW
« no previous file with comments | « components/visitedlink/renderer/visitedlink_slave.cc ('k') | components/wallpaper/wallpaper_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698