summaryrefslogtreecommitdiff
path: root/chromium/content/common/indexed_db/indexed_db_key_unittest.cc
blob: ca52cc4a134684b38b853b8c690f5659e4b62e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
#include "content/common/indexed_db/indexed_db_key.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

namespace {

TEST(IndexedDBKeyTest, KeySizeEstimates) {
  std::vector<IndexedDBKey> keys;
  std::vector<size_t> estimates;

  keys.push_back(IndexedDBKey());
  estimates.push_back(static_cast<size_t>(16));  // Overhead.

  keys.push_back(IndexedDBKey(blink::WebIDBKeyTypeNull));
  estimates.push_back(static_cast<size_t>(16));

  double number = 3.14159;
  keys.push_back(IndexedDBKey(number, blink::WebIDBKeyTypeNumber));
  estimates.push_back(static_cast<size_t>(24));  // Overhead + sizeof(double).

  double date = 1370884329.0;
  keys.push_back(IndexedDBKey(date, blink::WebIDBKeyTypeDate));
  estimates.push_back(static_cast<size_t>(24));  // Overhead + sizeof(double).

  const base::string16 string(1024, static_cast<char16>('X'));
  keys.push_back(IndexedDBKey(string));
  // Overhead + string length * sizeof(char16).
  estimates.push_back(static_cast<size_t>(2064));

  const size_t array_size = 1024;
  IndexedDBKey::KeyArray array;
  double value = 123.456;
  for (size_t i = 0; i < array_size; ++i) {
    array.push_back(IndexedDBKey(value, blink::WebIDBKeyTypeNumber));
  }
  keys.push_back(IndexedDBKey(array));
  // Overhead + array length * (Overhead + sizeof(double)).
  estimates.push_back(static_cast<size_t>(24592));

  ASSERT_EQ(keys.size(), estimates.size());
  for (size_t i = 0; i < keys.size(); ++i) {
    EXPECT_EQ(estimates[i], keys[i].size_estimate());
  }
}

}  // namespace

}  // namespace content