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

Side by Side Diff: content/common/indexed_db/indexed_db_key_unittest.cc

Issue 19442002: Convert to new WebIDBTypes enums and accessors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix content/common/DEPS Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "content/common/indexed_db/indexed_db_key.h" 10 #include "content/common/indexed_db/indexed_db_key.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebIDBKey.h" 12 #include "third_party/WebKit/public/platform/WebIDBKey.h"
13 13
14 using WebKit::WebIDBKey; 14 using WebKit::WebIDBKey;
15 using WebKit::WebVector; 15 using WebKit::WebVector;
16 16
17 namespace content { 17 namespace content {
18 18
19 namespace { 19 namespace {
20 20
21 TEST(IndexedDBKeyTest, KeySizeEstimates) { 21 TEST(IndexedDBKeyTest, KeySizeEstimates) {
22 std::vector<IndexedDBKey> keys; 22 std::vector<IndexedDBKey> keys;
23 std::vector<WebIDBKey> web_keys; 23 std::vector<WebIDBKey> web_keys;
24 std::vector<size_t> estimates; 24 std::vector<size_t> estimates;
25 25
26 keys.push_back(IndexedDBKey()); 26 keys.push_back(IndexedDBKey());
27 web_keys.push_back(WebIDBKey::createInvalid()); 27 web_keys.push_back(WebIDBKey::createInvalid());
28 estimates.push_back(static_cast<size_t>(16)); // Overhead. 28 estimates.push_back(static_cast<size_t>(16)); // Overhead.
29 29
30 keys.push_back(IndexedDBKey(WebIDBKey::NullType)); 30 keys.push_back(IndexedDBKey(WebKit::WebIDBKeyTypeNull));
31 web_keys.push_back(WebIDBKey::createNull()); 31 web_keys.push_back(WebIDBKey::createNull());
32 estimates.push_back(static_cast<size_t>(16)); 32 estimates.push_back(static_cast<size_t>(16));
33 33
34 double number = 3.14159; 34 double number = 3.14159;
35 keys.push_back(IndexedDBKey(number, WebIDBKey::NumberType)); 35 keys.push_back(IndexedDBKey(number, WebKit::WebIDBKeyTypeNumber));
36 web_keys.push_back(WebIDBKey::createNumber(number)); 36 web_keys.push_back(WebIDBKey::createNumber(number));
37 estimates.push_back(static_cast<size_t>(24)); // Overhead + sizeof(double). 37 estimates.push_back(static_cast<size_t>(24)); // Overhead + sizeof(double).
38 38
39 double date = 1370884329.0; 39 double date = 1370884329.0;
40 keys.push_back(IndexedDBKey(date, WebIDBKey::DateType)); 40 keys.push_back(IndexedDBKey(date, WebKit::WebIDBKeyTypeDate));
41 web_keys.push_back(WebIDBKey::createDate(date)); 41 web_keys.push_back(WebIDBKey::createDate(date));
42 estimates.push_back(static_cast<size_t>(24)); // Overhead + sizeof(double). 42 estimates.push_back(static_cast<size_t>(24)); // Overhead + sizeof(double).
43 43
44 const string16 string(1024, static_cast<char16>('X')); 44 const string16 string(1024, static_cast<char16>('X'));
45 keys.push_back(IndexedDBKey(string)); 45 keys.push_back(IndexedDBKey(string));
46 web_keys.push_back(WebIDBKey::createString(string)); 46 web_keys.push_back(WebIDBKey::createString(string));
47 // Overhead + string length * sizeof(char16). 47 // Overhead + string length * sizeof(char16).
48 estimates.push_back(static_cast<size_t>(2064)); 48 estimates.push_back(static_cast<size_t>(2064));
49 49
50 const size_t array_size = 1024; 50 const size_t array_size = 1024;
51 IndexedDBKey::KeyArray array; 51 IndexedDBKey::KeyArray array;
52 WebVector<WebIDBKey> web_array(static_cast<size_t>(array_size)); 52 WebVector<WebIDBKey> web_array(static_cast<size_t>(array_size));
53 double value = 123.456; 53 double value = 123.456;
54 for (size_t i = 0; i < array_size; ++i) { 54 for (size_t i = 0; i < array_size; ++i) {
55 array.push_back(IndexedDBKey(value, WebIDBKey::NumberType)); 55 array.push_back(IndexedDBKey(value, WebKit::WebIDBKeyTypeNumber));
56 web_array[i] = WebIDBKey::createNumber(value); 56 web_array[i] = WebIDBKey::createNumber(value);
57 } 57 }
58 keys.push_back(IndexedDBKey(array)); 58 keys.push_back(IndexedDBKey(array));
59 web_keys.push_back(WebIDBKey::createArray(array)); 59 web_keys.push_back(WebIDBKey::createArray(array));
60 // Overhead + array length * (Overhead + sizeof(double)). 60 // Overhead + array length * (Overhead + sizeof(double)).
61 estimates.push_back(static_cast<size_t>(24592)); 61 estimates.push_back(static_cast<size_t>(24592));
62 62
63 ASSERT_EQ(keys.size(), web_keys.size()); 63 ASSERT_EQ(keys.size(), web_keys.size());
64 ASSERT_EQ(keys.size(), estimates.size()); 64 ASSERT_EQ(keys.size(), estimates.size());
65 for (size_t i = 0; i < keys.size(); ++i) { 65 for (size_t i = 0; i < keys.size(); ++i) {
66 EXPECT_EQ(estimates[i], keys[i].size_estimate()); 66 EXPECT_EQ(estimates[i], keys[i].size_estimate());
67 EXPECT_EQ(estimates[i], IndexedDBKey(web_keys[i]).size_estimate()); 67 EXPECT_EQ(estimates[i], IndexedDBKey(web_keys[i]).size_estimate());
68 } 68 }
69 } 69 }
70 70
71 } // namespace 71 } // namespace
72 72
73 } // namespace content 73 } // namespace content
OLDNEW
« no previous file with comments | « content/common/indexed_db/indexed_db_key_range.cc ('k') | content/common/indexed_db/indexed_db_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698